Fixed bug where last tests were not executed.
[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 /* direct sound hardware acceleration levels */
30 #define DS_HW_ACCEL_FULL        0       /* default on Windows 98 */
31 #define DS_HW_ACCEL_STANDARD    1       /* default on Windows 2000 */
32 #define DS_HW_ACCEL_BASIC       2
33 #define DS_HW_ACCEL_EMULATION   3
34
35 extern int ds_emuldriver;
36 extern int ds_hel_margin;
37 extern int ds_hel_queue;
38 extern int ds_snd_queue_max;
39 extern int ds_snd_queue_min;
40 extern int ds_hw_accel;
41 extern int ds_default_playback;
42 extern int ds_default_capture;
43
44 /*****************************************************************************
45  * Predeclare the interface implementation structures
46  */
47 typedef struct IDirectSoundImpl IDirectSoundImpl;
48 typedef struct IDirectSoundBufferImpl IDirectSoundBufferImpl;
49 typedef struct IDirectSoundCaptureImpl IDirectSoundCaptureImpl;
50 typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl;
51 typedef struct IDirectSoundFullDuplexImpl IDirectSoundFullDuplexImpl;
52 typedef struct IDirectSoundNotifyImpl IDirectSoundNotifyImpl;
53 typedef struct IDirectSound3DListenerImpl IDirectSound3DListenerImpl;
54 typedef struct IDirectSound3DBufferImpl IDirectSound3DBufferImpl;
55 typedef struct IKsPropertySetImpl IKsPropertySetImpl;
56 typedef struct PrimaryBufferImpl PrimaryBufferImpl;
57 typedef struct IClassFactoryImpl IClassFactoryImpl;
58
59 /*****************************************************************************
60  * IDirectSound implementation structure
61  */
62 struct IDirectSoundImpl
63 {
64     /* IUnknown fields */
65     ICOM_VFIELD(IDirectSound8);
66     DWORD                       ref;
67     /* IDirectSoundImpl fields */
68     GUID                        guid;
69     PIDSDRIVER                  driver;
70     DSDRIVERDESC                drvdesc;
71     DSDRIVERCAPS                drvcaps;
72     DWORD                       priolevel;
73     WAVEFORMATEX                wfx; /* current main waveformat */
74     HWAVEOUT                    hwo;
75     LPWAVEHDR                   pwave[DS_HEL_FRAGS];
76     UINT                        timerID, pwplay, pwwrite, pwqueue, prebuf, precount;
77     DWORD                       fraglen;
78     PIDSDRIVERBUFFER            hwbuf;
79     LPBYTE                      buffer;
80     DWORD                       writelead, buflen, state, playpos, mixpos;
81     BOOL                        need_remix;
82     int                         nrofbuffers;
83     IDirectSoundBufferImpl**    buffers;
84     RTL_RWLOCK                  lock;
85     CRITICAL_SECTION            mixlock;
86     DSVOLUMEPAN                 volpan;
87     PrimaryBufferImpl*          primary;
88     DSBUFFERDESC                dsbd;
89
90     /* DirectSound3DListener fields */
91     IDirectSound3DListenerImpl* listener;
92     DS3DLISTENER                ds3dl;
93     CRITICAL_SECTION            ds3dl_lock;
94     BOOL                        ds3dl_need_recalc;
95 };
96
97 /* reference counted buffer memory for duplicated buffer memory */
98 typedef struct BufferMemory
99 {
100     DWORD                       ref;
101     LPBYTE                      memory;
102 } BufferMemory;
103
104 /*****************************************************************************
105  * IDirectSoundBuffer implementation structure
106  */
107 struct IDirectSoundBufferImpl
108 {
109     /* FIXME: document */
110     /* IUnknown fields */
111     ICOM_VFIELD(IDirectSoundBuffer8);
112     DWORD                       ref;
113     /* IDirectSoundBufferImpl fields */
114     IDirectSoundImpl*           dsound;
115     IDirectSound3DBufferImpl*   ds3db;
116     IKsPropertySetImpl*         iks;
117     CRITICAL_SECTION            lock;
118     PIDSDRIVERBUFFER            hwbuf;
119     WAVEFORMATEX                wfx;
120     BufferMemory*               buffer;
121     DWORD                       playflags,state,leadin;
122     DWORD                       playpos,startpos,writelead,buflen;
123     DWORD                       nAvgBytesPerSec;
124     DWORD                       freq;
125     DSVOLUMEPAN                 volpan, cvolpan;
126     DSBUFFERDESC                dsbd;
127     /* used for frequency conversion (PerfectPitch) */
128     ULONG                       freqAdjust, freqAcc;
129     /* used for intelligent (well, sort of) prebuffering */
130     DWORD                       probably_valid_to, last_playpos;
131     DWORD                       primary_mixpos, buf_mixpos;
132     BOOL                        need_remix;
133     /* IDirectSoundNotifyImpl fields */
134     IDirectSoundNotifyImpl*     notify;
135
136     /* DirectSound3DBuffer fields */
137     DS3DBUFFER                  ds3db_ds3db;
138     LONG                        ds3db_lVolume;
139     BOOL                        ds3db_need_recalc;
140 };
141
142 HRESULT WINAPI SecondaryBuffer_Create(
143         IDirectSoundImpl *This,
144         IDirectSoundBufferImpl **pdsb,
145         LPDSBUFFERDESC dsbd);
146
147 struct PrimaryBufferImpl {
148     ICOM_VFIELD(IDirectSoundBuffer8);
149     DWORD                       ref;
150     IDirectSoundImpl*           dsound;
151 };
152
153 HRESULT WINAPI PrimaryBuffer_Create(
154         IDirectSoundImpl *This,
155         PrimaryBufferImpl **pdsb,
156         LPDSBUFFERDESC dsbd);
157
158 /*****************************************************************************
159  * IDirectSoundCapture implementation structure
160  */
161 struct IDirectSoundCaptureImpl
162 {
163     /* IUnknown fields */
164     ICOM_VFIELD(IDirectSoundCapture);
165     DWORD                              ref;
166
167     /* IDirectSoundCaptureImpl fields */
168     GUID                               guid;
169     BOOL                               initialized;
170
171     /* DirectSound driver stuff */
172     PIDSCDRIVER                        driver;
173     DSDRIVERDESC                       drvdesc;
174     DSCDRIVERCAPS                      drvcaps;
175     PIDSCDRIVERBUFFER                  hwbuf;
176
177     /* wave driver info */
178     HWAVEIN                            hwi;
179
180     /* more stuff */
181     LPBYTE                             buffer;
182     DWORD                              buflen;
183     DWORD                              read_position;
184
185     /* FIXME: this should be a pointer because it can be bigger */
186     WAVEFORMATEX                       wfx;
187
188     IDirectSoundCaptureBufferImpl*     capture_buffer;
189     DWORD                              state;
190     LPWAVEHDR                          pwave;
191     int                                nrofpwaves;
192     int                                index;
193     CRITICAL_SECTION                   lock;
194 };
195
196 /*****************************************************************************
197  * IDirectSoundCaptureBuffer implementation structure
198  */
199 struct IDirectSoundCaptureBufferImpl
200 {
201     /* IUnknown fields */
202     ICOM_VFIELD(IDirectSoundCaptureBuffer8);
203     DWORD                               ref;
204
205     /* IDirectSoundCaptureBufferImpl fields */
206     IDirectSoundCaptureImpl*            dsound;
207     /* FIXME: don't need this */
208     LPDSCBUFFERDESC                     pdscbd;
209     DWORD                               flags;
210     /* IDirectSoundNotifyImpl fields */
211     IDirectSoundNotifyImpl*             notify;
212 };
213
214 /*****************************************************************************
215  * IDirectSoundFullDuplex implementation structure
216  */
217 struct IDirectSoundFullDuplexImpl
218 {
219     /* IUnknown fields */
220     ICOM_VFIELD(IDirectSoundFullDuplex);
221     DWORD                       ref;
222
223     /* IDirectSoundFullDuplexImpl fields */
224     CRITICAL_SECTION            lock;
225 };
226
227 /*****************************************************************************
228  * IDirectSoundNotify implementation structure
229  */
230 struct IDirectSoundNotifyImpl
231 {
232     /* IUnknown fields */
233     ICOM_VFIELD(IDirectSoundNotify);
234     DWORD                       ref;
235     /* IDirectSoundNotifyImpl fields */
236     LPDSBPOSITIONNOTIFY         notifies;
237     int                         nrofnotifies;
238
239     PIDSDRIVERNOTIFY            hwnotify;
240 };
241
242 /*****************************************************************************
243  *  IDirectSound3DListener implementation structure
244  */
245 struct IDirectSound3DListenerImpl
246 {
247     /* IUnknown fields */
248     ICOM_VFIELD(IDirectSound3DListener);
249     DWORD                       ref;
250     /* IDirectSound3DListenerImpl fields */
251     IDirectSoundImpl*           dsound;
252 };
253
254 HRESULT WINAPI IDirectSound3DListenerImpl_Create(
255         PrimaryBufferImpl *This,
256         IDirectSound3DListenerImpl **pdsl);
257
258 /*****************************************************************************
259  *  IKsPropertySet implementation structure
260  */
261 struct IKsPropertySetImpl
262 {
263     /* IUnknown fields */
264     ICOM_VFIELD(IKsPropertySet);
265     DWORD                       ref;
266     /* IKsPropertySetImpl fields */
267     IDirectSoundBufferImpl*     dsb;
268 };
269
270 HRESULT WINAPI IKsPropertySetImpl_Create(
271         IDirectSoundBufferImpl *This,
272         IKsPropertySetImpl **piks);
273
274 /*****************************************************************************
275  * IDirectSound3DBuffer implementation structure
276  */
277 struct IDirectSound3DBufferImpl
278 {
279     /* IUnknown fields */
280     ICOM_VFIELD(IDirectSound3DBuffer);
281     DWORD                       ref;
282     /* IDirectSound3DBufferImpl fields */
283     IDirectSoundBufferImpl*     dsb;
284     CRITICAL_SECTION            lock;
285 };
286
287 HRESULT WINAPI IDirectSound3DBufferImpl_Create(
288         IDirectSoundBufferImpl *This,
289         IDirectSound3DBufferImpl **pds3db);
290
291 /*******************************************************************************
292  * DirectSound ClassFactory implementation structure
293  */
294 struct IClassFactoryImpl
295 {
296     /* IUnknown fields */
297     ICOM_VFIELD(IClassFactory);
298     DWORD                       ref;
299 };
300
301 extern IClassFactoryImpl DSOUND_CAPTURE_CF;
302 extern IClassFactoryImpl DSOUND_FULLDUPLEX_CF;
303
304 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
305 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
306
307 /* primary.c */
308
309 HRESULT DSOUND_PrimaryCreate(IDirectSoundImpl *This);
310 HRESULT DSOUND_PrimaryDestroy(IDirectSoundImpl *This);
311 HRESULT DSOUND_PrimaryPlay(IDirectSoundImpl *This);
312 HRESULT DSOUND_PrimaryStop(IDirectSoundImpl *This);
313 HRESULT DSOUND_PrimaryGetPosition(IDirectSoundImpl *This, LPDWORD playpos, LPDWORD writepos);
314
315 /* buffer.c */
316
317 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
318                               DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix);
319
320 /* mixer.c */
321
322 void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len);
323 void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb);
324 void DSOUND_MixCancelAt(IDirectSoundBufferImpl *dsb, DWORD buf_writepos);
325 void DSOUND_WaveQueue(IDirectSoundImpl *dsound, DWORD mixq);
326 void DSOUND_PerformMix(void);
327 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
328 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
329
330 /* sound3d.c */
331
332 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb);
333
334 #define STATE_STOPPED   0
335 #define STATE_STARTING  1
336 #define STATE_PLAYING   2
337 #define STATE_CAPTURING 2
338 #define STATE_STOPPING  3
339
340 #define DSOUND_FREQSHIFT (14)
341
342 extern IDirectSoundImpl* dsound;
343 extern IDirectSoundCaptureImpl* dsound_capture;
344
345 extern ICOM_VTABLE(IDirectSoundNotify) dsnvt;
346 extern HRESULT mmErr(UINT err);
347 extern void setup_dsound_options(void);