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