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 IDirectSoundBufferImpl IDirectSoundBufferImpl;
49 typedef struct IDirectSoundCaptureImpl IDirectSoundCaptureImpl;
50 typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl;
51 typedef struct IDirectSoundFullDuplexImpl IDirectSoundFullDuplexImpl;
52 typedef struct IDirectSoundNotifyImpl IDirectSoundNotifyImpl;
53 typedef struct IDirectSoundCaptureNotifyImpl IDirectSoundCaptureNotifyImpl;
54 typedef struct IDirectSound3DListenerImpl IDirectSound3DListenerImpl;
55 typedef struct IDirectSound3DBufferImpl IDirectSound3DBufferImpl;
56 typedef struct IKsBufferPropertySetImpl IKsBufferPropertySetImpl;
57 typedef struct IKsPrivatePropertySetImpl IKsPrivatePropertySetImpl;
58 typedef struct PrimaryBufferImpl PrimaryBufferImpl;
59 typedef struct SecondaryBufferImpl SecondaryBufferImpl;
60 typedef struct IClassFactoryImpl IClassFactoryImpl;
62 /*****************************************************************************
63 * IDirectSound implementation structure
65 struct IDirectSoundImpl
68 ICOM_VFIELD(IDirectSound8);
70 /* IDirectSoundImpl fields */
76 WAVEFORMATEX wfx; /* current main waveformat */
78 LPWAVEHDR pwave[DS_HEL_FRAGS];
79 UINT timerID, pwplay, pwwrite, pwqueue, prebuf, precount;
81 PIDSDRIVERBUFFER hwbuf;
83 DWORD writelead, buflen, state, playpos, mixpos;
86 IDirectSoundBufferImpl** buffers;
88 CRITICAL_SECTION mixlock;
90 PrimaryBufferImpl* primary;
94 /* DirectSound3DListener fields */
95 IDirectSound3DListenerImpl* listener;
97 CRITICAL_SECTION ds3dl_lock;
98 BOOL ds3dl_need_recalc;
101 /* reference counted buffer memory for duplicated buffer memory */
102 typedef struct BufferMemory
108 /*****************************************************************************
109 * IDirectSoundBuffer implementation structure
111 struct IDirectSoundBufferImpl
113 /* FIXME: document */
114 /* IUnknown fields */
115 ICOM_VFIELD(IDirectSoundBuffer8);
117 /* IDirectSoundBufferImpl fields */
118 SecondaryBufferImpl* dsb;
119 IDirectSoundImpl* dsound;
120 CRITICAL_SECTION lock;
121 PIDSDRIVERBUFFER hwbuf;
123 BufferMemory* buffer;
124 DWORD playflags,state,leadin;
125 DWORD playpos,startpos,writelead,buflen;
126 DWORD nAvgBytesPerSec;
128 DSVOLUMEPAN volpan, cvolpan;
130 /* used for frequency conversion (PerfectPitch) */
131 ULONG freqAdjust, freqAcc;
132 /* used for intelligent (well, sort of) prebuffering */
133 DWORD probably_valid_to, last_playpos;
134 DWORD primary_mixpos, buf_mixpos;
137 /* IDirectSoundNotifyImpl fields */
138 IDirectSoundNotifyImpl* notify;
139 LPDSBPOSITIONNOTIFY notifies;
141 PIDSDRIVERNOTIFY hwnotify;
143 /* DirectSound3DBuffer fields */
144 IDirectSound3DBufferImpl* ds3db;
145 DS3DBUFFER ds3db_ds3db;
147 BOOL ds3db_need_recalc;
149 /* IKsPropertySet fields */
150 IKsBufferPropertySetImpl* iks;
153 HRESULT WINAPI IDirectSoundBufferImpl_Create(
154 IDirectSoundImpl *ds,
155 IDirectSoundBufferImpl **pdsb,
156 LPDSBUFFERDESC dsbd);
158 /*****************************************************************************
159 * SecondaryBuffer implementation structure
161 struct SecondaryBufferImpl
163 ICOM_VFIELD(IDirectSoundBuffer8);
165 IDirectSoundBufferImpl* dsb;
168 HRESULT WINAPI SecondaryBufferImpl_Create(
169 IDirectSoundBufferImpl *dsb,
170 SecondaryBufferImpl **pdsb);
172 /*****************************************************************************
173 * PrimaryBuffer implementation structure
175 struct PrimaryBufferImpl
177 ICOM_VFIELD(IDirectSoundBuffer8);
179 IDirectSoundImpl* dsound;
182 HRESULT WINAPI PrimaryBufferImpl_Create(
183 IDirectSoundImpl *ds,
184 PrimaryBufferImpl **pdsb,
185 LPDSBUFFERDESC dsbd);
187 /*****************************************************************************
188 * IDirectSoundCapture implementation structure
190 struct IDirectSoundCaptureImpl
192 /* IUnknown fields */
193 ICOM_VFIELD(IDirectSoundCapture);
196 /* IDirectSoundCaptureImpl fields */
200 /* DirectSound driver stuff */
202 DSDRIVERDESC drvdesc;
203 DSCDRIVERCAPS drvcaps;
204 PIDSCDRIVERBUFFER hwbuf;
206 /* wave driver info */
214 /* FIXME: this should be a pointer because it can be bigger */
217 IDirectSoundCaptureBufferImpl* capture_buffer;
222 CRITICAL_SECTION lock;
225 /*****************************************************************************
226 * IDirectSoundCaptureBuffer implementation structure
228 struct IDirectSoundCaptureBufferImpl
230 /* IUnknown fields */
231 ICOM_VFIELD(IDirectSoundCaptureBuffer8);
234 /* IDirectSoundCaptureBufferImpl fields */
235 IDirectSoundCaptureImpl* dsound;
236 /* FIXME: don't need this */
237 LPDSCBUFFERDESC pdscbd;
240 /* IDirectSoundCaptureNotifyImpl fields */
241 IDirectSoundCaptureNotifyImpl* notify;
242 LPDSBPOSITIONNOTIFY notifies;
244 PIDSDRIVERNOTIFY hwnotify;
247 /*****************************************************************************
248 * IDirectSoundFullDuplex implementation structure
250 struct IDirectSoundFullDuplexImpl
252 /* IUnknown fields */
253 ICOM_VFIELD(IDirectSoundFullDuplex);
256 /* IDirectSoundFullDuplexImpl fields */
257 CRITICAL_SECTION lock;
260 /*****************************************************************************
261 * IDirectSoundNotify implementation structure
263 struct IDirectSoundNotifyImpl
265 /* IUnknown fields */
266 ICOM_VFIELD(IDirectSoundNotify);
268 IDirectSoundBufferImpl* dsb;
271 HRESULT WINAPI IDirectSoundNotifyImpl_Create(
272 IDirectSoundBufferImpl *dsb,
273 IDirectSoundNotifyImpl **pdsn);
275 /*****************************************************************************
276 * IDirectSoundCaptureNotify implementation structure
278 struct IDirectSoundCaptureNotifyImpl
280 /* IUnknown fields */
281 ICOM_VFIELD(IDirectSoundNotify);
283 IDirectSoundCaptureBufferImpl* dscb;
286 HRESULT WINAPI IDirectSoundCaptureNotifyImpl_Create(
287 IDirectSoundCaptureBufferImpl *dscb,
288 IDirectSoundCaptureNotifyImpl ** pdscn);
290 /*****************************************************************************
291 * IDirectSound3DListener implementation structure
293 struct IDirectSound3DListenerImpl
295 /* IUnknown fields */
296 ICOM_VFIELD(IDirectSound3DListener);
298 /* IDirectSound3DListenerImpl fields */
299 IDirectSoundImpl* dsound;
302 HRESULT WINAPI IDirectSound3DListenerImpl_Create(
303 PrimaryBufferImpl *pb,
304 IDirectSound3DListenerImpl **pdsl);
306 /*****************************************************************************
307 * IKsBufferPropertySet implementation structure
309 struct IKsBufferPropertySetImpl
311 /* IUnknown fields */
312 ICOM_VFIELD(IKsPropertySet);
314 /* IKsPropertySetImpl fields */
315 IDirectSoundBufferImpl* dsb;
318 HRESULT WINAPI IKsBufferPropertySetImpl_Create(
319 IDirectSoundBufferImpl *dsb,
320 IKsBufferPropertySetImpl **piks);
322 /*****************************************************************************
323 * IKsPrivatePropertySet implementation structure
325 struct IKsPrivatePropertySetImpl
327 /* IUnknown fields */
328 ICOM_VFIELD(IKsPropertySet);
332 HRESULT WINAPI IKsPrivatePropertySetImpl_Create(
333 IKsPrivatePropertySetImpl **piks);
335 /*****************************************************************************
336 * IDirectSound3DBuffer implementation structure
338 struct IDirectSound3DBufferImpl
340 /* IUnknown fields */
341 ICOM_VFIELD(IDirectSound3DBuffer);
343 /* IDirectSound3DBufferImpl fields */
344 IDirectSoundBufferImpl* dsb;
347 HRESULT WINAPI IDirectSound3DBufferImpl_Create(
348 IDirectSoundBufferImpl *dsb,
349 IDirectSound3DBufferImpl **pds3db);
351 /*******************************************************************************
352 * DirectSound ClassFactory implementation structure
354 struct IClassFactoryImpl
356 /* IUnknown fields */
357 ICOM_VFIELD(IClassFactory);
361 extern IClassFactoryImpl DSOUND_CAPTURE_CF;
362 extern IClassFactoryImpl DSOUND_FULLDUPLEX_CF;
364 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
365 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
369 HRESULT DSOUND_PrimaryCreate(IDirectSoundImpl *This);
370 HRESULT DSOUND_PrimaryDestroy(IDirectSoundImpl *This);
371 HRESULT DSOUND_PrimaryPlay(IDirectSoundImpl *This);
372 HRESULT DSOUND_PrimaryStop(IDirectSoundImpl *This);
373 HRESULT DSOUND_PrimaryGetPosition(IDirectSoundImpl *This, LPDWORD playpos, LPDWORD writepos);
377 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
378 DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix);
382 void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len);
383 void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb);
384 void DSOUND_MixCancelAt(IDirectSoundBufferImpl *dsb, DWORD buf_writepos);
385 void DSOUND_WaveQueue(IDirectSoundImpl *dsound, DWORD mixq);
386 void DSOUND_PerformMix(void);
387 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
388 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
392 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb);
394 #define STATE_STOPPED 0
395 #define STATE_STARTING 1
396 #define STATE_PLAYING 2
397 #define STATE_CAPTURING 2
398 #define STATE_STOPPING 3
400 #define DSOUND_FREQSHIFT (14)
402 extern IDirectSoundImpl* dsound;
403 extern IDirectSoundCaptureImpl* dsound_capture;
405 extern HRESULT mmErr(UINT err);
406 extern void setup_dsound_options(void);