dinput: Use correct data structure for EVIOCGABS instead of an array.
[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     DWORD                              read_position;
257
258     PWAVEFORMATEX                      pwfx;
259
260     IDirectSoundCaptureBufferImpl*     capture_buffer;
261     DWORD                              state;
262     LPWAVEHDR                          pwave;
263     int                                nrofpwaves;
264     int                                index;
265     CRITICAL_SECTION                   lock;
266 };
267
268 HRESULT DirectSoundCaptureDevice_Initialize(
269     DirectSoundCaptureDevice ** ppDevice,
270     LPCGUID lpcGUID);
271 ULONG DirectSoundCaptureDevice_Release(
272     DirectSoundCaptureDevice * device);
273
274 /*****************************************************************************
275  * IDirectSoundCaptureBuffer implementation structure
276  */
277 struct IDirectSoundCaptureBufferImpl
278 {
279     /* IUnknown fields */
280     const IDirectSoundCaptureBuffer8Vtbl *lpVtbl;
281     LONG                                ref;
282
283     /* IDirectSoundCaptureBufferImpl fields */
284     DirectSoundCaptureDevice*           device;
285     /* FIXME: don't need this */
286     LPDSCBUFFERDESC                     pdscbd;
287     DWORD                               flags;
288
289     /* IDirectSoundCaptureNotifyImpl fields */
290     IDirectSoundCaptureNotifyImpl*      notify;
291     LPDSBPOSITIONNOTIFY                 notifies;
292     int                                 nrofnotifies;
293     PIDSDRIVERNOTIFY                    hwnotify;
294 };
295
296 HRESULT IDirectSoundCaptureBufferImpl_Create(
297     DirectSoundCaptureDevice *device,
298     IDirectSoundCaptureBufferImpl ** ppobj,
299     LPCDSCBUFFERDESC lpcDSCBufferDesc);
300
301 /*****************************************************************************
302  * IDirectSoundFullDuplex implementation structure
303  */
304 struct IDirectSoundFullDuplexImpl
305 {
306     /* IUnknown fields */
307     const IDirectSoundFullDuplexVtbl *lpVtbl;
308     LONG                              ref;
309
310     /* IDirectSoundFullDuplexImpl fields */
311     DirectSoundDevice                *renderer_device;
312     DirectSoundCaptureDevice         *capture_device;
313
314     LPUNKNOWN                         pUnknown;
315     LPDIRECTSOUND                     pDS;
316     LPDIRECTSOUND8                    pDS8;
317     LPDIRECTSOUNDCAPTURE              pDSC;
318 };
319
320 /*****************************************************************************
321  * IDirectSoundFullDuplex COM components
322  */
323 struct IDirectSoundFullDuplex_IUnknown {
324     const IUnknownVtbl         *lpVtbl;
325     LONG                        ref;
326     IDirectSoundFullDuplexImpl *pdsfd;
327 };
328
329 struct IDirectSoundFullDuplex_IDirectSound {
330     const IDirectSoundVtbl     *lpVtbl;
331     LONG                        ref;
332     IDirectSoundFullDuplexImpl *pdsfd;
333 };
334
335 struct IDirectSoundFullDuplex_IDirectSound8 {
336     const IDirectSound8Vtbl    *lpVtbl;
337     LONG                        ref;
338     IDirectSoundFullDuplexImpl *pdsfd;
339 };
340
341 struct IDirectSoundFullDuplex_IDirectSoundCapture {
342     const IDirectSoundCaptureVtbl *lpVtbl;
343     LONG                           ref;
344     IDirectSoundFullDuplexImpl    *pdsfd;
345 };
346
347 /*****************************************************************************
348  *  IDirectSound3DListener implementation structure
349  */
350 struct IDirectSound3DListenerImpl
351 {
352     /* IUnknown fields */
353     const IDirectSound3DListenerVtbl *lpVtbl;
354     LONG                        ref;
355     /* IDirectSound3DListenerImpl fields */
356     DirectSoundDevice*          device;
357 };
358
359 HRESULT IDirectSound3DListenerImpl_Create(
360     DirectSoundDevice           *device,
361     IDirectSound3DListenerImpl **pdsl);
362
363 /*****************************************************************************
364  *  IKsBufferPropertySet implementation structure
365  */
366 struct IKsBufferPropertySetImpl
367 {
368     /* IUnknown fields */
369     const IKsPropertySetVtbl   *lpVtbl;
370     LONG                        ref;
371     /* IKsPropertySetImpl fields */
372     IDirectSoundBufferImpl*     dsb;
373 };
374
375 HRESULT IKsBufferPropertySetImpl_Create(
376     IDirectSoundBufferImpl *dsb,
377     IKsBufferPropertySetImpl **piks);
378 HRESULT IKsBufferPropertySetImpl_Destroy(
379     IKsBufferPropertySetImpl *piks);
380
381 /*****************************************************************************
382  *  IKsPrivatePropertySet implementation structure
383  */
384 struct IKsPrivatePropertySetImpl
385 {
386     /* IUnknown fields */
387     const IKsPropertySetVtbl   *lpVtbl;
388     LONG                        ref;
389 };
390
391 HRESULT IKsPrivatePropertySetImpl_Create(
392     REFIID riid,
393     IKsPrivatePropertySetImpl **piks);
394
395 /*****************************************************************************
396  * IDirectSound3DBuffer implementation structure
397  */
398 struct IDirectSound3DBufferImpl
399 {
400     /* IUnknown fields */
401     const IDirectSound3DBufferVtbl *lpVtbl;
402     LONG                        ref;
403     /* IDirectSound3DBufferImpl fields */
404     IDirectSoundBufferImpl*     dsb;
405 };
406
407 HRESULT IDirectSound3DBufferImpl_Create(
408     IDirectSoundBufferImpl *dsb,
409     IDirectSound3DBufferImpl **pds3db);
410 HRESULT IDirectSound3DBufferImpl_Destroy(
411     IDirectSound3DBufferImpl *pds3db);
412
413 /*******************************************************************************
414  */
415
416 /* dsound.c */
417
418 HRESULT DSOUND_Create(REFIID riid, LPDIRECTSOUND *ppDS);
419 HRESULT DSOUND_Create8(REFIID riid, LPDIRECTSOUND8 *ppDS);
420
421 /* primary.c */
422
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);
429
430 /* duplex.c */
431  
432 HRESULT DSOUND_FullDuplexCreate(REFIID riid, LPDIRECTSOUNDFULLDUPLEX* ppDSFD);
433
434 /* mixer.c */
435
436 void DSOUND_CheckEvent(const IDirectSoundBufferImpl *dsb, DWORD playpos, int len);
437 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
438 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan);
439 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
440 void DSOUND_MixToTemporary(const IDirectSoundBufferImpl *dsb, DWORD writepos, DWORD mixlen);
441 DWORD DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl *dsb, DWORD secpos, DWORD secmixpos, DWORD* overshot);
442
443 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2);
444 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
445
446 /* sound3d.c */
447
448 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb);
449
450 /* capture.c */
451  
452 HRESULT DSOUND_CaptureCreate(REFIID riid, LPDIRECTSOUNDCAPTURE *ppDSC);
453 HRESULT DSOUND_CaptureCreate8(REFIID riid, LPDIRECTSOUNDCAPTURE8 *ppDSC8);
454 HRESULT WINAPI IDirectSoundCaptureImpl_CreateCaptureBuffer(
455     LPDIRECTSOUNDCAPTURE iface,
456     LPCDSCBUFFERDESC lpcDSCBufferDesc,
457     LPDIRECTSOUNDCAPTUREBUFFER* lplpDSCaptureBuffer,
458     LPUNKNOWN pUnk);
459 HRESULT WINAPI IDirectSoundCaptureImpl_GetCaps(
460     LPDIRECTSOUNDCAPTURE iface,
461     LPDSCCAPS lpDSCCaps);
462 HRESULT WINAPI IDirectSoundCaptureImpl_Initialize(
463     LPDIRECTSOUNDCAPTURE iface,
464     LPCGUID lpcGUID);
465
466 #define STATE_STOPPED   0
467 #define STATE_STARTING  1
468 #define STATE_PLAYING   2
469 #define STATE_CAPTURING 2
470 #define STATE_STOPPING  3
471
472 #define DSOUND_FREQSHIFT (20)
473
474 extern DirectSoundDevice* DSOUND_renderer[MAXWAVEDRIVERS];
475 extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS];
476
477 extern DirectSoundCaptureDevice * DSOUND_capture[MAXWAVEDRIVERS];
478 extern GUID DSOUND_capture_guids[MAXWAVEDRIVERS];
479
480 HRESULT mmErr(UINT err);
481 void setup_dsound_options(void);
482 const char * dumpCooperativeLevel(DWORD level);