dsound: Make dumpCooperativeLevel global.
[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 IDirectSound_IUnknown         IDirectSound_IUnknown;
49 typedef struct IDirectSound_IDirectSound     IDirectSound_IDirectSound;
50 typedef struct IDirectSound8_IUnknown        IDirectSound8_IUnknown;
51 typedef struct IDirectSound8_IDirectSound    IDirectSound8_IDirectSound;
52 typedef struct IDirectSound8_IDirectSound8   IDirectSound8_IDirectSound8;
53 typedef struct IDirectSoundBufferImpl        IDirectSoundBufferImpl;
54 typedef struct IDirectSoundCaptureImpl       IDirectSoundCaptureImpl;
55 typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl;
56 typedef struct IDirectSoundFullDuplexImpl    IDirectSoundFullDuplexImpl;
57 typedef struct IDirectSoundNotifyImpl        IDirectSoundNotifyImpl;
58 typedef struct IDirectSoundCaptureNotifyImpl IDirectSoundCaptureNotifyImpl;
59 typedef struct IDirectSound3DListenerImpl    IDirectSound3DListenerImpl;
60 typedef struct IDirectSound3DBufferImpl      IDirectSound3DBufferImpl;
61 typedef struct IKsBufferPropertySetImpl      IKsBufferPropertySetImpl;
62 typedef struct IKsPrivatePropertySetImpl     IKsPrivatePropertySetImpl;
63 typedef struct PrimaryBufferImpl             PrimaryBufferImpl;
64 typedef struct SecondaryBufferImpl           SecondaryBufferImpl;
65 typedef struct IClassFactoryImpl             IClassFactoryImpl;
66 typedef struct DirectSoundDevice             DirectSoundDevice;
67 typedef struct DirectSoundCaptureDevice      DirectSoundCaptureDevice;
68
69 /*****************************************************************************
70  * IDirectSound implementation structure
71  */
72 struct IDirectSoundImpl
73 {
74     /* IUnknown fields */
75     const IDirectSound8Vtbl    *lpVtbl;
76     LONG                        ref;
77
78     DirectSoundDevice          *device;
79     LPUNKNOWN                   pUnknown;
80     LPDIRECTSOUND               pDS;
81     LPDIRECTSOUND8              pDS8;
82 };
83
84 HRESULT IDirectSoundImpl_Create(
85     LPDIRECTSOUND8 * ppds);
86
87 /*****************************************************************************
88  * IDirectSoundDevice implementation structure
89  */
90 struct DirectSoundDevice
91 {
92     LONG                        ref;
93
94     GUID                        guid;
95     PIDSDRIVER                  driver;
96     DSDRIVERDESC                drvdesc;
97     DSDRIVERCAPS                drvcaps;
98     DWORD                       priolevel;
99     PWAVEFORMATEX               pwfx;
100     HWAVEOUT                    hwo;
101     LPWAVEHDR                   pwave[DS_HEL_FRAGS];
102     UINT                        timerID, pwplay, pwwrite, pwqueue, prebuf, precount;
103     DWORD                       fraglen;
104     PIDSDRIVERBUFFER            hwbuf;
105     LPBYTE                      buffer;
106     DWORD                       writelead, buflen, state, playpos, mixpos;
107     BOOL                        need_remix;
108     int                         nrofbuffers;
109     IDirectSoundBufferImpl**    buffers;
110     RTL_RWLOCK                  buffer_list_lock;
111     CRITICAL_SECTION            mixlock;
112     PrimaryBufferImpl*          primary;
113     DSBUFFERDESC                dsbd;
114     DWORD                       speaker_config;
115     LPBYTE                      tmp_buffer;
116     DWORD                       tmp_buffer_len;
117
118     /* DirectSound3DListener fields */
119     IDirectSound3DListenerImpl* listener;
120     DS3DLISTENER                ds3dl;
121     BOOL                        ds3dl_need_recalc;
122 };
123
124 /* reference counted buffer memory for duplicated buffer memory */
125 typedef struct BufferMemory
126 {
127     LONG                        ref;
128     LPBYTE                      memory;
129 } BufferMemory;
130
131 HRESULT DirectSoundDevice_Create(DirectSoundDevice ** ppDevice);
132 ULONG DirectSoundDevice_AddRef(DirectSoundDevice * device);
133 ULONG DirectSoundDevice_Release(DirectSoundDevice * device);
134 HRESULT DirectSoundDevice_AddBuffer(
135     DirectSoundDevice *device,
136     IDirectSoundBufferImpl * pDSB);
137 HRESULT DirectSoundDevice_RemoveBuffer(
138     DirectSoundDevice *device,
139     IDirectSoundBufferImpl * pDSB);
140
141 /*****************************************************************************
142  * IDirectSound COM components
143  */
144 struct IDirectSound_IUnknown {
145     const IUnknownVtbl         *lpVtbl;
146     LONG                        ref;
147     LPDIRECTSOUND8              pds;
148 };
149
150 HRESULT IDirectSound_IUnknown_Create(
151     LPDIRECTSOUND8 pds,
152     LPUNKNOWN * ppunk);
153
154 struct IDirectSound_IDirectSound {
155     const IDirectSoundVtbl     *lpVtbl;
156     LONG                        ref;
157     LPDIRECTSOUND8              pds;
158 };
159
160 HRESULT IDirectSound_IDirectSound_Create(
161     LPDIRECTSOUND8 pds,
162     LPDIRECTSOUND * ppds);
163
164 /*****************************************************************************
165  * IDirectSound8 COM components
166  */
167 struct IDirectSound8_IUnknown {
168     const IUnknownVtbl         *lpVtbl;
169     LONG                        ref;
170     LPDIRECTSOUND8              pds;
171 };
172
173 HRESULT IDirectSound8_IUnknown_Create(
174     LPDIRECTSOUND8 pds,
175     LPUNKNOWN * ppunk);
176
177 struct IDirectSound8_IDirectSound {
178     const IDirectSoundVtbl     *lpVtbl;
179     LONG                        ref;
180     LPDIRECTSOUND8              pds;
181 };
182
183 HRESULT IDirectSound8_IDirectSound_Create(
184     LPDIRECTSOUND8 pds,
185     LPDIRECTSOUND * ppds);
186
187 struct IDirectSound8_IDirectSound8 {
188     const IDirectSound8Vtbl    *lpVtbl;
189     LONG                        ref;
190     LPDIRECTSOUND8              pds;
191 };
192
193 HRESULT IDirectSound8_IDirectSound8_Create(
194     LPDIRECTSOUND8 pds,
195     LPDIRECTSOUND8 * ppds);
196
197 /*****************************************************************************
198  * IDirectSoundBuffer implementation structure
199  */
200 struct IDirectSoundBufferImpl
201 {
202     /* FIXME: document */
203     /* IUnknown fields */
204     const IDirectSoundBuffer8Vtbl *lpVtbl;
205     LONG                        ref;
206     /* IDirectSoundBufferImpl fields */
207     SecondaryBufferImpl*        secondary;
208     DirectSoundDevice*          device;
209     CRITICAL_SECTION            lock;
210     PIDSDRIVERBUFFER            hwbuf;
211     PWAVEFORMATEX               pwfx;
212     BufferMemory*               buffer;
213     DWORD                       playflags,state,leadin;
214     DWORD                       playpos,startpos,writelead,buflen;
215     DWORD                       nAvgBytesPerSec;
216     DWORD                       freq;
217     DSVOLUMEPAN                 volpan, cvolpan;
218     DSBUFFERDESC                dsbd;
219     /* used for frequency conversion (PerfectPitch) */
220     ULONG                       freqAdjust, freqAcc;
221     /* used for intelligent (well, sort of) prebuffering */
222     DWORD                       probably_valid_to, last_playpos;
223     DWORD                       primary_mixpos, buf_mixpos;
224     BOOL                        need_remix;
225
226     /* IDirectSoundNotifyImpl fields */
227     IDirectSoundNotifyImpl*     notify;
228     LPDSBPOSITIONNOTIFY         notifies;
229     int                         nrofnotifies;
230     PIDSDRIVERNOTIFY            hwnotify;
231
232     /* DirectSound3DBuffer fields */
233     IDirectSound3DBufferImpl*   ds3db;
234     DS3DBUFFER                  ds3db_ds3db;
235     LONG                        ds3db_lVolume;
236     BOOL                        ds3db_need_recalc;
237
238     /* IKsPropertySet fields */
239     IKsBufferPropertySetImpl*   iks;
240 };
241
242 HRESULT IDirectSoundBufferImpl_Create(
243     DirectSoundDevice *device,
244     IDirectSoundBufferImpl **ppdsb,
245     LPCDSBUFFERDESC dsbd);
246 HRESULT IDirectSoundBufferImpl_Destroy(
247     IDirectSoundBufferImpl *pdsb);
248 HRESULT IDirectSoundBufferImpl_Duplicate(
249     DirectSoundDevice *device,
250     IDirectSoundBufferImpl **ppdsb,
251     IDirectSoundBufferImpl *pdsb);
252
253 /*****************************************************************************
254  * SecondaryBuffer implementation structure
255  */
256 struct SecondaryBufferImpl
257 {
258     const IDirectSoundBuffer8Vtbl *lpVtbl;
259     LONG                        ref;
260     IDirectSoundBufferImpl*     dsb;
261 };
262
263 HRESULT SecondaryBufferImpl_Create(
264     IDirectSoundBufferImpl *dsb,
265     SecondaryBufferImpl **pdsb);
266 HRESULT SecondaryBufferImpl_Destroy(
267     SecondaryBufferImpl *pdsb);
268
269 /*****************************************************************************
270  * PrimaryBuffer implementation structure
271  */
272 struct PrimaryBufferImpl
273 {
274     const IDirectSoundBuffer8Vtbl *lpVtbl;
275     LONG                        ref;
276     DirectSoundDevice*          device;
277 };
278
279 HRESULT PrimaryBufferImpl_Create(
280     DirectSoundDevice * device,
281     PrimaryBufferImpl **ppdsb,
282     LPCDSBUFFERDESC dsbd);
283
284 /*****************************************************************************
285  * IDirectSoundCapture implementation structure
286  */
287 struct IDirectSoundCaptureImpl
288 {
289     /* IUnknown fields */
290     const IDirectSoundCaptureVtbl     *lpVtbl;
291     LONG                               ref;
292
293     DirectSoundCaptureDevice          *device;
294 };
295
296 HRESULT IDirectSoundCaptureImpl_Create(
297     LPDIRECTSOUNDCAPTURE8 * ppds);
298
299 /*****************************************************************************
300  * DirectSoundCaptureDevice implementation structure
301  */
302 struct DirectSoundCaptureDevice
303 {
304     /* IDirectSoundCaptureImpl fields */
305     GUID                               guid;
306     LONG                               ref;
307
308     /* DirectSound driver stuff */
309     PIDSCDRIVER                        driver;
310     DSDRIVERDESC                       drvdesc;
311     DSCDRIVERCAPS                      drvcaps;
312     PIDSCDRIVERBUFFER                  hwbuf;
313
314     /* wave driver info */
315     HWAVEIN                            hwi;
316
317     /* more stuff */
318     LPBYTE                             buffer;
319     DWORD                              buflen;
320     DWORD                              read_position;
321
322     PWAVEFORMATEX                      pwfx;
323
324     IDirectSoundCaptureBufferImpl*     capture_buffer;
325     DWORD                              state;
326     LPWAVEHDR                          pwave;
327     int                                nrofpwaves;
328     int                                index;
329     CRITICAL_SECTION                   lock;
330 };
331
332 HRESULT DirectSoundCaptureDevice_Create(
333     DirectSoundCaptureDevice ** ppDevice);
334
335 HRESULT DirectSoundCaptureDevice_Initialize(
336     DirectSoundCaptureDevice ** ppDevice,
337     LPCGUID lpcGUID);
338
339 ULONG DirectSoundCaptureDevice_AddRef(
340     DirectSoundCaptureDevice * device);
341
342 ULONG DirectSoundCaptureDevice_Release(
343     DirectSoundCaptureDevice * device);
344
345 /*****************************************************************************
346  * IDirectSoundCaptureBuffer implementation structure
347  */
348 struct IDirectSoundCaptureBufferImpl
349 {
350     /* IUnknown fields */
351     const IDirectSoundCaptureBuffer8Vtbl *lpVtbl;
352     LONG                                ref;
353
354     /* IDirectSoundCaptureBufferImpl fields */
355     DirectSoundCaptureDevice*           device;
356     /* FIXME: don't need this */
357     LPDSCBUFFERDESC                     pdscbd;
358     DWORD                               flags;
359
360     /* IDirectSoundCaptureNotifyImpl fields */
361     IDirectSoundCaptureNotifyImpl*      notify;
362     LPDSBPOSITIONNOTIFY                 notifies;
363     int                                 nrofnotifies;
364     PIDSDRIVERNOTIFY                    hwnotify;
365 };
366
367 HRESULT IDirectSoundCaptureBufferImpl_Create(
368     DirectSoundCaptureDevice *device,
369     IDirectSoundCaptureBufferImpl ** ppobj,
370     LPCDSCBUFFERDESC lpcDSCBufferDesc);
371
372 /*****************************************************************************
373  * IDirectSoundFullDuplex implementation structure
374  */
375 struct IDirectSoundFullDuplexImpl
376 {
377     /* IUnknown fields */
378     const IDirectSoundFullDuplexVtbl *lpVtbl;
379     LONG                        ref;
380
381     /* IDirectSoundFullDuplexImpl fields */
382 };
383
384 /*****************************************************************************
385  * IDirectSoundNotify implementation structure
386  */
387 struct IDirectSoundNotifyImpl
388 {
389     /* IUnknown fields */
390     const IDirectSoundNotifyVtbl *lpVtbl;
391     LONG                        ref;
392     IDirectSoundBufferImpl*     dsb;
393 };
394
395 HRESULT IDirectSoundNotifyImpl_Create(
396     IDirectSoundBufferImpl *dsb,
397     IDirectSoundNotifyImpl **pdsn);
398 HRESULT IDirectSoundNotifyImpl_Destroy(
399     IDirectSoundNotifyImpl *pdsn);
400
401 /*****************************************************************************
402  * IDirectSoundCaptureNotify implementation structure
403  */
404 struct IDirectSoundCaptureNotifyImpl
405 {
406     /* IUnknown fields */
407     const IDirectSoundNotifyVtbl       *lpVtbl;
408     LONG                                ref;
409     IDirectSoundCaptureBufferImpl*      dscb;
410 };
411
412 HRESULT IDirectSoundCaptureNotifyImpl_Create(
413     IDirectSoundCaptureBufferImpl *dscb,
414     IDirectSoundCaptureNotifyImpl ** pdscn);
415
416 /*****************************************************************************
417  *  IDirectSound3DListener implementation structure
418  */
419 struct IDirectSound3DListenerImpl
420 {
421     /* IUnknown fields */
422     const IDirectSound3DListenerVtbl *lpVtbl;
423     LONG                        ref;
424     /* IDirectSound3DListenerImpl fields */
425     DirectSoundDevice*          device;
426 };
427
428 HRESULT IDirectSound3DListenerImpl_Create(
429     DirectSoundDevice           *device,
430     IDirectSound3DListenerImpl **pdsl);
431
432 /*****************************************************************************
433  *  IKsBufferPropertySet implementation structure
434  */
435 struct IKsBufferPropertySetImpl
436 {
437     /* IUnknown fields */
438     const IKsPropertySetVtbl   *lpVtbl;
439     LONG                        ref;
440     /* IKsPropertySetImpl fields */
441     IDirectSoundBufferImpl*     dsb;
442 };
443
444 HRESULT IKsBufferPropertySetImpl_Create(
445     IDirectSoundBufferImpl *dsb,
446     IKsBufferPropertySetImpl **piks);
447 HRESULT IKsBufferPropertySetImpl_Destroy(
448     IKsBufferPropertySetImpl *piks);
449
450 /*****************************************************************************
451  *  IKsPrivatePropertySet implementation structure
452  */
453 struct IKsPrivatePropertySetImpl
454 {
455     /* IUnknown fields */
456     const IKsPropertySetVtbl   *lpVtbl;
457     LONG                        ref;
458 };
459
460 HRESULT IKsPrivatePropertySetImpl_Create(
461     IKsPrivatePropertySetImpl **piks);
462
463 /*****************************************************************************
464  * IDirectSound3DBuffer implementation structure
465  */
466 struct IDirectSound3DBufferImpl
467 {
468     /* IUnknown fields */
469     const IDirectSound3DBufferVtbl *lpVtbl;
470     LONG                        ref;
471     /* IDirectSound3DBufferImpl fields */
472     IDirectSoundBufferImpl*     dsb;
473 };
474
475 HRESULT IDirectSound3DBufferImpl_Create(
476     IDirectSoundBufferImpl *dsb,
477     IDirectSound3DBufferImpl **pds3db);
478 HRESULT IDirectSound3DBufferImpl_Destroy(
479     IDirectSound3DBufferImpl *pds3db);
480
481 /*******************************************************************************
482  * DirectSound ClassFactory implementation structure
483  */
484 struct IClassFactoryImpl
485 {
486     /* IUnknown fields */
487     const IClassFactoryVtbl    *lpVtbl;
488     LONG                        ref;
489 };
490
491 extern IClassFactoryImpl DSOUND_CAPTURE_CF;
492 extern IClassFactoryImpl DSOUND_FULLDUPLEX_CF;
493
494 /*******************************************************************************
495  */
496
497 /* dsound.c */
498
499 HRESULT DSOUND_Create(LPDIRECTSOUND *ppDS, IUnknown *pUnkOuter);
500 HRESULT DSOUND_Create8(LPDIRECTSOUND8 *ppDS, IUnknown *pUnkOuter);
501
502 /* primary.c */
503
504 HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device);
505 HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device);
506 HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device);
507 HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device);
508 HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos);
509 HRESULT DSOUND_PrimarySetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX wfex);
510
511 /* buffer.c */
512
513 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This, DWORD pplay, DWORD pwrite);
514
515 /* mixer.c */
516
517 void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len);
518 void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb);
519 void DSOUND_MixCancelAt(IDirectSoundBufferImpl *dsb, DWORD buf_writepos);
520 void DSOUND_WaveQueue(DirectSoundDevice *device, DWORD mixq);
521 void DSOUND_PerformMix(DirectSoundDevice *device);
522 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
523 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan);
524 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
525 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
526 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
527
528 /* sound3d.c */
529
530 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb);
531
532 /* capture.c */
533
534 HRESULT WINAPI IDirectSoundCaptureImpl_CreateCaptureBuffer(
535     LPDIRECTSOUNDCAPTURE iface,
536     LPCDSCBUFFERDESC lpcDSCBufferDesc,
537     LPDIRECTSOUNDCAPTUREBUFFER* lplpDSCaptureBuffer,
538     LPUNKNOWN pUnk);
539 HRESULT WINAPI IDirectSoundCaptureImpl_GetCaps(
540     LPDIRECTSOUNDCAPTURE iface,
541     LPDSCCAPS lpDSCCaps);
542 HRESULT WINAPI IDirectSoundCaptureImpl_Initialize(
543     LPDIRECTSOUNDCAPTURE iface,
544     LPCGUID lpcGUID);
545
546 #define STATE_STOPPED   0
547 #define STATE_STARTING  1
548 #define STATE_PLAYING   2
549 #define STATE_CAPTURING 2
550 #define STATE_STOPPING  3
551
552 #define DSOUND_FREQSHIFT (14)
553
554 extern DirectSoundDevice* DSOUND_renderer[MAXWAVEDRIVERS];
555 extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS];
556
557 extern DirectSoundCaptureDevice * DSOUND_capture[MAXWAVEDRIVERS];
558 extern GUID DSOUND_capture_guids[MAXWAVEDRIVERS];
559
560 HRESULT mmErr(UINT err);
561 void setup_dsound_options(void);
562 const char * get_device_id(LPCGUID pGuid);
563 const char * dumpCooperativeLevel(DWORD level);