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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 /* Linux does not support better timing than 10ms */
23 #define DS_TIME_RES 10 /* Resolution of multimedia timer */
24 #define DS_TIME_DEL 10 /* Delay of multimedia timer callback, and duration of HEL fragment */
26 #define DS_HEL_FRAGS 48 /* HEL only: number of waveOut fragments in primary buffer
27 * (changing this won't help you) */
29 /* direct sound hardware acceleration levels */
30 #define DS_HW_ACCEL_FULL 0 /* default on Windows 98 */
31 #define DS_HW_ACCEL_STANDARD 1 /* default on Windows 2000 */
32 #define DS_HW_ACCEL_BASIC 2
33 #define DS_HW_ACCEL_EMULATION 3
35 extern int ds_emuldriver
;
36 extern int ds_hel_margin
;
37 extern int ds_hel_queue
;
38 extern int ds_snd_queue_max
;
39 extern int ds_snd_queue_min
;
40 extern int ds_hw_accel
;
41 extern int ds_default_playback
;
42 extern int ds_default_capture
;
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 IDirectSoundNotifyImpl IDirectSoundNotifyImpl
;
58 typedef struct IDirectSoundCaptureNotifyImpl IDirectSoundCaptureNotifyImpl
;
59 typedef struct IDirectSound3DListenerImpl IDirectSound3DListenerImpl
;
60 typedef struct IDirectSound3DBufferImpl IDirectSound3DBufferImpl
;
61 typedef struct IKsBufferPropertySetImpl IKsBufferPropertySetImpl
;
62 typedef struct IKsPrivatePropertySetImpl IKsPrivatePropertySetImpl
;
63 typedef struct PrimaryBufferImpl PrimaryBufferImpl
;
64 typedef struct SecondaryBufferImpl SecondaryBufferImpl
;
65 typedef struct IClassFactoryImpl IClassFactoryImpl
;
67 /*****************************************************************************
68 * IDirectSound implementation structure
70 struct IDirectSoundImpl
73 IDirectSound8Vtbl
*lpVtbl
;
75 /* IDirectSoundImpl fields */
83 LPWAVEHDR pwave
[DS_HEL_FRAGS
];
84 UINT timerID
, pwplay
, pwwrite
, pwqueue
, prebuf
, precount
;
86 PIDSDRIVERBUFFER hwbuf
;
88 DWORD writelead
, buflen
, state
, playpos
, mixpos
;
91 IDirectSoundBufferImpl
** buffers
;
93 CRITICAL_SECTION mixlock
;
94 PrimaryBufferImpl
* primary
;
99 /* DirectSound3DListener fields */
100 IDirectSound3DListenerImpl
* listener
;
102 BOOL ds3dl_need_recalc
;
109 /* reference counted buffer memory for duplicated buffer memory */
110 typedef struct BufferMemory
116 HRESULT WINAPI
IDirectSoundImpl_Create(
118 LPDIRECTSOUND8
* ppds
);
120 HRESULT WINAPI
DSOUND_Create(
123 IUnknown
*pUnkOuter
);
125 HRESULT WINAPI
DSOUND_Create8(
127 LPDIRECTSOUND8
*ppDS
,
128 IUnknown
*pUnkOuter
);
130 /*****************************************************************************
131 * IDirectSound COM components
133 struct IDirectSound_IUnknown
{
134 IUnknownVtbl
*lpVtbl
;
139 HRESULT WINAPI
IDirectSound_IUnknown_Create(
143 struct IDirectSound_IDirectSound
{
144 IDirectSoundVtbl
*lpVtbl
;
149 HRESULT WINAPI
IDirectSound_IDirectSound_Create(
151 LPDIRECTSOUND
* ppds
);
153 /*****************************************************************************
154 * IDirectSound8 COM components
156 struct IDirectSound8_IUnknown
{
157 IUnknownVtbl
*lpVtbl
;
162 HRESULT WINAPI
IDirectSound8_IUnknown_Create(
166 struct IDirectSound8_IDirectSound
{
167 IDirectSoundVtbl
*lpVtbl
;
172 HRESULT WINAPI
IDirectSound8_IDirectSound_Create(
174 LPDIRECTSOUND
* ppds
);
176 struct IDirectSound8_IDirectSound8
{
177 IDirectSound8Vtbl
*lpVtbl
;
182 HRESULT WINAPI
IDirectSound8_IDirectSound8_Create(
184 LPDIRECTSOUND8
* ppds
);
186 /*****************************************************************************
187 * IDirectSoundBuffer implementation structure
189 struct IDirectSoundBufferImpl
191 /* FIXME: document */
192 /* IUnknown fields */
193 IDirectSoundBuffer8Vtbl
*lpVtbl
;
195 /* IDirectSoundBufferImpl fields */
196 SecondaryBufferImpl
* dsb
;
197 IDirectSoundImpl
* dsound
;
198 CRITICAL_SECTION lock
;
199 PIDSDRIVERBUFFER hwbuf
;
201 BufferMemory
* buffer
;
202 DWORD playflags
,state
,leadin
;
203 DWORD playpos
,startpos
,writelead
,buflen
;
204 DWORD nAvgBytesPerSec
;
206 DSVOLUMEPAN volpan
, cvolpan
;
208 /* used for frequency conversion (PerfectPitch) */
209 ULONG freqAdjust
, freqAcc
;
210 /* used for intelligent (well, sort of) prebuffering */
211 DWORD probably_valid_to
, last_playpos
;
212 DWORD primary_mixpos
, buf_mixpos
;
215 /* IDirectSoundNotifyImpl fields */
216 IDirectSoundNotifyImpl
* notify
;
217 LPDSBPOSITIONNOTIFY notifies
;
219 PIDSDRIVERNOTIFY hwnotify
;
221 /* DirectSound3DBuffer fields */
222 IDirectSound3DBufferImpl
* ds3db
;
223 DS3DBUFFER ds3db_ds3db
;
225 BOOL ds3db_need_recalc
;
227 /* IKsPropertySet fields */
228 IKsBufferPropertySetImpl
* iks
;
231 HRESULT WINAPI
IDirectSoundBufferImpl_Create(
232 IDirectSoundImpl
*ds
,
233 IDirectSoundBufferImpl
**pdsb
,
234 LPCDSBUFFERDESC dsbd
);
235 HRESULT WINAPI
IDirectSoundBufferImpl_Destroy(
236 IDirectSoundBufferImpl
*pdsb
);
238 /*****************************************************************************
239 * SecondaryBuffer implementation structure
241 struct SecondaryBufferImpl
243 IDirectSoundBuffer8Vtbl
*lpVtbl
;
245 IDirectSoundBufferImpl
* dsb
;
248 HRESULT WINAPI
SecondaryBufferImpl_Create(
249 IDirectSoundBufferImpl
*dsb
,
250 SecondaryBufferImpl
**pdsb
);
251 HRESULT WINAPI
SecondaryBufferImpl_Destroy(
252 SecondaryBufferImpl
*pdsb
);
254 /*****************************************************************************
255 * PrimaryBuffer implementation structure
257 struct PrimaryBufferImpl
259 IDirectSoundBuffer8Vtbl
*lpVtbl
;
261 IDirectSoundImpl
* dsound
;
264 HRESULT WINAPI
PrimaryBufferImpl_Create(
265 IDirectSoundImpl
*ds
,
266 PrimaryBufferImpl
**pdsb
,
267 LPCDSBUFFERDESC dsbd
);
269 /*****************************************************************************
270 * IDirectSoundCapture implementation structure
272 struct IDirectSoundCaptureImpl
274 /* IUnknown fields */
275 IDirectSoundCaptureVtbl
*lpVtbl
;
278 /* IDirectSoundCaptureImpl fields */
282 /* DirectSound driver stuff */
284 DSDRIVERDESC drvdesc
;
285 DSCDRIVERCAPS drvcaps
;
286 PIDSCDRIVERBUFFER hwbuf
;
288 /* wave driver info */
298 IDirectSoundCaptureBufferImpl
* capture_buffer
;
303 CRITICAL_SECTION lock
;
306 /*****************************************************************************
307 * IDirectSoundCaptureBuffer implementation structure
309 struct IDirectSoundCaptureBufferImpl
311 /* IUnknown fields */
312 IDirectSoundCaptureBuffer8Vtbl
*lpVtbl
;
315 /* IDirectSoundCaptureBufferImpl fields */
316 IDirectSoundCaptureImpl
* dsound
;
317 /* FIXME: don't need this */
318 LPDSCBUFFERDESC pdscbd
;
321 /* IDirectSoundCaptureNotifyImpl fields */
322 IDirectSoundCaptureNotifyImpl
* notify
;
323 LPDSBPOSITIONNOTIFY notifies
;
325 PIDSDRIVERNOTIFY hwnotify
;
328 /*****************************************************************************
329 * IDirectSoundFullDuplex implementation structure
331 struct IDirectSoundFullDuplexImpl
333 /* IUnknown fields */
334 IDirectSoundFullDuplexVtbl
*lpVtbl
;
337 /* IDirectSoundFullDuplexImpl fields */
338 CRITICAL_SECTION lock
;
341 /*****************************************************************************
342 * IDirectSoundNotify implementation structure
344 struct IDirectSoundNotifyImpl
346 /* IUnknown fields */
347 IDirectSoundNotifyVtbl
*lpVtbl
;
349 IDirectSoundBufferImpl
* dsb
;
352 HRESULT WINAPI
IDirectSoundNotifyImpl_Create(
353 IDirectSoundBufferImpl
*dsb
,
354 IDirectSoundNotifyImpl
**pdsn
);
355 HRESULT WINAPI
IDirectSoundNotifyImpl_Destroy(
356 IDirectSoundNotifyImpl
*pdsn
);
358 /*****************************************************************************
359 * IDirectSoundCaptureNotify implementation structure
361 struct IDirectSoundCaptureNotifyImpl
363 /* IUnknown fields */
364 IDirectSoundNotifyVtbl
*lpVtbl
;
366 IDirectSoundCaptureBufferImpl
* dscb
;
369 HRESULT WINAPI
IDirectSoundCaptureNotifyImpl_Create(
370 IDirectSoundCaptureBufferImpl
*dscb
,
371 IDirectSoundCaptureNotifyImpl
** pdscn
);
373 /*****************************************************************************
374 * IDirectSound3DListener implementation structure
376 struct IDirectSound3DListenerImpl
378 /* IUnknown fields */
379 IDirectSound3DListenerVtbl
*lpVtbl
;
381 /* IDirectSound3DListenerImpl fields */
382 IDirectSoundImpl
* dsound
;
385 HRESULT WINAPI
IDirectSound3DListenerImpl_Create(
386 PrimaryBufferImpl
*pb
,
387 IDirectSound3DListenerImpl
**pdsl
);
389 /*****************************************************************************
390 * IKsBufferPropertySet implementation structure
392 struct IKsBufferPropertySetImpl
394 /* IUnknown fields */
395 IKsPropertySetVtbl
*lpVtbl
;
397 /* IKsPropertySetImpl fields */
398 IDirectSoundBufferImpl
* dsb
;
401 HRESULT WINAPI
IKsBufferPropertySetImpl_Create(
402 IDirectSoundBufferImpl
*dsb
,
403 IKsBufferPropertySetImpl
**piks
);
404 HRESULT WINAPI
IKsBufferPropertySetImpl_Destroy(
405 IKsBufferPropertySetImpl
*piks
);
407 /*****************************************************************************
408 * IKsPrivatePropertySet implementation structure
410 struct IKsPrivatePropertySetImpl
412 /* IUnknown fields */
413 IKsPropertySetVtbl
*lpVtbl
;
417 HRESULT WINAPI
IKsPrivatePropertySetImpl_Create(
418 IKsPrivatePropertySetImpl
**piks
);
420 /*****************************************************************************
421 * IDirectSound3DBuffer implementation structure
423 struct IDirectSound3DBufferImpl
425 /* IUnknown fields */
426 IDirectSound3DBufferVtbl
*lpVtbl
;
428 /* IDirectSound3DBufferImpl fields */
429 IDirectSoundBufferImpl
* dsb
;
432 HRESULT WINAPI
IDirectSound3DBufferImpl_Create(
433 IDirectSoundBufferImpl
*dsb
,
434 IDirectSound3DBufferImpl
**pds3db
);
435 HRESULT WINAPI
IDirectSound3DBufferImpl_Destroy(
436 IDirectSound3DBufferImpl
*pds3db
);
438 /*******************************************************************************
439 * DirectSound ClassFactory implementation structure
441 struct IClassFactoryImpl
443 /* IUnknown fields */
444 IClassFactoryVtbl
*lpVtbl
;
448 extern IClassFactoryImpl DSOUND_CAPTURE_CF
;
449 extern IClassFactoryImpl DSOUND_FULLDUPLEX_CF
;
451 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan
);
452 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan
);
453 void DSOUND_RecalcFormat(IDirectSoundBufferImpl
*dsb
);
457 HRESULT
DSOUND_PrimaryCreate(IDirectSoundImpl
*This
);
458 HRESULT
DSOUND_PrimaryDestroy(IDirectSoundImpl
*This
);
459 HRESULT
DSOUND_PrimaryPlay(IDirectSoundImpl
*This
);
460 HRESULT
DSOUND_PrimaryStop(IDirectSoundImpl
*This
);
461 HRESULT
DSOUND_PrimaryGetPosition(IDirectSoundImpl
*This
, LPDWORD playpos
, LPDWORD writepos
);
465 DWORD
DSOUND_CalcPlayPosition(IDirectSoundBufferImpl
*This
,
466 DWORD state
, DWORD pplay
, DWORD pwrite
, DWORD pmix
, DWORD bmix
);
470 void DSOUND_CheckEvent(IDirectSoundBufferImpl
*dsb
, int len
);
471 void DSOUND_ForceRemix(IDirectSoundBufferImpl
*dsb
);
472 void DSOUND_MixCancelAt(IDirectSoundBufferImpl
*dsb
, DWORD buf_writepos
);
473 void DSOUND_WaveQueue(IDirectSoundImpl
*dsound
, DWORD mixq
);
474 void DSOUND_PerformMix(IDirectSoundImpl
*dsound
);
475 void CALLBACK
DSOUND_timer(UINT timerID
, UINT msg
, DWORD dwUser
, DWORD dw1
, DWORD dw2
);
476 void CALLBACK
DSOUND_callback(HWAVEOUT hwo
, UINT msg
, DWORD dwUser
, DWORD dw1
, DWORD dw2
);
480 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl
*dsb
);
482 #define STATE_STOPPED 0
483 #define STATE_STARTING 1
484 #define STATE_PLAYING 2
485 #define STATE_CAPTURING 2
486 #define STATE_STOPPING 3
488 #define DSOUND_FREQSHIFT (14)
490 extern IDirectSoundImpl
* dsound
;
492 extern GUID renderer_guids
[MAXWAVEDRIVERS
];
493 extern GUID capture_guids
[MAXWAVEDRIVERS
];
495 extern HRESULT
mmErr(UINT err
);
496 extern void setup_dsound_options(void);
497 extern const char * get_device_id(LPCGUID pGuid
);