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 BOOL ds3dl_need_recalc;
100 /* reference counted buffer memory for duplicated buffer memory */
101 typedef struct BufferMemory
107 /*****************************************************************************
108 * IDirectSoundBuffer implementation structure
110 struct IDirectSoundBufferImpl
112 /* FIXME: document */
113 /* IUnknown fields */
114 ICOM_VFIELD(IDirectSoundBuffer8);
116 /* IDirectSoundBufferImpl fields */
117 SecondaryBufferImpl* dsb;
118 IDirectSoundImpl* dsound;
119 CRITICAL_SECTION lock;
120 PIDSDRIVERBUFFER hwbuf;
122 BufferMemory* buffer;
123 DWORD playflags,state,leadin;
124 DWORD playpos,startpos,writelead,buflen;
125 DWORD nAvgBytesPerSec;
127 DSVOLUMEPAN volpan, cvolpan;
129 /* used for frequency conversion (PerfectPitch) */
130 ULONG freqAdjust, freqAcc;
131 /* used for intelligent (well, sort of) prebuffering */
132 DWORD probably_valid_to, last_playpos;
133 DWORD primary_mixpos, buf_mixpos;
136 /* IDirectSoundNotifyImpl fields */
137 IDirectSoundNotifyImpl* notify;
138 LPDSBPOSITIONNOTIFY notifies;
140 PIDSDRIVERNOTIFY hwnotify;
142 /* DirectSound3DBuffer fields */
143 IDirectSound3DBufferImpl* ds3db;
144 DS3DBUFFER ds3db_ds3db;
146 BOOL ds3db_need_recalc;
148 /* IKsPropertySet fields */
149 IKsBufferPropertySetImpl* iks;
152 HRESULT WINAPI IDirectSoundBufferImpl_Create(
153 IDirectSoundImpl *ds,
154 IDirectSoundBufferImpl **pdsb,
155 LPCDSBUFFERDESC dsbd);
157 /*****************************************************************************
158 * SecondaryBuffer implementation structure
160 struct SecondaryBufferImpl
162 ICOM_VFIELD(IDirectSoundBuffer8);
164 IDirectSoundBufferImpl* dsb;
167 HRESULT WINAPI SecondaryBufferImpl_Create(
168 IDirectSoundBufferImpl *dsb,
169 SecondaryBufferImpl **pdsb);
171 /*****************************************************************************
172 * PrimaryBuffer implementation structure
174 struct PrimaryBufferImpl
176 ICOM_VFIELD(IDirectSoundBuffer8);
178 IDirectSoundImpl* dsound;
181 HRESULT WINAPI PrimaryBufferImpl_Create(
182 IDirectSoundImpl *ds,
183 PrimaryBufferImpl **pdsb,
184 LPCDSBUFFERDESC dsbd);
186 /*****************************************************************************
187 * IDirectSoundCapture implementation structure
189 struct IDirectSoundCaptureImpl
191 /* IUnknown fields */
192 ICOM_VFIELD(IDirectSoundCapture);
195 /* IDirectSoundCaptureImpl fields */
199 /* DirectSound driver stuff */
201 DSDRIVERDESC drvdesc;
202 DSCDRIVERCAPS drvcaps;
203 PIDSCDRIVERBUFFER hwbuf;
205 /* wave driver info */
215 IDirectSoundCaptureBufferImpl* capture_buffer;
220 CRITICAL_SECTION lock;
223 /*****************************************************************************
224 * IDirectSoundCaptureBuffer implementation structure
226 struct IDirectSoundCaptureBufferImpl
228 /* IUnknown fields */
229 ICOM_VFIELD(IDirectSoundCaptureBuffer8);
232 /* IDirectSoundCaptureBufferImpl fields */
233 IDirectSoundCaptureImpl* dsound;
234 /* FIXME: don't need this */
235 LPDSCBUFFERDESC pdscbd;
238 /* IDirectSoundCaptureNotifyImpl fields */
239 IDirectSoundCaptureNotifyImpl* notify;
240 LPDSBPOSITIONNOTIFY notifies;
242 PIDSDRIVERNOTIFY hwnotify;
245 /*****************************************************************************
246 * IDirectSoundFullDuplex implementation structure
248 struct IDirectSoundFullDuplexImpl
250 /* IUnknown fields */
251 ICOM_VFIELD(IDirectSoundFullDuplex);
254 /* IDirectSoundFullDuplexImpl fields */
255 CRITICAL_SECTION lock;
258 /*****************************************************************************
259 * IDirectSoundNotify implementation structure
261 struct IDirectSoundNotifyImpl
263 /* IUnknown fields */
264 ICOM_VFIELD(IDirectSoundNotify);
266 IDirectSoundBufferImpl* dsb;
269 HRESULT WINAPI IDirectSoundNotifyImpl_Create(
270 IDirectSoundBufferImpl *dsb,
271 IDirectSoundNotifyImpl **pdsn);
273 /*****************************************************************************
274 * IDirectSoundCaptureNotify implementation structure
276 struct IDirectSoundCaptureNotifyImpl
278 /* IUnknown fields */
279 ICOM_VFIELD(IDirectSoundNotify);
281 IDirectSoundCaptureBufferImpl* dscb;
284 HRESULT WINAPI IDirectSoundCaptureNotifyImpl_Create(
285 IDirectSoundCaptureBufferImpl *dscb,
286 IDirectSoundCaptureNotifyImpl ** pdscn);
288 /*****************************************************************************
289 * IDirectSound3DListener implementation structure
291 struct IDirectSound3DListenerImpl
293 /* IUnknown fields */
294 ICOM_VFIELD(IDirectSound3DListener);
296 /* IDirectSound3DListenerImpl fields */
297 IDirectSoundImpl* dsound;
300 HRESULT WINAPI IDirectSound3DListenerImpl_Create(
301 PrimaryBufferImpl *pb,
302 IDirectSound3DListenerImpl **pdsl);
304 /*****************************************************************************
305 * IKsBufferPropertySet implementation structure
307 struct IKsBufferPropertySetImpl
309 /* IUnknown fields */
310 ICOM_VFIELD(IKsPropertySet);
312 /* IKsPropertySetImpl fields */
313 IDirectSoundBufferImpl* dsb;
316 HRESULT WINAPI IKsBufferPropertySetImpl_Create(
317 IDirectSoundBufferImpl *dsb,
318 IKsBufferPropertySetImpl **piks);
320 /*****************************************************************************
321 * IKsPrivatePropertySet implementation structure
323 struct IKsPrivatePropertySetImpl
325 /* IUnknown fields */
326 ICOM_VFIELD(IKsPropertySet);
330 HRESULT WINAPI IKsPrivatePropertySetImpl_Create(
331 IKsPrivatePropertySetImpl **piks);
333 /*****************************************************************************
334 * IDirectSound3DBuffer implementation structure
336 struct IDirectSound3DBufferImpl
338 /* IUnknown fields */
339 ICOM_VFIELD(IDirectSound3DBuffer);
341 /* IDirectSound3DBufferImpl fields */
342 IDirectSoundBufferImpl* dsb;
345 HRESULT WINAPI IDirectSound3DBufferImpl_Create(
346 IDirectSoundBufferImpl *dsb,
347 IDirectSound3DBufferImpl **pds3db);
349 /*******************************************************************************
350 * DirectSound ClassFactory implementation structure
352 struct IClassFactoryImpl
354 /* IUnknown fields */
355 ICOM_VFIELD(IClassFactory);
359 extern IClassFactoryImpl DSOUND_CAPTURE_CF;
360 extern IClassFactoryImpl DSOUND_FULLDUPLEX_CF;
362 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
363 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
367 HRESULT DSOUND_PrimaryCreate(IDirectSoundImpl *This);
368 HRESULT DSOUND_PrimaryDestroy(IDirectSoundImpl *This);
369 HRESULT DSOUND_PrimaryPlay(IDirectSoundImpl *This);
370 HRESULT DSOUND_PrimaryStop(IDirectSoundImpl *This);
371 HRESULT DSOUND_PrimaryGetPosition(IDirectSoundImpl *This, LPDWORD playpos, LPDWORD writepos);
375 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
376 DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix);
380 void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len);
381 void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb);
382 void DSOUND_MixCancelAt(IDirectSoundBufferImpl *dsb, DWORD buf_writepos);
383 void DSOUND_WaveQueue(IDirectSoundImpl *dsound, DWORD mixq);
384 void DSOUND_PerformMix(IDirectSoundImpl *dsound);
385 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
386 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
390 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb);
392 #define STATE_STOPPED 0
393 #define STATE_STARTING 1
394 #define STATE_PLAYING 2
395 #define STATE_CAPTURING 2
396 #define STATE_STOPPING 3
398 #define DSOUND_FREQSHIFT (14)
400 extern IDirectSoundImpl* dsound;
402 extern HRESULT mmErr(UINT err);
403 extern void setup_dsound_options(void);