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
95 UINT timerID
, pwplay
, pwqueue
, prebuf
, helfrags
;
97 PIDSDRIVERBUFFER hwbuf
;
99 DWORD writelead
, buflen
, state
, playpos
, mixpos
;
101 IDirectSoundBufferImpl
** buffers
;
102 RTL_RWLOCK buffer_list_lock
;
103 CRITICAL_SECTION mixlock
;
104 PrimaryBufferImpl
* primary
;
106 DWORD speaker_config
;
107 LPBYTE tmp_buffer
, mix_buffer
;
108 DWORD tmp_buffer_len
, mix_buffer_len
;
111 normfunc normfunction
;
113 /* DirectSound3DListener fields */
114 IDirectSound3DListenerImpl
* listener
;
116 BOOL ds3dl_need_recalc
;
119 /* reference counted buffer memory for duplicated buffer memory */
120 typedef struct BufferMemory
127 ULONG
DirectSoundDevice_Release(DirectSoundDevice
* device
);
128 HRESULT
DirectSoundDevice_Initialize(
129 DirectSoundDevice
** ppDevice
,
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
,
144 HRESULT
DirectSoundDevice_DuplicateSoundBuffer(
145 DirectSoundDevice
* device
,
146 LPDIRECTSOUNDBUFFER psb
,
147 LPLPDIRECTSOUNDBUFFER ppdsb
);
148 HRESULT
DirectSoundDevice_SetCooperativeLevel(
149 DirectSoundDevice
* devcie
,
152 HRESULT
DirectSoundDevice_Compact(DirectSoundDevice
* device
);
153 HRESULT
DirectSoundDevice_GetSpeakerConfig(
154 DirectSoundDevice
* device
,
155 LPDWORD lpdwSpeakerConfig
);
156 HRESULT
DirectSoundDevice_SetSpeakerConfig(
157 DirectSoundDevice
* device
,
160 /*****************************************************************************
161 * IDirectSoundBuffer implementation structure
163 struct IDirectSoundBufferImpl
165 /* FIXME: document */
166 /* IUnknown fields */
167 const IDirectSoundBuffer8Vtbl
*lpVtbl
;
169 /* IDirectSoundBufferImpl fields */
170 SecondaryBufferImpl
* secondary
;
171 DirectSoundDevice
* device
;
173 PIDSDRIVERBUFFER hwbuf
;
175 BufferMemory
* buffer
;
177 DWORD playflags
,state
,leadin
;
178 DWORD writelead
,buflen
;
179 DWORD nAvgBytesPerSec
;
180 DWORD freq
, tmp_buffer_len
, max_buffer_len
;
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
;
192 PIDSDRIVERNOTIFY hwnotify
;
194 /* DirectSound3DBuffer fields */
195 IDirectSound3DBufferImpl
* ds3db
;
196 DS3DBUFFER ds3db_ds3db
;
198 BOOL ds3db_need_recalc
;
200 /* IKsPropertySet fields */
201 IKsBufferPropertySetImpl
* iks
;
202 bitsconvertfunc convert
;
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
;
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
;
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 */
255 /* DirectSound driver stuff */
257 DSDRIVERDESC drvdesc
;
258 DSCDRIVERCAPS drvcaps
;
259 PIDSCDRIVERBUFFER hwbuf
;
261 /* wave driver info */
270 IDirectSoundCaptureBufferImpl
* capture_buffer
;
275 CRITICAL_SECTION lock
;
278 HRESULT
DirectSoundCaptureDevice_Initialize(
279 DirectSoundCaptureDevice
** ppDevice
,
281 ULONG
DirectSoundCaptureDevice_Release(
282 DirectSoundCaptureDevice
* device
);
284 /*****************************************************************************
285 * IDirectSoundCaptureBuffer implementation structure
287 struct IDirectSoundCaptureBufferImpl
289 /* IUnknown fields */
290 const IDirectSoundCaptureBuffer8Vtbl
*lpVtbl
;
293 /* IDirectSoundCaptureBufferImpl fields */
294 DirectSoundCaptureDevice
* device
;
295 /* FIXME: don't need this */
296 LPDSCBUFFERDESC pdscbd
;
299 /* IDirectSoundCaptureNotifyImpl fields */
300 IDirectSoundCaptureNotifyImpl
* notify
;
301 LPDSBPOSITIONNOTIFY notifies
;
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
;
320 /* IDirectSoundFullDuplexImpl fields */
321 DirectSoundDevice
*renderer_device
;
322 DirectSoundCaptureDevice
*capture_device
;
327 LPDIRECTSOUNDCAPTURE pDSC
;
330 /*****************************************************************************
331 * IDirectSoundFullDuplex COM components
333 struct IDirectSoundFullDuplex_IUnknown
{
334 const IUnknownVtbl
*lpVtbl
;
336 IDirectSoundFullDuplexImpl
*pdsfd
;
339 struct IDirectSoundFullDuplex_IDirectSound
{
340 const IDirectSoundVtbl
*lpVtbl
;
342 IDirectSoundFullDuplexImpl
*pdsfd
;
345 struct IDirectSoundFullDuplex_IDirectSound8
{
346 const IDirectSound8Vtbl
*lpVtbl
;
348 IDirectSoundFullDuplexImpl
*pdsfd
;
351 struct IDirectSoundFullDuplex_IDirectSoundCapture
{
352 const IDirectSoundCaptureVtbl
*lpVtbl
;
354 IDirectSoundFullDuplexImpl
*pdsfd
;
357 /*****************************************************************************
358 * IDirectSound3DListener implementation structure
360 struct IDirectSound3DListenerImpl
362 /* IUnknown fields */
363 const IDirectSound3DListenerVtbl
*lpVtbl
;
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
;
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
;
401 HRESULT
IKsPrivatePropertySetImpl_Create(
403 IKsPrivatePropertySetImpl
**piks
);
405 /*****************************************************************************
406 * IDirectSound3DBuffer implementation structure
408 struct IDirectSound3DBufferImpl
410 /* IUnknown fields */
411 const IDirectSound3DBufferVtbl
*lpVtbl
;
413 /* IDirectSound3DBufferImpl fields */
414 IDirectSoundBufferImpl
* dsb
;
417 HRESULT
IDirectSound3DBufferImpl_Create(
418 IDirectSoundBufferImpl
*dsb
,
419 IDirectSound3DBufferImpl
**pds3db
);
420 HRESULT
IDirectSound3DBufferImpl_Destroy(
421 IDirectSound3DBufferImpl
*pds3db
);
423 /*******************************************************************************
428 HRESULT
DSOUND_Create(REFIID riid
, LPDIRECTSOUND
*ppDS
);
429 HRESULT
DSOUND_Create8(REFIID riid
, LPDIRECTSOUND8
*ppDS
);
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
);
444 HRESULT
DSOUND_FullDuplexCreate(REFIID riid
, LPDIRECTSOUNDFULLDUPLEX
* ppDSFD
);
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
);
460 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl
*dsb
);
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
,
471 HRESULT WINAPI
IDirectSoundCaptureImpl_GetCaps(
472 LPDIRECTSOUNDCAPTURE iface
,
473 LPDSCCAPS lpDSCCaps
);
474 HRESULT WINAPI
IDirectSoundCaptureImpl_Initialize(
475 LPDIRECTSOUNDCAPTURE iface
,
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
);