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 IDirectSound3DListenerImpl IDirectSound3DListenerImpl;
54 typedef struct IDirectSound3DBufferImpl IDirectSound3DBufferImpl;
55 typedef struct IKsPropertySetImpl IKsPropertySetImpl;
56 typedef struct PrimaryBufferImpl PrimaryBufferImpl;
58 /*****************************************************************************
59 * IDirectSound implementation structure
61 struct IDirectSoundImpl
64 ICOM_VFIELD(IDirectSound8);
66 /* IDirectSoundImpl fields */
72 WAVEFORMATEX wfx; /* current main waveformat */
74 LPWAVEHDR pwave[DS_HEL_FRAGS];
75 UINT timerID, pwplay, pwwrite, pwqueue, prebuf, precount;
77 PIDSDRIVERBUFFER hwbuf;
79 DWORD writelead, buflen, state, playpos, mixpos;
82 IDirectSoundBufferImpl** buffers;
84 CRITICAL_SECTION mixlock;
86 PrimaryBufferImpl* primary;
89 /* DirectSound3DListener fields */
90 IDirectSound3DListenerImpl* listener;
92 CRITICAL_SECTION ds3dl_lock;
93 BOOL ds3dl_need_recalc;
96 /* reference counted buffer memory for duplicated buffer memory */
97 typedef struct BufferMemory
103 /*****************************************************************************
104 * IDirectSoundBuffer implementation structure
106 struct IDirectSoundBufferImpl
108 /* FIXME: document */
109 /* IUnknown fields */
110 ICOM_VFIELD(IDirectSoundBuffer8);
112 /* IDirectSoundBufferImpl fields */
113 IDirectSoundImpl* dsound;
114 IDirectSound3DBufferImpl* ds3db;
115 IKsPropertySetImpl* iks;
116 CRITICAL_SECTION lock;
117 PIDSDRIVERBUFFER hwbuf;
119 BufferMemory* buffer;
120 DWORD playflags,state,leadin;
121 DWORD playpos,startpos,writelead,buflen;
122 DWORD nAvgBytesPerSec;
124 DSVOLUMEPAN volpan, cvolpan;
126 /* used for frequency conversion (PerfectPitch) */
127 ULONG freqAdjust, freqAcc;
128 /* used for intelligent (well, sort of) prebuffering */
129 DWORD probably_valid_to, last_playpos;
130 DWORD primary_mixpos, buf_mixpos;
132 /* IDirectSoundNotifyImpl fields */
133 IDirectSoundNotifyImpl* notify;
135 /* DirectSound3DBuffer fields */
136 DS3DBUFFER ds3db_ds3db;
138 BOOL ds3db_need_recalc;
141 HRESULT WINAPI SecondaryBuffer_Create(
142 IDirectSoundImpl *This,
143 IDirectSoundBufferImpl **pdsb,
144 LPDSBUFFERDESC dsbd);
146 struct PrimaryBufferImpl {
147 ICOM_VFIELD(IDirectSoundBuffer8);
149 IDirectSoundImpl* dsound;
152 HRESULT WINAPI PrimaryBuffer_Create(
153 IDirectSoundImpl *This,
154 PrimaryBufferImpl **pdsb,
155 LPDSBUFFERDESC dsbd);
157 /*****************************************************************************
158 * IDirectSoundCapture implementation structure
160 struct IDirectSoundCaptureImpl
162 /* IUnknown fields */
163 ICOM_VFIELD(IDirectSoundCapture);
166 /* IDirectSoundCaptureImpl fields */
170 /* DirectSound driver stuff */
172 DSDRIVERDESC drvdesc;
173 DSCDRIVERCAPS drvcaps;
174 PIDSCDRIVERBUFFER hwbuf;
176 /* wave driver info */
184 /* FIXME: this should be a pointer because it can be bigger */
187 IDirectSoundCaptureBufferImpl* capture_buffer;
192 CRITICAL_SECTION lock;
195 /*****************************************************************************
196 * IDirectSoundCaptureBuffer implementation structure
198 struct IDirectSoundCaptureBufferImpl
200 /* IUnknown fields */
201 ICOM_VFIELD(IDirectSoundCaptureBuffer8);
204 /* IDirectSoundCaptureBufferImpl fields */
205 IDirectSoundCaptureImpl* dsound;
206 /* FIXME: don't need this */
207 LPDSCBUFFERDESC pdscbd;
209 /* IDirectSoundNotifyImpl fields */
210 IDirectSoundNotifyImpl* notify;
213 /*****************************************************************************
214 * IDirectSoundFullDuplex implementation structure
216 struct IDirectSoundFullDuplexImpl
218 /* IUnknown fields */
219 ICOM_VFIELD(IDirectSoundFullDuplex);
222 /* IDirectSoundFullDuplexImpl fields */
223 CRITICAL_SECTION lock;
226 /*****************************************************************************
227 * IDirectSoundNotify implementation structure
229 struct IDirectSoundNotifyImpl
231 /* IUnknown fields */
232 ICOM_VFIELD(IDirectSoundNotify);
234 /* IDirectSoundNotifyImpl fields */
235 LPDSBPOSITIONNOTIFY notifies;
238 PIDSDRIVERNOTIFY hwnotify;
241 /*****************************************************************************
242 * IDirectSound3DListener implementation structure
244 struct IDirectSound3DListenerImpl
246 /* IUnknown fields */
247 ICOM_VFIELD(IDirectSound3DListener);
249 /* IDirectSound3DListenerImpl fields */
250 IDirectSoundImpl* dsound;
253 HRESULT WINAPI IDirectSound3DListenerImpl_Create(
254 PrimaryBufferImpl *This,
255 IDirectSound3DListenerImpl **pdsl);
257 /*****************************************************************************
258 * IKsPropertySet implementation structure
260 struct IKsPropertySetImpl
262 /* IUnknown fields */
263 ICOM_VFIELD(IKsPropertySet);
265 /* IKsPropertySetImpl fields */
266 IDirectSoundBufferImpl* dsb;
269 HRESULT WINAPI IKsPropertySetImpl_Create(
270 IDirectSoundBufferImpl *This,
271 IKsPropertySetImpl **piks);
273 /*****************************************************************************
274 * IDirectSound3DBuffer implementation structure
276 struct IDirectSound3DBufferImpl
278 /* IUnknown fields */
279 ICOM_VFIELD(IDirectSound3DBuffer);
281 /* IDirectSound3DBufferImpl fields */
282 IDirectSoundBufferImpl* dsb;
283 CRITICAL_SECTION lock;
286 HRESULT WINAPI IDirectSound3DBufferImpl_Create(
287 IDirectSoundBufferImpl *This,
288 IDirectSound3DBufferImpl **pds3db);
290 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
291 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
295 HRESULT DSOUND_PrimaryCreate(IDirectSoundImpl *This);
296 HRESULT DSOUND_PrimaryDestroy(IDirectSoundImpl *This);
297 HRESULT DSOUND_PrimaryPlay(IDirectSoundImpl *This);
298 HRESULT DSOUND_PrimaryStop(IDirectSoundImpl *This);
299 HRESULT DSOUND_PrimaryGetPosition(IDirectSoundImpl *This, LPDWORD playpos, LPDWORD writepos);
303 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
304 DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix);
308 void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len);
309 void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb);
310 void DSOUND_MixCancelAt(IDirectSoundBufferImpl *dsb, DWORD buf_writepos);
311 void DSOUND_WaveQueue(IDirectSoundImpl *dsound, DWORD mixq);
312 void DSOUND_PerformMix(void);
313 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
314 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
318 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb);
320 #define STATE_STOPPED 0
321 #define STATE_STARTING 1
322 #define STATE_PLAYING 2
323 #define STATE_CAPTURING 2
324 #define STATE_STOPPING 3
326 #define DSOUND_FREQSHIFT (14)
328 extern IDirectSoundImpl* dsound;
329 extern IDirectSoundCaptureImpl* dsound_capture;
331 extern ICOM_VTABLE(IDirectSoundNotify) dsnvt;
332 extern HRESULT mmErr(UINT err);
333 extern void setup_dsound_options(void);