user32: Fix a typo in the StretchDIBits stub name.
[wine/multimedia.git] / dlls / dsound / dsound_private.h
blob004ed45f55acedd84938b0ee5ba6b362b915f03d
1 /* DirectSound
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998 Rob Riggs
5 * Copyright 2000-2001 TransGaming Technologies, Inc.
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.
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.
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
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 */
26 #include "wine/list.h"
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
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;
44 /*****************************************************************************
45 * Predeclare the interface implementation structures
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;
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];
80 /*****************************************************************************
81 * IDirectSoundDevice implementation structure
83 struct DirectSoundDevice
85 LONG ref;
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;
110 mixfunc mixfunction;
111 normfunc normfunction;
113 /* DirectSound3DListener fields */
114 IDirectSound3DListenerImpl* listener;
115 DS3DLISTENER ds3dl;
116 BOOL ds3dl_need_recalc;
119 /* reference counted buffer memory for duplicated buffer memory */
120 typedef struct BufferMemory
122 LONG ref;
123 LPBYTE memory;
124 struct list buffers;
125 } BufferMemory;
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);
160 /*****************************************************************************
161 * IDirectSoundBuffer implementation structure
163 struct IDirectSoundBufferImpl
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;
188 /* IDirectSoundNotifyImpl fields */
189 IDirectSoundNotifyImpl* notify;
190 LPDSBPOSITIONNOTIFY notifies;
191 int nrofnotifies;
192 PIDSDRIVERNOTIFY hwnotify;
194 /* DirectSound3DBuffer fields */
195 IDirectSound3DBufferImpl* ds3db;
196 DS3DBUFFER ds3db_ds3db;
197 LONG ds3db_lVolume;
198 BOOL ds3db_need_recalc;
200 /* IKsPropertySet fields */
201 IKsBufferPropertySetImpl* iks;
202 bitsconvertfunc convert;
203 struct list entry;
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);
217 /*****************************************************************************
218 * SecondaryBuffer implementation structure
220 struct SecondaryBufferImpl
222 const IDirectSoundBuffer8Vtbl *lpVtbl;
223 LONG ref;
224 IDirectSoundBufferImpl* dsb;
227 HRESULT SecondaryBufferImpl_Create(
228 IDirectSoundBufferImpl *dsb,
229 SecondaryBufferImpl **pdsb);
231 /*****************************************************************************
232 * PrimaryBuffer implementation structure
234 struct PrimaryBufferImpl
236 const IDirectSoundBufferVtbl *lpVtbl;
237 LONG ref;
238 DirectSoundDevice* device;
241 HRESULT PrimaryBufferImpl_Create(
242 DirectSoundDevice * device,
243 PrimaryBufferImpl **ppdsb,
244 LPCDSBUFFERDESC dsbd);
246 /*****************************************************************************
247 * DirectSoundCaptureDevice implementation structure
249 struct DirectSoundCaptureDevice
251 /* IDirectSoundCaptureImpl fields */
252 GUID guid;
253 LONG ref;
255 /* DirectSound driver stuff */
256 PIDSCDRIVER driver;
257 DSDRIVERDESC drvdesc;
258 DSCDRIVERCAPS drvcaps;
259 PIDSCDRIVERBUFFER hwbuf;
261 /* wave driver info */
262 HWAVEIN hwi;
264 /* more stuff */
265 LPBYTE buffer;
266 DWORD buflen;
268 PWAVEFORMATEX pwfx;
270 IDirectSoundCaptureBufferImpl* capture_buffer;
271 DWORD state;
272 LPWAVEHDR pwave;
273 int nrofpwaves;
274 int index;
275 CRITICAL_SECTION lock;
278 HRESULT DirectSoundCaptureDevice_Initialize(
279 DirectSoundCaptureDevice ** ppDevice,
280 LPCGUID lpcGUID);
281 ULONG DirectSoundCaptureDevice_Release(
282 DirectSoundCaptureDevice * device);
284 /*****************************************************************************
285 * IDirectSoundCaptureBuffer implementation structure
287 struct IDirectSoundCaptureBufferImpl
289 /* IUnknown fields */
290 const IDirectSoundCaptureBuffer8Vtbl *lpVtbl;
291 LONG ref;
293 /* IDirectSoundCaptureBufferImpl fields */
294 DirectSoundCaptureDevice* device;
295 /* FIXME: don't need this */
296 LPDSCBUFFERDESC pdscbd;
297 DWORD flags;
299 /* IDirectSoundCaptureNotifyImpl fields */
300 IDirectSoundCaptureNotifyImpl* notify;
301 LPDSBPOSITIONNOTIFY notifies;
302 int nrofnotifies;
303 PIDSDRIVERNOTIFY hwnotify;
306 HRESULT IDirectSoundCaptureBufferImpl_Create(
307 DirectSoundCaptureDevice *device,
308 IDirectSoundCaptureBufferImpl ** ppobj,
309 LPCDSCBUFFERDESC lpcDSCBufferDesc);
311 /*****************************************************************************
312 * IDirectSoundFullDuplex implementation structure
314 struct IDirectSoundFullDuplexImpl
316 /* IUnknown fields */
317 const IDirectSoundFullDuplexVtbl *lpVtbl;
318 LONG ref;
320 /* IDirectSoundFullDuplexImpl fields */
321 DirectSoundDevice *renderer_device;
322 DirectSoundCaptureDevice *capture_device;
324 LPUNKNOWN pUnknown;
325 LPDIRECTSOUND pDS;
326 LPDIRECTSOUND8 pDS8;
327 LPDIRECTSOUNDCAPTURE pDSC;
330 /*****************************************************************************
331 * IDirectSoundFullDuplex COM components
333 struct IDirectSoundFullDuplex_IUnknown {
334 const IUnknownVtbl *lpVtbl;
335 LONG ref;
336 IDirectSoundFullDuplexImpl *pdsfd;
339 struct IDirectSoundFullDuplex_IDirectSound {
340 const IDirectSoundVtbl *lpVtbl;
341 LONG ref;
342 IDirectSoundFullDuplexImpl *pdsfd;
345 struct IDirectSoundFullDuplex_IDirectSound8 {
346 const IDirectSound8Vtbl *lpVtbl;
347 LONG ref;
348 IDirectSoundFullDuplexImpl *pdsfd;
351 struct IDirectSoundFullDuplex_IDirectSoundCapture {
352 const IDirectSoundCaptureVtbl *lpVtbl;
353 LONG ref;
354 IDirectSoundFullDuplexImpl *pdsfd;
357 /*****************************************************************************
358 * IDirectSound3DListener implementation structure
360 struct IDirectSound3DListenerImpl
362 /* IUnknown fields */
363 const IDirectSound3DListenerVtbl *lpVtbl;
364 LONG ref;
365 /* IDirectSound3DListenerImpl fields */
366 DirectSoundDevice* device;
369 HRESULT IDirectSound3DListenerImpl_Create(
370 DirectSoundDevice *device,
371 IDirectSound3DListenerImpl **pdsl);
373 /*****************************************************************************
374 * IKsBufferPropertySet implementation structure
376 struct IKsBufferPropertySetImpl
378 /* IUnknown fields */
379 const IKsPropertySetVtbl *lpVtbl;
380 LONG ref;
381 /* IKsPropertySetImpl fields */
382 IDirectSoundBufferImpl* dsb;
385 HRESULT IKsBufferPropertySetImpl_Create(
386 IDirectSoundBufferImpl *dsb,
387 IKsBufferPropertySetImpl **piks);
388 HRESULT IKsBufferPropertySetImpl_Destroy(
389 IKsBufferPropertySetImpl *piks);
391 /*****************************************************************************
392 * IKsPrivatePropertySet implementation structure
394 struct IKsPrivatePropertySetImpl
396 /* IUnknown fields */
397 const IKsPropertySetVtbl *lpVtbl;
398 LONG ref;
401 HRESULT IKsPrivatePropertySetImpl_Create(
402 REFIID riid,
403 IKsPrivatePropertySetImpl **piks);
405 /*****************************************************************************
406 * IDirectSound3DBuffer implementation structure
408 struct IDirectSound3DBufferImpl
410 /* IUnknown fields */
411 const IDirectSound3DBufferVtbl *lpVtbl;
412 LONG ref;
413 /* IDirectSound3DBufferImpl fields */
414 IDirectSoundBufferImpl* dsb;
417 HRESULT IDirectSound3DBufferImpl_Create(
418 IDirectSoundBufferImpl *dsb,
419 IDirectSound3DBufferImpl **pds3db);
420 HRESULT IDirectSound3DBufferImpl_Destroy(
421 IDirectSound3DBufferImpl *pds3db);
423 /*******************************************************************************
426 /* dsound.c */
428 HRESULT DSOUND_Create(REFIID riid, LPDIRECTSOUND *ppDS);
429 HRESULT DSOUND_Create8(REFIID riid, LPDIRECTSOUND8 *ppDS);
431 /* primary.c */
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);
442 /* duplex.c */
444 HRESULT DSOUND_FullDuplexCreate(REFIID riid, LPDIRECTSOUNDFULLDUPLEX* ppDSFD);
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);
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);
458 /* sound3d.c */
460 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb);
462 /* capture.c */
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);
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
484 #define DSOUND_FREQSHIFT (20)
486 extern DirectSoundDevice* DSOUND_renderer[MAXWAVEDRIVERS];
487 extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS];
489 extern DirectSoundCaptureDevice * DSOUND_capture[MAXWAVEDRIVERS];
490 extern GUID DSOUND_capture_guids[MAXWAVEDRIVERS];
492 HRESULT mmErr(UINT err);
493 void setup_dsound_options(void);
494 const char * dumpCooperativeLevel(DWORD level);