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;
92 RTL_RWLOCK buffer_list_lock;
93 CRITICAL_SECTION mixlock;
94 PrimaryBufferImpl* primary;
101 /* DirectSound3DListener fields */
102 IDirectSound3DListenerImpl* listener;
104 BOOL ds3dl_need_recalc;
111 /* reference counted buffer memory for duplicated buffer memory */
112 typedef struct BufferMemory
118 HRESULT WINAPI IDirectSoundImpl_Create(
120 LPDIRECTSOUND8 * ppds);
122 HRESULT WINAPI DSOUND_Create(
125 IUnknown *pUnkOuter);
127 HRESULT WINAPI DSOUND_Create8(
129 LPDIRECTSOUND8 *ppDS,
130 IUnknown *pUnkOuter);
132 /*****************************************************************************
133 * IDirectSound COM components
135 struct IDirectSound_IUnknown {
136 IUnknownVtbl *lpVtbl;
141 HRESULT WINAPI IDirectSound_IUnknown_Create(
145 struct IDirectSound_IDirectSound {
146 IDirectSoundVtbl *lpVtbl;
151 HRESULT WINAPI IDirectSound_IDirectSound_Create(
153 LPDIRECTSOUND * ppds);
155 /*****************************************************************************
156 * IDirectSound8 COM components
158 struct IDirectSound8_IUnknown {
159 IUnknownVtbl *lpVtbl;
164 HRESULT WINAPI IDirectSound8_IUnknown_Create(
168 struct IDirectSound8_IDirectSound {
169 IDirectSoundVtbl *lpVtbl;
174 HRESULT WINAPI IDirectSound8_IDirectSound_Create(
176 LPDIRECTSOUND * ppds);
178 struct IDirectSound8_IDirectSound8 {
179 IDirectSound8Vtbl *lpVtbl;
184 HRESULT WINAPI IDirectSound8_IDirectSound8_Create(
186 LPDIRECTSOUND8 * ppds);
188 /*****************************************************************************
189 * IDirectSoundBuffer implementation structure
191 struct IDirectSoundBufferImpl
193 /* FIXME: document */
194 /* IUnknown fields */
195 IDirectSoundBuffer8Vtbl *lpVtbl;
197 /* IDirectSoundBufferImpl fields */
198 SecondaryBufferImpl* dsb;
199 IDirectSoundImpl* dsound;
200 CRITICAL_SECTION lock;
201 PIDSDRIVERBUFFER hwbuf;
203 BufferMemory* buffer;
204 DWORD playflags,state,leadin;
205 DWORD playpos,startpos,writelead,buflen;
206 DWORD nAvgBytesPerSec;
208 DSVOLUMEPAN volpan, cvolpan;
210 /* used for frequency conversion (PerfectPitch) */
211 ULONG freqAdjust, freqAcc;
212 /* used for intelligent (well, sort of) prebuffering */
213 DWORD probably_valid_to, last_playpos;
214 DWORD primary_mixpos, buf_mixpos;
217 /* IDirectSoundNotifyImpl fields */
218 IDirectSoundNotifyImpl* notify;
219 LPDSBPOSITIONNOTIFY notifies;
221 PIDSDRIVERNOTIFY hwnotify;
223 /* DirectSound3DBuffer fields */
224 IDirectSound3DBufferImpl* ds3db;
225 DS3DBUFFER ds3db_ds3db;
227 BOOL ds3db_need_recalc;
229 /* IKsPropertySet fields */
230 IKsBufferPropertySetImpl* iks;
233 HRESULT WINAPI IDirectSoundBufferImpl_Create(
234 IDirectSoundImpl *ds,
235 IDirectSoundBufferImpl **pdsb,
236 LPCDSBUFFERDESC dsbd);
237 HRESULT WINAPI IDirectSoundBufferImpl_Destroy(
238 IDirectSoundBufferImpl *pdsb);
240 /*****************************************************************************
241 * SecondaryBuffer implementation structure
243 struct SecondaryBufferImpl
245 IDirectSoundBuffer8Vtbl *lpVtbl;
247 IDirectSoundBufferImpl* dsb;
250 HRESULT WINAPI SecondaryBufferImpl_Create(
251 IDirectSoundBufferImpl *dsb,
252 SecondaryBufferImpl **pdsb);
253 HRESULT WINAPI SecondaryBufferImpl_Destroy(
254 SecondaryBufferImpl *pdsb);
256 /*****************************************************************************
257 * PrimaryBuffer implementation structure
259 struct PrimaryBufferImpl
261 IDirectSoundBuffer8Vtbl *lpVtbl;
263 IDirectSoundImpl* dsound;
266 HRESULT WINAPI PrimaryBufferImpl_Create(
267 IDirectSoundImpl *ds,
268 PrimaryBufferImpl **pdsb,
269 LPCDSBUFFERDESC dsbd);
271 /*****************************************************************************
272 * IDirectSoundCapture implementation structure
274 struct IDirectSoundCaptureImpl
276 /* IUnknown fields */
277 IDirectSoundCaptureVtbl *lpVtbl;
280 /* IDirectSoundCaptureImpl fields */
284 /* DirectSound driver stuff */
286 DSDRIVERDESC drvdesc;
287 DSCDRIVERCAPS drvcaps;
288 PIDSCDRIVERBUFFER hwbuf;
290 /* wave driver info */
300 IDirectSoundCaptureBufferImpl* capture_buffer;
305 CRITICAL_SECTION lock;
308 /*****************************************************************************
309 * IDirectSoundCaptureBuffer implementation structure
311 struct IDirectSoundCaptureBufferImpl
313 /* IUnknown fields */
314 IDirectSoundCaptureBuffer8Vtbl *lpVtbl;
317 /* IDirectSoundCaptureBufferImpl fields */
318 IDirectSoundCaptureImpl* dsound;
319 /* FIXME: don't need this */
320 LPDSCBUFFERDESC pdscbd;
323 /* IDirectSoundCaptureNotifyImpl fields */
324 IDirectSoundCaptureNotifyImpl* notify;
325 LPDSBPOSITIONNOTIFY notifies;
327 PIDSDRIVERNOTIFY hwnotify;
330 /*****************************************************************************
331 * IDirectSoundFullDuplex implementation structure
333 struct IDirectSoundFullDuplexImpl
335 /* IUnknown fields */
336 IDirectSoundFullDuplexVtbl *lpVtbl;
339 /* IDirectSoundFullDuplexImpl fields */
340 CRITICAL_SECTION lock;
343 /*****************************************************************************
344 * IDirectSoundNotify implementation structure
346 struct IDirectSoundNotifyImpl
348 /* IUnknown fields */
349 IDirectSoundNotifyVtbl *lpVtbl;
351 IDirectSoundBufferImpl* dsb;
354 HRESULT WINAPI IDirectSoundNotifyImpl_Create(
355 IDirectSoundBufferImpl *dsb,
356 IDirectSoundNotifyImpl **pdsn);
357 HRESULT WINAPI IDirectSoundNotifyImpl_Destroy(
358 IDirectSoundNotifyImpl *pdsn);
360 /*****************************************************************************
361 * IDirectSoundCaptureNotify implementation structure
363 struct IDirectSoundCaptureNotifyImpl
365 /* IUnknown fields */
366 IDirectSoundNotifyVtbl *lpVtbl;
368 IDirectSoundCaptureBufferImpl* dscb;
371 HRESULT WINAPI IDirectSoundCaptureNotifyImpl_Create(
372 IDirectSoundCaptureBufferImpl *dscb,
373 IDirectSoundCaptureNotifyImpl ** pdscn);
375 /*****************************************************************************
376 * IDirectSound3DListener implementation structure
378 struct IDirectSound3DListenerImpl
380 /* IUnknown fields */
381 IDirectSound3DListenerVtbl *lpVtbl;
383 /* IDirectSound3DListenerImpl fields */
384 IDirectSoundImpl* dsound;
387 HRESULT WINAPI IDirectSound3DListenerImpl_Create(
388 PrimaryBufferImpl *pb,
389 IDirectSound3DListenerImpl **pdsl);
391 /*****************************************************************************
392 * IKsBufferPropertySet implementation structure
394 struct IKsBufferPropertySetImpl
396 /* IUnknown fields */
397 IKsPropertySetVtbl *lpVtbl;
399 /* IKsPropertySetImpl fields */
400 IDirectSoundBufferImpl* dsb;
403 HRESULT WINAPI IKsBufferPropertySetImpl_Create(
404 IDirectSoundBufferImpl *dsb,
405 IKsBufferPropertySetImpl **piks);
406 HRESULT WINAPI IKsBufferPropertySetImpl_Destroy(
407 IKsBufferPropertySetImpl *piks);
409 /*****************************************************************************
410 * IKsPrivatePropertySet implementation structure
412 struct IKsPrivatePropertySetImpl
414 /* IUnknown fields */
415 IKsPropertySetVtbl *lpVtbl;
419 HRESULT WINAPI IKsPrivatePropertySetImpl_Create(
420 IKsPrivatePropertySetImpl **piks);
422 /*****************************************************************************
423 * IDirectSound3DBuffer implementation structure
425 struct IDirectSound3DBufferImpl
427 /* IUnknown fields */
428 IDirectSound3DBufferVtbl *lpVtbl;
430 /* IDirectSound3DBufferImpl fields */
431 IDirectSoundBufferImpl* dsb;
434 HRESULT WINAPI IDirectSound3DBufferImpl_Create(
435 IDirectSoundBufferImpl *dsb,
436 IDirectSound3DBufferImpl **pds3db);
437 HRESULT WINAPI IDirectSound3DBufferImpl_Destroy(
438 IDirectSound3DBufferImpl *pds3db);
440 /*******************************************************************************
441 * DirectSound ClassFactory implementation structure
443 struct IClassFactoryImpl
445 /* IUnknown fields */
446 IClassFactoryVtbl *lpVtbl;
450 extern IClassFactoryImpl DSOUND_CAPTURE_CF;
451 extern IClassFactoryImpl DSOUND_FULLDUPLEX_CF;
453 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
454 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan);
455 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
459 HRESULT DSOUND_AddBuffer(IDirectSoundImpl * pDS, IDirectSoundBufferImpl * pDSB);
460 HRESULT DSOUND_RemoveBuffer(IDirectSoundImpl * pDS, IDirectSoundBufferImpl * pDSB);
464 HRESULT DSOUND_PrimaryCreate(IDirectSoundImpl *This);
465 HRESULT DSOUND_PrimaryDestroy(IDirectSoundImpl *This);
466 HRESULT DSOUND_PrimaryPlay(IDirectSoundImpl *This);
467 HRESULT DSOUND_PrimaryStop(IDirectSoundImpl *This);
468 HRESULT DSOUND_PrimaryGetPosition(IDirectSoundImpl *This, LPDWORD playpos, LPDWORD writepos);
472 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
473 DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix);
477 void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len);
478 void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb);
479 void DSOUND_MixCancelAt(IDirectSoundBufferImpl *dsb, DWORD buf_writepos);
480 void DSOUND_WaveQueue(IDirectSoundImpl *dsound, DWORD mixq);
481 void DSOUND_PerformMix(IDirectSoundImpl *dsound);
482 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
483 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
487 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb);
489 #define STATE_STOPPED 0
490 #define STATE_STARTING 1
491 #define STATE_PLAYING 2
492 #define STATE_CAPTURING 2
493 #define STATE_STOPPING 3
495 #define DSOUND_FREQSHIFT (14)
497 extern IDirectSoundImpl* dsound;
499 extern GUID renderer_guids[MAXWAVEDRIVERS];
500 extern GUID capture_guids[MAXWAVEDRIVERS];
502 extern HRESULT mmErr(UINT err);
503 extern void setup_dsound_options(void);
504 extern const char * get_device_id(LPCGUID pGuid);