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