kernel32: FindExSearchLimitToDirectories has no effect on FindFirstFileEx.
[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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 /* Linux does not support better timing than 10ms */
23 #define DS_TIME_RES 2  /* Resolution of multimedia timer */
24 #define DS_TIME_DEL 10  /* Delay of multimedia timer callback, and duration of HEL fragment */
25
26 #include "wine/list.h"
27
28 /* direct sound hardware acceleration levels */
29 #define DS_HW_ACCEL_FULL        0       /* default on Windows 98 */
30 #define DS_HW_ACCEL_STANDARD    1       /* default on Windows 2000 */
31 #define DS_HW_ACCEL_BASIC       2
32 #define DS_HW_ACCEL_EMULATION   3
33
34 extern int ds_emuldriver;
35 extern int ds_hel_buflen;
36 extern int ds_snd_queue_max;
37 extern int ds_snd_queue_min;
38 extern int ds_hw_accel;
39 extern int ds_default_playback;
40 extern int ds_default_capture;
41 extern int ds_default_sample_rate;
42 extern int ds_default_bits_per_sample;
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 IDirectSoundFullDuplex_IUnknown IDirectSoundFullDuplex_IUnknown;
58 typedef struct IDirectSoundFullDuplex_IDirectSound IDirectSoundFullDuplex_IDirectSound;
59 typedef struct IDirectSoundFullDuplex_IDirectSound8 IDirectSoundFullDuplex_IDirectSound8;
60 typedef struct IDirectSoundFullDuplex_IDirectSoundCapture IDirectSoundFullDuplex_IDirectSoundCapture;
61 typedef struct IDirectSoundNotifyImpl        IDirectSoundNotifyImpl;
62 typedef struct IDirectSoundCaptureNotifyImpl IDirectSoundCaptureNotifyImpl;
63 typedef struct IDirectSound3DListenerImpl    IDirectSound3DListenerImpl;
64 typedef struct IDirectSound3DBufferImpl      IDirectSound3DBufferImpl;
65 typedef struct IKsBufferPropertySetImpl      IKsBufferPropertySetImpl;
66 typedef struct IKsPrivatePropertySetImpl     IKsPrivatePropertySetImpl;
67 typedef struct PrimaryBufferImpl             PrimaryBufferImpl;
68 typedef struct SecondaryBufferImpl           SecondaryBufferImpl;
69 typedef struct DirectSoundDevice             DirectSoundDevice;
70 typedef struct DirectSoundCaptureDevice      DirectSoundCaptureDevice;
71
72 /*****************************************************************************
73  * IDirectSoundDevice implementation structure
74  */
75 struct DirectSoundDevice
76 {
77     LONG                        ref;
78
79     GUID                        guid;
80     PIDSDRIVER                  driver;
81     DSDRIVERDESC                drvdesc;
82     DSDRIVERCAPS                drvcaps;
83     DWORD                       priolevel;
84     PWAVEFORMATEX               pwfx;
85     HWAVEOUT                    hwo;
86     LPWAVEHDR                   pwave;
87     UINT                        timerID, pwplay, pwqueue, prebuf, helfrags;
88     DWORD                       fraglen;
89     PIDSDRIVERBUFFER            hwbuf;
90     LPBYTE                      buffer;
91     DWORD                       writelead, buflen, state, playpos, mixpos;
92     int                         nrofbuffers;
93     IDirectSoundBufferImpl**    buffers;
94     RTL_RWLOCK                  buffer_list_lock;
95     CRITICAL_SECTION            mixlock;
96     PrimaryBufferImpl*          primary;
97     DSBUFFERDESC                dsbd;
98     DWORD                       speaker_config;
99     LPBYTE                      tmp_buffer;
100     DWORD                       tmp_buffer_len;
101
102     /* DirectSound3DListener fields */
103     IDirectSound3DListenerImpl* listener;
104     DS3DLISTENER                ds3dl;
105     BOOL                        ds3dl_need_recalc;
106 };
107
108 /* reference counted buffer memory for duplicated buffer memory */
109 typedef struct BufferMemory
110 {
111     LONG                        ref;
112     LPBYTE                      memory;
113     struct list buffers;
114 } BufferMemory;
115
116 ULONG DirectSoundDevice_Release(DirectSoundDevice * device);
117 HRESULT DirectSoundDevice_Initialize(
118     DirectSoundDevice ** ppDevice,
119     LPCGUID lpcGUID);
120 HRESULT DirectSoundDevice_AddBuffer(
121     DirectSoundDevice * device,
122     IDirectSoundBufferImpl * pDSB);
123 HRESULT DirectSoundDevice_RemoveBuffer(
124     DirectSoundDevice * device,
125     IDirectSoundBufferImpl * pDSB);
126 HRESULT DirectSoundDevice_GetCaps(DirectSoundDevice * device, LPDSCAPS lpDSCaps);
127 HRESULT DirectSoundDevice_CreateSoundBuffer(
128     DirectSoundDevice * device,
129     LPCDSBUFFERDESC dsbd,
130     LPLPDIRECTSOUNDBUFFER ppdsb,
131     LPUNKNOWN lpunk,
132     BOOL from8);
133 HRESULT DirectSoundDevice_DuplicateSoundBuffer(
134     DirectSoundDevice * device,
135     LPDIRECTSOUNDBUFFER psb,
136     LPLPDIRECTSOUNDBUFFER ppdsb);
137 HRESULT DirectSoundDevice_SetCooperativeLevel(
138     DirectSoundDevice * devcie,
139     HWND hwnd,
140     DWORD level);
141 HRESULT DirectSoundDevice_Compact(DirectSoundDevice * device);
142 HRESULT DirectSoundDevice_GetSpeakerConfig(
143     DirectSoundDevice * device,
144     LPDWORD lpdwSpeakerConfig);
145 HRESULT DirectSoundDevice_SetSpeakerConfig(
146     DirectSoundDevice * device,
147     DWORD config);
148
149 /*****************************************************************************
150  * IDirectSoundBuffer implementation structure
151  */
152 struct IDirectSoundBufferImpl
153 {
154     /* FIXME: document */
155     /* IUnknown fields */
156     const IDirectSoundBuffer8Vtbl *lpVtbl;
157     LONG                        ref;
158     /* IDirectSoundBufferImpl fields */
159     SecondaryBufferImpl*        secondary;
160     DirectSoundDevice*          device;
161     RTL_RWLOCK                  lock;
162     PIDSDRIVERBUFFER            hwbuf;
163     PWAVEFORMATEX               pwfx;
164     BufferMemory*               buffer;
165     LPBYTE                      tmp_buffer;
166     DWORD                       playflags,state,leadin;
167     DWORD                       writelead,buflen;
168     DWORD                       nAvgBytesPerSec;
169     DWORD                       freq, tmp_buffer_len, max_buffer_len;
170     DSVOLUMEPAN                 volpan;
171     DSBUFFERDESC                dsbd;
172     /* used for frequency conversion (PerfectPitch) */
173     ULONG                       freqneeded, freqAdjust, freqAcc, freqAccNext;
174     /* used for mixing */
175     DWORD                       primary_mixpos, buf_mixpos, sec_mixpos;
176
177     /* IDirectSoundNotifyImpl fields */
178     IDirectSoundNotifyImpl*     notify;
179     LPDSBPOSITIONNOTIFY         notifies;
180     int                         nrofnotifies;
181     PIDSDRIVERNOTIFY            hwnotify;
182
183     /* DirectSound3DBuffer fields */
184     IDirectSound3DBufferImpl*   ds3db;
185     DS3DBUFFER                  ds3db_ds3db;
186     LONG                        ds3db_lVolume;
187     BOOL                        ds3db_need_recalc;
188
189     /* IKsPropertySet fields */
190     IKsBufferPropertySetImpl*   iks;
191
192     struct list entry;
193 };
194
195 HRESULT IDirectSoundBufferImpl_Create(
196     DirectSoundDevice *device,
197     IDirectSoundBufferImpl **ppdsb,
198     LPCDSBUFFERDESC dsbd);
199 HRESULT IDirectSoundBufferImpl_Destroy(
200     IDirectSoundBufferImpl *pdsb);
201 HRESULT IDirectSoundBufferImpl_Duplicate(
202     DirectSoundDevice *device,
203     IDirectSoundBufferImpl **ppdsb,
204     IDirectSoundBufferImpl *pdsb);
205
206 /*****************************************************************************
207  * SecondaryBuffer implementation structure
208  */
209 struct SecondaryBufferImpl
210 {
211     const IDirectSoundBuffer8Vtbl *lpVtbl;
212     LONG                        ref;
213     IDirectSoundBufferImpl*     dsb;
214 };
215
216 HRESULT SecondaryBufferImpl_Create(
217     IDirectSoundBufferImpl *dsb,
218     SecondaryBufferImpl **pdsb);
219
220 /*****************************************************************************
221  * PrimaryBuffer implementation structure
222  */
223 struct PrimaryBufferImpl
224 {
225     const IDirectSoundBufferVtbl *lpVtbl;
226     LONG                        ref;
227     DirectSoundDevice*          device;
228 };
229
230 HRESULT PrimaryBufferImpl_Create(
231     DirectSoundDevice * device,
232     PrimaryBufferImpl **ppdsb,
233     LPCDSBUFFERDESC dsbd);
234
235 /*****************************************************************************
236  * DirectSoundCaptureDevice implementation structure
237  */
238 struct DirectSoundCaptureDevice
239 {
240     /* IDirectSoundCaptureImpl fields */
241     GUID                               guid;
242     LONG                               ref;
243
244     /* DirectSound driver stuff */
245     PIDSCDRIVER                        driver;
246     DSDRIVERDESC                       drvdesc;
247     DSCDRIVERCAPS                      drvcaps;
248     PIDSCDRIVERBUFFER                  hwbuf;
249
250     /* wave driver info */
251     HWAVEIN                            hwi;
252
253     /* more stuff */
254     LPBYTE                             buffer;
255     DWORD                              buflen;
256
257     PWAVEFORMATEX                      pwfx;
258
259     IDirectSoundCaptureBufferImpl*     capture_buffer;
260     DWORD                              state;
261     LPWAVEHDR                          pwave;
262     int                                nrofpwaves;
263     int                                index;
264     CRITICAL_SECTION                   lock;
265 };
266
267 HRESULT DirectSoundCaptureDevice_Initialize(
268     DirectSoundCaptureDevice ** ppDevice,
269     LPCGUID lpcGUID);
270 ULONG DirectSoundCaptureDevice_Release(
271     DirectSoundCaptureDevice * device);
272
273 /*****************************************************************************
274  * IDirectSoundCaptureBuffer implementation structure
275  */
276 struct IDirectSoundCaptureBufferImpl
277 {
278     /* IUnknown fields */
279     const IDirectSoundCaptureBuffer8Vtbl *lpVtbl;
280     LONG                                ref;
281
282     /* IDirectSoundCaptureBufferImpl fields */
283     DirectSoundCaptureDevice*           device;
284     /* FIXME: don't need this */
285     LPDSCBUFFERDESC                     pdscbd;
286     DWORD                               flags;
287
288     /* IDirectSoundCaptureNotifyImpl fields */
289     IDirectSoundCaptureNotifyImpl*      notify;
290     LPDSBPOSITIONNOTIFY                 notifies;
291     int                                 nrofnotifies;
292     PIDSDRIVERNOTIFY                    hwnotify;
293 };
294
295 HRESULT IDirectSoundCaptureBufferImpl_Create(
296     DirectSoundCaptureDevice *device,
297     IDirectSoundCaptureBufferImpl ** ppobj,
298     LPCDSCBUFFERDESC lpcDSCBufferDesc);
299
300 /*****************************************************************************
301  * IDirectSoundFullDuplex implementation structure
302  */
303 struct IDirectSoundFullDuplexImpl
304 {
305     /* IUnknown fields */
306     const IDirectSoundFullDuplexVtbl *lpVtbl;
307     LONG                              ref;
308
309     /* IDirectSoundFullDuplexImpl fields */
310     DirectSoundDevice                *renderer_device;
311     DirectSoundCaptureDevice         *capture_device;
312
313     LPUNKNOWN                         pUnknown;
314     LPDIRECTSOUND                     pDS;
315     LPDIRECTSOUND8                    pDS8;
316     LPDIRECTSOUNDCAPTURE              pDSC;
317 };
318
319 /*****************************************************************************
320  * IDirectSoundFullDuplex COM components
321  */
322 struct IDirectSoundFullDuplex_IUnknown {
323     const IUnknownVtbl         *lpVtbl;
324     LONG                        ref;
325     IDirectSoundFullDuplexImpl *pdsfd;
326 };
327
328 struct IDirectSoundFullDuplex_IDirectSound {
329     const IDirectSoundVtbl     *lpVtbl;
330     LONG                        ref;
331     IDirectSoundFullDuplexImpl *pdsfd;
332 };
333
334 struct IDirectSoundFullDuplex_IDirectSound8 {
335     const IDirectSound8Vtbl    *lpVtbl;
336     LONG                        ref;
337     IDirectSoundFullDuplexImpl *pdsfd;
338 };
339
340 struct IDirectSoundFullDuplex_IDirectSoundCapture {
341     const IDirectSoundCaptureVtbl *lpVtbl;
342     LONG                           ref;
343     IDirectSoundFullDuplexImpl    *pdsfd;
344 };
345
346 /*****************************************************************************
347  *  IDirectSound3DListener implementation structure
348  */
349 struct IDirectSound3DListenerImpl
350 {
351     /* IUnknown fields */
352     const IDirectSound3DListenerVtbl *lpVtbl;
353     LONG                        ref;
354     /* IDirectSound3DListenerImpl fields */
355     DirectSoundDevice*          device;
356 };
357
358 HRESULT IDirectSound3DListenerImpl_Create(
359     DirectSoundDevice           *device,
360     IDirectSound3DListenerImpl **pdsl);
361
362 /*****************************************************************************
363  *  IKsBufferPropertySet implementation structure
364  */
365 struct IKsBufferPropertySetImpl
366 {
367     /* IUnknown fields */
368     const IKsPropertySetVtbl   *lpVtbl;
369     LONG                        ref;
370     /* IKsPropertySetImpl fields */
371     IDirectSoundBufferImpl*     dsb;
372 };
373
374 HRESULT IKsBufferPropertySetImpl_Create(
375     IDirectSoundBufferImpl *dsb,
376     IKsBufferPropertySetImpl **piks);
377 HRESULT IKsBufferPropertySetImpl_Destroy(
378     IKsBufferPropertySetImpl *piks);
379
380 /*****************************************************************************
381  *  IKsPrivatePropertySet implementation structure
382  */
383 struct IKsPrivatePropertySetImpl
384 {
385     /* IUnknown fields */
386     const IKsPropertySetVtbl   *lpVtbl;
387     LONG                        ref;
388 };
389
390 HRESULT IKsPrivatePropertySetImpl_Create(
391     REFIID riid,
392     IKsPrivatePropertySetImpl **piks);
393
394 /*****************************************************************************
395  * IDirectSound3DBuffer implementation structure
396  */
397 struct IDirectSound3DBufferImpl
398 {
399     /* IUnknown fields */
400     const IDirectSound3DBufferVtbl *lpVtbl;
401     LONG                        ref;
402     /* IDirectSound3DBufferImpl fields */
403     IDirectSoundBufferImpl*     dsb;
404 };
405
406 HRESULT IDirectSound3DBufferImpl_Create(
407     IDirectSoundBufferImpl *dsb,
408     IDirectSound3DBufferImpl **pds3db);
409 HRESULT IDirectSound3DBufferImpl_Destroy(
410     IDirectSound3DBufferImpl *pds3db);
411
412 /*******************************************************************************
413  */
414
415 /* dsound.c */
416
417 HRESULT DSOUND_Create(REFIID riid, LPDIRECTSOUND *ppDS);
418 HRESULT DSOUND_Create8(REFIID riid, LPDIRECTSOUND8 *ppDS);
419
420 /* primary.c */
421
422 DWORD DSOUND_fraglen(DWORD nSamplesPerSec, DWORD nBlockAlign);
423 HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device);
424 HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device);
425 HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device);
426 HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device);
427 HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos);
428 HRESULT DSOUND_PrimarySetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX wfex, BOOL forced);
429 HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave);
430
431 /* duplex.c */
432  
433 HRESULT DSOUND_FullDuplexCreate(REFIID riid, LPDIRECTSOUNDFULLDUPLEX* ppDSFD);
434
435 /* mixer.c */
436
437 void DSOUND_CheckEvent(const IDirectSoundBufferImpl *dsb, DWORD playpos, int len);
438 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
439 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan);
440 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
441 void DSOUND_MixToTemporary(const IDirectSoundBufferImpl *dsb, DWORD writepos, DWORD mixlen);
442 DWORD DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl *dsb, DWORD secpos, DWORD secmixpos, DWORD* overshot);
443
444 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2);
445 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
446
447 /* sound3d.c */
448
449 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb);
450
451 /* capture.c */
452  
453 HRESULT DSOUND_CaptureCreate(REFIID riid, LPDIRECTSOUNDCAPTURE *ppDSC);
454 HRESULT DSOUND_CaptureCreate8(REFIID riid, LPDIRECTSOUNDCAPTURE8 *ppDSC8);
455 HRESULT WINAPI IDirectSoundCaptureImpl_CreateCaptureBuffer(
456     LPDIRECTSOUNDCAPTURE iface,
457     LPCDSCBUFFERDESC lpcDSCBufferDesc,
458     LPDIRECTSOUNDCAPTUREBUFFER* lplpDSCaptureBuffer,
459     LPUNKNOWN pUnk);
460 HRESULT WINAPI IDirectSoundCaptureImpl_GetCaps(
461     LPDIRECTSOUNDCAPTURE iface,
462     LPDSCCAPS lpDSCCaps);
463 HRESULT WINAPI IDirectSoundCaptureImpl_Initialize(
464     LPDIRECTSOUNDCAPTURE iface,
465     LPCGUID lpcGUID);
466
467 #define STATE_STOPPED   0
468 #define STATE_STARTING  1
469 #define STATE_PLAYING   2
470 #define STATE_CAPTURING 2
471 #define STATE_STOPPING  3
472
473 #define DSOUND_FREQSHIFT (20)
474
475 extern DirectSoundDevice* DSOUND_renderer[MAXWAVEDRIVERS];
476 extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS];
477
478 extern DirectSoundCaptureDevice * DSOUND_capture[MAXWAVEDRIVERS];
479 extern GUID DSOUND_capture_guids[MAXWAVEDRIVERS];
480
481 HRESULT mmErr(UINT err);
482 void setup_dsound_options(void);
483 const char * dumpCooperativeLevel(DWORD level);