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 #define DS_HEL_BUFLEN 0x8000 /* HEL: The buffer length of the emulated buffer */
27 #define DS_HEL_FRAGS 0x10 /* HEL only: number of waveOut fragments in primary buffer
28 * (changing this won't help you) */
30 /* direct sound hardware acceleration levels */
31 #define DS_HW_ACCEL_FULL 0 /* default on Windows 98 */
32 #define DS_HW_ACCEL_STANDARD 1 /* default on Windows 2000 */
33 #define DS_HW_ACCEL_BASIC 2
34 #define DS_HW_ACCEL_EMULATION 3
36 extern int ds_emuldriver
;
37 extern int ds_hel_margin
;
38 extern int ds_hel_queue
;
39 extern int ds_snd_queue_max
;
40 extern int ds_hw_accel
;
41 extern int ds_default_playback
;
42 extern int ds_default_capture
;
43 extern int ds_default_sample_rate
;
44 extern int ds_default_bits_per_sample
;
46 /*****************************************************************************
47 * Predeclare the interface implementation structures
49 typedef struct IDirectSoundImpl IDirectSoundImpl
;
50 typedef struct IDirectSound_IUnknown IDirectSound_IUnknown
;
51 typedef struct IDirectSound_IDirectSound IDirectSound_IDirectSound
;
52 typedef struct IDirectSound8_IUnknown IDirectSound8_IUnknown
;
53 typedef struct IDirectSound8_IDirectSound IDirectSound8_IDirectSound
;
54 typedef struct IDirectSound8_IDirectSound8 IDirectSound8_IDirectSound8
;
55 typedef struct IDirectSoundBufferImpl IDirectSoundBufferImpl
;
56 typedef struct IDirectSoundCaptureImpl IDirectSoundCaptureImpl
;
57 typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl
;
58 typedef struct IDirectSoundFullDuplexImpl IDirectSoundFullDuplexImpl
;
59 typedef struct IDirectSoundFullDuplex_IUnknown IDirectSoundFullDuplex_IUnknown
;
60 typedef struct IDirectSoundFullDuplex_IDirectSound IDirectSoundFullDuplex_IDirectSound
;
61 typedef struct IDirectSoundFullDuplex_IDirectSound8 IDirectSoundFullDuplex_IDirectSound8
;
62 typedef struct IDirectSoundFullDuplex_IDirectSoundCapture IDirectSoundFullDuplex_IDirectSoundCapture
;
63 typedef struct IDirectSoundNotifyImpl IDirectSoundNotifyImpl
;
64 typedef struct IDirectSoundCaptureNotifyImpl IDirectSoundCaptureNotifyImpl
;
65 typedef struct IDirectSound3DListenerImpl IDirectSound3DListenerImpl
;
66 typedef struct IDirectSound3DBufferImpl IDirectSound3DBufferImpl
;
67 typedef struct IKsBufferPropertySetImpl IKsBufferPropertySetImpl
;
68 typedef struct IKsPrivatePropertySetImpl IKsPrivatePropertySetImpl
;
69 typedef struct PrimaryBufferImpl PrimaryBufferImpl
;
70 typedef struct SecondaryBufferImpl SecondaryBufferImpl
;
71 typedef struct DirectSoundDevice DirectSoundDevice
;
72 typedef struct DirectSoundCaptureDevice DirectSoundCaptureDevice
;
74 /*****************************************************************************
75 * IDirectSoundDevice implementation structure
77 struct DirectSoundDevice
88 LPWAVEHDR pwave
[DS_HEL_FRAGS
];
89 UINT timerID
, pwplay
, pwwrite
, pwqueue
, prebuf
, precount
;
91 PIDSDRIVERBUFFER hwbuf
;
93 DWORD writelead
, buflen
, state
, playpos
, mixpos
;
95 IDirectSoundBufferImpl
** buffers
;
96 RTL_RWLOCK buffer_list_lock
;
97 CRITICAL_SECTION mixlock
;
98 PrimaryBufferImpl
* primary
;
100 DWORD speaker_config
;
102 DWORD tmp_buffer_len
;
104 /* DirectSound3DListener fields */
105 IDirectSound3DListenerImpl
* listener
;
107 BOOL ds3dl_need_recalc
;
110 /* reference counted buffer memory for duplicated buffer memory */
111 typedef struct BufferMemory
117 ULONG
DirectSoundDevice_Release(DirectSoundDevice
* device
);
118 HRESULT
DirectSoundDevice_Initialize(
119 DirectSoundDevice
** ppDevice
,
121 HRESULT
DirectSoundDevice_AddBuffer(
122 DirectSoundDevice
* device
,
123 IDirectSoundBufferImpl
* pDSB
);
124 HRESULT
DirectSoundDevice_RemoveBuffer(
125 DirectSoundDevice
* device
,
126 IDirectSoundBufferImpl
* pDSB
);
127 HRESULT
DirectSoundDevice_GetCaps(DirectSoundDevice
* device
, LPDSCAPS lpDSCaps
);
128 HRESULT
DirectSoundDevice_CreateSoundBuffer(
129 DirectSoundDevice
* device
,
130 LPCDSBUFFERDESC dsbd
,
131 LPLPDIRECTSOUNDBUFFER ppdsb
,
134 HRESULT
DirectSoundDevice_DuplicateSoundBuffer(
135 DirectSoundDevice
* device
,
136 LPDIRECTSOUNDBUFFER psb
,
137 LPLPDIRECTSOUNDBUFFER ppdsb
);
138 HRESULT
DirectSoundDevice_SetCooperativeLevel(
139 DirectSoundDevice
* devcie
,
142 HRESULT
DirectSoundDevice_Compact(DirectSoundDevice
* device
);
143 HRESULT
DirectSoundDevice_GetSpeakerConfig(
144 DirectSoundDevice
* device
,
145 LPDWORD lpdwSpeakerConfig
);
146 HRESULT
DirectSoundDevice_SetSpeakerConfig(
147 DirectSoundDevice
* device
,
150 /*****************************************************************************
151 * IDirectSoundBuffer implementation structure
153 struct IDirectSoundBufferImpl
155 /* FIXME: document */
156 /* IUnknown fields */
157 const IDirectSoundBuffer8Vtbl
*lpVtbl
;
159 /* IDirectSoundBufferImpl fields */
160 SecondaryBufferImpl
* secondary
;
161 DirectSoundDevice
* device
;
162 CRITICAL_SECTION lock
;
163 PIDSDRIVERBUFFER hwbuf
;
165 BufferMemory
* buffer
;
166 DWORD playflags
,state
,leadin
;
167 DWORD playpos
,startpos
,writelead
,buflen
;
168 DWORD nAvgBytesPerSec
;
172 /* used for frequency conversion (PerfectPitch) */
173 ULONG freqAdjust
, freqAcc
;
174 /* used for intelligent (well, sort of) prebuffering */
175 DWORD primary_mixpos
, buf_mixpos
, last_playpos
, remix_pos
;
177 /* IDirectSoundNotifyImpl fields */
178 IDirectSoundNotifyImpl
* notify
;
179 LPDSBPOSITIONNOTIFY notifies
;
181 PIDSDRIVERNOTIFY hwnotify
;
183 /* DirectSound3DBuffer fields */
184 IDirectSound3DBufferImpl
* ds3db
;
185 DS3DBUFFER ds3db_ds3db
;
187 BOOL ds3db_need_recalc
;
189 /* IKsPropertySet fields */
190 IKsBufferPropertySetImpl
* iks
;
193 HRESULT
IDirectSoundBufferImpl_Create(
194 DirectSoundDevice
*device
,
195 IDirectSoundBufferImpl
**ppdsb
,
196 LPCDSBUFFERDESC dsbd
);
197 HRESULT
IDirectSoundBufferImpl_Destroy(
198 IDirectSoundBufferImpl
*pdsb
);
199 HRESULT
IDirectSoundBufferImpl_Duplicate(
200 DirectSoundDevice
*device
,
201 IDirectSoundBufferImpl
**ppdsb
,
202 IDirectSoundBufferImpl
*pdsb
);
204 /*****************************************************************************
205 * SecondaryBuffer implementation structure
207 struct SecondaryBufferImpl
209 const IDirectSoundBuffer8Vtbl
*lpVtbl
;
211 IDirectSoundBufferImpl
* dsb
;
214 HRESULT
SecondaryBufferImpl_Create(
215 IDirectSoundBufferImpl
*dsb
,
216 SecondaryBufferImpl
**pdsb
);
218 /*****************************************************************************
219 * PrimaryBuffer implementation structure
221 struct PrimaryBufferImpl
223 const IDirectSoundBufferVtbl
*lpVtbl
;
225 DirectSoundDevice
* device
;
228 HRESULT
PrimaryBufferImpl_Create(
229 DirectSoundDevice
* device
,
230 PrimaryBufferImpl
**ppdsb
,
231 LPCDSBUFFERDESC dsbd
);
233 /*****************************************************************************
234 * DirectSoundCaptureDevice implementation structure
236 struct DirectSoundCaptureDevice
238 /* IDirectSoundCaptureImpl fields */
242 /* DirectSound driver stuff */
244 DSDRIVERDESC drvdesc
;
245 DSCDRIVERCAPS drvcaps
;
246 PIDSCDRIVERBUFFER hwbuf
;
248 /* wave driver info */
258 IDirectSoundCaptureBufferImpl
* capture_buffer
;
263 CRITICAL_SECTION lock
;
266 HRESULT
DirectSoundCaptureDevice_Initialize(
267 DirectSoundCaptureDevice
** ppDevice
,
269 ULONG
DirectSoundCaptureDevice_Release(
270 DirectSoundCaptureDevice
* device
);
272 /*****************************************************************************
273 * IDirectSoundCaptureBuffer implementation structure
275 struct IDirectSoundCaptureBufferImpl
277 /* IUnknown fields */
278 const IDirectSoundCaptureBuffer8Vtbl
*lpVtbl
;
281 /* IDirectSoundCaptureBufferImpl fields */
282 DirectSoundCaptureDevice
* device
;
283 /* FIXME: don't need this */
284 LPDSCBUFFERDESC pdscbd
;
287 /* IDirectSoundCaptureNotifyImpl fields */
288 IDirectSoundCaptureNotifyImpl
* notify
;
289 LPDSBPOSITIONNOTIFY notifies
;
291 PIDSDRIVERNOTIFY hwnotify
;
294 HRESULT
IDirectSoundCaptureBufferImpl_Create(
295 DirectSoundCaptureDevice
*device
,
296 IDirectSoundCaptureBufferImpl
** ppobj
,
297 LPCDSCBUFFERDESC lpcDSCBufferDesc
);
299 /*****************************************************************************
300 * IDirectSoundFullDuplex implementation structure
302 struct IDirectSoundFullDuplexImpl
304 /* IUnknown fields */
305 const IDirectSoundFullDuplexVtbl
*lpVtbl
;
308 /* IDirectSoundFullDuplexImpl fields */
309 DirectSoundDevice
*renderer_device
;
310 DirectSoundCaptureDevice
*capture_device
;
315 LPDIRECTSOUNDCAPTURE pDSC
;
318 /*****************************************************************************
319 * IDirectSoundFullDuplex COM components
321 struct IDirectSoundFullDuplex_IUnknown
{
322 const IUnknownVtbl
*lpVtbl
;
324 IDirectSoundFullDuplexImpl
*pdsfd
;
327 struct IDirectSoundFullDuplex_IDirectSound
{
328 const IDirectSoundVtbl
*lpVtbl
;
330 IDirectSoundFullDuplexImpl
*pdsfd
;
333 struct IDirectSoundFullDuplex_IDirectSound8
{
334 const IDirectSound8Vtbl
*lpVtbl
;
336 IDirectSoundFullDuplexImpl
*pdsfd
;
339 struct IDirectSoundFullDuplex_IDirectSoundCapture
{
340 const IDirectSoundCaptureVtbl
*lpVtbl
;
342 IDirectSoundFullDuplexImpl
*pdsfd
;
345 /*****************************************************************************
346 * IDirectSound3DListener implementation structure
348 struct IDirectSound3DListenerImpl
350 /* IUnknown fields */
351 const IDirectSound3DListenerVtbl
*lpVtbl
;
353 /* IDirectSound3DListenerImpl fields */
354 DirectSoundDevice
* device
;
357 HRESULT
IDirectSound3DListenerImpl_Create(
358 DirectSoundDevice
*device
,
359 IDirectSound3DListenerImpl
**pdsl
);
361 /*****************************************************************************
362 * IKsBufferPropertySet implementation structure
364 struct IKsBufferPropertySetImpl
366 /* IUnknown fields */
367 const IKsPropertySetVtbl
*lpVtbl
;
369 /* IKsPropertySetImpl fields */
370 IDirectSoundBufferImpl
* dsb
;
373 HRESULT
IKsBufferPropertySetImpl_Create(
374 IDirectSoundBufferImpl
*dsb
,
375 IKsBufferPropertySetImpl
**piks
);
376 HRESULT
IKsBufferPropertySetImpl_Destroy(
377 IKsBufferPropertySetImpl
*piks
);
379 /*****************************************************************************
380 * IKsPrivatePropertySet implementation structure
382 struct IKsPrivatePropertySetImpl
384 /* IUnknown fields */
385 const IKsPropertySetVtbl
*lpVtbl
;
389 HRESULT
IKsPrivatePropertySetImpl_Create(
391 IKsPrivatePropertySetImpl
**piks
);
393 /*****************************************************************************
394 * IDirectSound3DBuffer implementation structure
396 struct IDirectSound3DBufferImpl
398 /* IUnknown fields */
399 const IDirectSound3DBufferVtbl
*lpVtbl
;
401 /* IDirectSound3DBufferImpl fields */
402 IDirectSoundBufferImpl
* dsb
;
405 HRESULT
IDirectSound3DBufferImpl_Create(
406 IDirectSoundBufferImpl
*dsb
,
407 IDirectSound3DBufferImpl
**pds3db
);
408 HRESULT
IDirectSound3DBufferImpl_Destroy(
409 IDirectSound3DBufferImpl
*pds3db
);
411 /*******************************************************************************
416 HRESULT
DSOUND_Create(REFIID riid
, LPDIRECTSOUND
*ppDS
);
417 HRESULT
DSOUND_Create8(REFIID riid
, LPDIRECTSOUND8
*ppDS
);
421 HRESULT
DSOUND_PrimaryCreate(DirectSoundDevice
*device
);
422 HRESULT
DSOUND_PrimaryDestroy(DirectSoundDevice
*device
);
423 HRESULT
DSOUND_PrimaryPlay(DirectSoundDevice
*device
);
424 HRESULT
DSOUND_PrimaryStop(DirectSoundDevice
*device
);
425 HRESULT
DSOUND_PrimaryGetPosition(DirectSoundDevice
*device
, LPDWORD playpos
, LPDWORD writepos
);
426 HRESULT
DSOUND_PrimarySetFormat(DirectSoundDevice
*device
, LPCWAVEFORMATEX wfex
);
430 HRESULT
DSOUND_FullDuplexCreate(REFIID riid
, LPDIRECTSOUNDFULLDUPLEX
* ppDSFD
);
434 DWORD
DSOUND_CalcPlayPosition(IDirectSoundBufferImpl
*This
, DWORD pplay
, DWORD pwrite
);
438 void DSOUND_CheckEvent(IDirectSoundBufferImpl
*dsb
, int len
);
439 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan
);
440 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan
);
441 void DSOUND_RecalcFormat(IDirectSoundBufferImpl
*dsb
);
442 void CALLBACK
DSOUND_timer(UINT timerID
, UINT msg
, DWORD_PTR dwUser
, DWORD_PTR dw1
, DWORD_PTR dw2
);
443 void CALLBACK
DSOUND_callback(HWAVEOUT hwo
, UINT msg
, DWORD dwUser
, DWORD dw1
, DWORD dw2
);
447 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl
*dsb
);
451 HRESULT
DSOUND_CaptureCreate(REFIID riid
, LPDIRECTSOUNDCAPTURE
*ppDSC
);
452 HRESULT
DSOUND_CaptureCreate8(REFIID riid
, LPDIRECTSOUNDCAPTURE8
*ppDSC8
);
453 HRESULT WINAPI
IDirectSoundCaptureImpl_CreateCaptureBuffer(
454 LPDIRECTSOUNDCAPTURE iface
,
455 LPCDSCBUFFERDESC lpcDSCBufferDesc
,
456 LPDIRECTSOUNDCAPTUREBUFFER
* lplpDSCaptureBuffer
,
458 HRESULT WINAPI
IDirectSoundCaptureImpl_GetCaps(
459 LPDIRECTSOUNDCAPTURE iface
,
460 LPDSCCAPS lpDSCCaps
);
461 HRESULT WINAPI
IDirectSoundCaptureImpl_Initialize(
462 LPDIRECTSOUNDCAPTURE iface
,
465 #define STATE_STOPPED 0
466 #define STATE_STARTING 1
467 #define STATE_PLAYING 2
468 #define STATE_CAPTURING 2
469 #define STATE_STOPPING 3
471 #define DSOUND_FREQSHIFT (14)
473 extern DirectSoundDevice
* DSOUND_renderer
[MAXWAVEDRIVERS
];
474 extern GUID DSOUND_renderer_guids
[MAXWAVEDRIVERS
];
476 extern DirectSoundCaptureDevice
* DSOUND_capture
[MAXWAVEDRIVERS
];
477 extern GUID DSOUND_capture_guids
[MAXWAVEDRIVERS
];
479 HRESULT
mmErr(UINT err
);
480 void setup_dsound_options(void);
481 const char * dumpCooperativeLevel(DWORD level
);