Added .spec.def files.
[wine] / dlls / dsound / dsound_private.h
1 /*                      DirectSound
2  *
3  * Copyright 1998 Marcus Meissner
4  * Copyright 1998 Rob Riggs
5  * Copyright 2000-2001 TransGaming Technologies, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 /* Linux does not support better timing than 10ms */
23 #define DS_TIME_RES 10  /* Resolution of multimedia timer */
24 #define DS_TIME_DEL 10  /* Delay of multimedia timer callback, and duration of HEL fragment */
25
26 #define DS_HEL_FRAGS 48 /* HEL only: number of waveOut fragments in primary buffer
27                          * (changing this won't help you) */
28
29 extern int ds_emuldriver;
30 extern int ds_hel_margin;
31 extern int ds_hel_queue;
32 extern int ds_snd_queue_max;
33 extern int ds_snd_queue_min;
34
35 /*****************************************************************************
36  * Predeclare the interface implementation structures
37  */
38 typedef struct IDirectSoundImpl IDirectSoundImpl;
39 typedef struct IDirectSoundBufferImpl IDirectSoundBufferImpl;
40 typedef struct IDirectSoundNotifyImpl IDirectSoundNotifyImpl;
41 typedef struct IDirectSound3DListenerImpl IDirectSound3DListenerImpl;
42 typedef struct IDirectSound3DBufferImpl IDirectSound3DBufferImpl;
43 typedef struct IKsPropertySetImpl IKsPropertySetImpl;
44 typedef struct PrimaryBufferImpl PrimaryBufferImpl;
45
46 /*****************************************************************************
47  * IDirectSound implementation structure
48  */
49 struct IDirectSoundImpl
50 {
51     /* IUnknown fields */
52     ICOM_VFIELD(IDirectSound8);
53     DWORD                      ref;
54     /* IDirectSoundImpl fields */
55     PIDSDRIVER                  driver;
56     DSDRIVERDESC                drvdesc;
57     DSDRIVERCAPS                drvcaps;
58     DWORD                       priolevel;
59     WAVEFORMATEX                wfx; /* current main waveformat */
60     HWAVEOUT                    hwo;
61     LPWAVEHDR                   pwave[DS_HEL_FRAGS];
62     UINT                        timerID, pwplay, pwwrite, pwqueue, prebuf, precount;
63     DWORD                       fraglen;
64     PIDSDRIVERBUFFER            hwbuf;
65     LPBYTE                      buffer;
66     DWORD                       writelead, buflen, state, playpos, mixpos;
67     BOOL                        need_remix;
68     int                         nrofbuffers;
69     IDirectSoundBufferImpl**    buffers;
70     IDirectSound3DListenerImpl* listener;
71     RTL_RWLOCK                  lock;
72     CRITICAL_SECTION            mixlock;
73     DSVOLUMEPAN                 volpan;
74 };
75
76 /*****************************************************************************
77  * IDirectSoundBuffer implementation structure
78  */
79 struct IDirectSoundBufferImpl
80 {
81     /* FIXME: document */
82     /* IUnknown fields */
83     ICOM_VFIELD(IDirectSoundBuffer8);
84     DWORD                     ref;
85     /* IDirectSoundBufferImpl fields */
86     IDirectSoundImpl*         dsound;
87     IDirectSoundBufferImpl*   parent;         /* for duplicates */
88     IDirectSound3DBufferImpl* ds3db;
89     IKsPropertySetImpl*       iks;
90     CRITICAL_SECTION          lock;
91     PIDSDRIVERBUFFER          hwbuf;
92     WAVEFORMATEX              wfx;
93     LPBYTE                    buffer;
94     DWORD                     playflags,state,leadin;
95     DWORD                     playpos,startpos,writelead,buflen;
96     DWORD                     nAvgBytesPerSec;
97     DWORD                     freq;
98     DSVOLUMEPAN               volpan, cvolpan;
99     DSBUFFERDESC              dsbd;
100     /* used for frequency conversion (PerfectPitch) */
101     ULONG                     freqAdjust, freqAcc;
102     /* used for intelligent (well, sort of) prebuffering */
103     DWORD                     probably_valid_to, last_playpos;
104     DWORD                     primary_mixpos, buf_mixpos;
105     BOOL                      need_remix;
106     /* IDirectSoundNotifyImpl fields */
107     LPDSBPOSITIONNOTIFY       notifies;
108     int                       nrofnotifies;
109 };
110
111 HRESULT WINAPI SecondaryBuffer_Create(
112         IDirectSoundImpl *This,
113         IDirectSoundBufferImpl **pdsb,
114         LPDSBUFFERDESC dsbd);
115
116 struct PrimaryBufferImpl {
117         ICOM_VFIELD(IDirectSoundBuffer8);
118         DWORD                   ref;
119         IDirectSoundImpl*       dsound;
120         DSBUFFERDESC            dsbd;
121 };
122
123 HRESULT WINAPI PrimaryBuffer_Create(
124         IDirectSoundImpl *This,
125         PrimaryBufferImpl **pdsb,
126         LPDSBUFFERDESC dsbd);
127
128 /*****************************************************************************
129  * IDirectSoundNotify implementation structure
130  */
131 struct IDirectSoundNotifyImpl
132 {
133     /* IUnknown fields */
134     ICOM_VFIELD(IDirectSoundNotify);
135     DWORD                            ref;
136     /* IDirectSoundNotifyImpl fields */
137     IDirectSoundBufferImpl* dsb;
138 };
139
140 /*****************************************************************************
141  *  IDirectSound3DListener implementation structure
142  */
143 struct IDirectSound3DListenerImpl
144 {
145     /* IUnknown fields */
146     ICOM_VFIELD(IDirectSound3DListener);
147     DWORD                                ref;
148     /* IDirectSound3DListenerImpl fields */
149     PrimaryBufferImpl*      dsb;
150     DS3DLISTENER            ds3dl;
151     CRITICAL_SECTION        lock;
152     BOOL                    need_recalc;
153 };
154
155 HRESULT WINAPI IDirectSound3DListenerImpl_Create(
156         PrimaryBufferImpl *This,
157         IDirectSound3DListenerImpl **pdsl);
158
159 /*****************************************************************************
160  *  IKsPropertySet implementation structure
161  */
162 struct IKsPropertySetImpl
163 {
164     /* IUnknown fields */
165     ICOM_VFIELD(IKsPropertySet);
166     DWORD                       ref;
167     /* IKsPropertySetImpl fields */
168     IDirectSoundBufferImpl*     dsb;
169 };
170
171 HRESULT WINAPI IKsPropertySetImpl_Create(
172         IDirectSoundBufferImpl *This,
173         IKsPropertySetImpl **piks);
174
175 /*****************************************************************************
176  * IDirectSound3DBuffer implementation structure
177  */
178 struct IDirectSound3DBufferImpl
179 {
180     /* IUnknown fields */
181     ICOM_VFIELD(IDirectSound3DBuffer);
182     DWORD                              ref;
183     /* IDirectSound3DBufferImpl fields */
184     IDirectSoundBufferImpl* dsb;
185     DS3DBUFFER              ds3db;
186     LONG                    lVolume;
187     CRITICAL_SECTION        lock;
188     BOOL                    need_recalc;
189 };
190
191 HRESULT WINAPI IDirectSound3DBufferImpl_Create(
192         IDirectSoundBufferImpl *This,
193         IDirectSound3DBufferImpl **pds3db);
194
195 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
196 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
197
198 /* primary.c */
199
200 HRESULT DSOUND_PrimaryCreate(IDirectSoundImpl *This);
201 HRESULT DSOUND_PrimaryDestroy(IDirectSoundImpl *This);
202 HRESULT DSOUND_PrimaryPlay(IDirectSoundImpl *This);
203 HRESULT DSOUND_PrimaryStop(IDirectSoundImpl *This);
204 HRESULT DSOUND_PrimaryGetPosition(IDirectSoundImpl *This, LPDWORD playpos, LPDWORD writepos);
205
206 /* buffer.c */
207
208 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
209                               DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix);
210
211 /* mixer.c */
212
213 void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len);
214 void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb);
215 void DSOUND_MixCancelAt(IDirectSoundBufferImpl *dsb, DWORD buf_writepos);
216 void DSOUND_WaveQueue(IDirectSoundImpl *dsound, DWORD mixq);
217 void DSOUND_PerformMix(void);
218 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
219 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
220
221 #define STATE_STOPPED  0
222 #define STATE_STARTING 1
223 #define STATE_PLAYING  2
224 #define STATE_STOPPING 3
225
226 #define DSOUND_FREQSHIFT (14)
227
228 extern IDirectSoundImpl* dsound;
229
230 struct PrimaryBuffer {
231         DWORD ref;
232         PIDSDRIVERBUFFER hwbuf;
233         DWORD state;
234 };