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;
83 IDirectSound3DListenerImpl* listener;
85 CRITICAL_SECTION mixlock;
89 /*****************************************************************************
90 * IDirectSoundBuffer implementation structure
92 struct IDirectSoundBufferImpl
96 ICOM_VFIELD(IDirectSoundBuffer8);
98 /* IDirectSoundBufferImpl fields */
99 IDirectSoundImpl* dsound;
100 IDirectSoundBufferImpl* parent; /* for duplicates */
101 IDirectSound3DBufferImpl* ds3db;
102 IKsPropertySetImpl* iks;
103 CRITICAL_SECTION lock;
104 PIDSDRIVERBUFFER hwbuf;
107 DWORD playflags,state,leadin;
108 DWORD playpos,startpos,writelead,buflen;
109 DWORD nAvgBytesPerSec;
111 DSVOLUMEPAN volpan, cvolpan;
113 /* used for frequency conversion (PerfectPitch) */
114 ULONG freqAdjust, freqAcc;
115 /* used for intelligent (well, sort of) prebuffering */
116 DWORD probably_valid_to, last_playpos;
117 DWORD primary_mixpos, buf_mixpos;
119 /* IDirectSoundNotifyImpl fields */
120 LPDSBPOSITIONNOTIFY notifies;
124 HRESULT WINAPI SecondaryBuffer_Create(
125 IDirectSoundImpl *This,
126 IDirectSoundBufferImpl **pdsb,
127 LPDSBUFFERDESC dsbd);
129 struct PrimaryBufferImpl {
130 ICOM_VFIELD(IDirectSoundBuffer8);
132 IDirectSoundImpl* dsound;
136 HRESULT WINAPI PrimaryBuffer_Create(
137 IDirectSoundImpl *This,
138 PrimaryBufferImpl **pdsb,
139 LPDSBUFFERDESC dsbd);
141 /*****************************************************************************
142 * IDirectSoundCapture implementation structure
144 struct IDirectSoundCaptureImpl
146 /* IUnknown fields */
147 ICOM_VFIELD(IDirectSoundCapture);
150 /* IDirectSoundCaptureImpl fields */
154 /* DirectSound driver stuff */
156 DSDRIVERDESC drvdesc;
157 DSCDRIVERCAPS drvcaps;
158 PIDSCDRIVERBUFFER hwbuf;
160 /* wave driver info */
168 /* FIXME: this should be a pointer because it can be bigger */
171 IDirectSoundCaptureBufferImpl* capture_buffer;
176 CRITICAL_SECTION lock;
179 /*****************************************************************************
180 * IDirectSoundCaptureBuffer implementation structure
182 struct IDirectSoundCaptureBufferImpl
184 /* IUnknown fields */
185 ICOM_VFIELD(IDirectSoundCaptureBuffer8);
188 /* IDirectSoundCaptureBufferImpl fields */
189 IDirectSoundCaptureImpl* dsound;
190 /* FIXME: don't need this */
191 LPDSCBUFFERDESC pdscbd;
192 LPDSBPOSITIONNOTIFY notifies;
197 /*****************************************************************************
198 * IDirectSoundFullDuplex implementation structure
200 struct IDirectSoundFullDuplexImpl
202 /* IUnknown fields */
203 ICOM_VFIELD(IDirectSoundFullDuplex);
206 /* IDirectSoundFullDuplexImpl fields */
207 CRITICAL_SECTION lock;
210 /*****************************************************************************
211 * IDirectSoundNotify implementation structure
213 struct IDirectSoundNotifyImpl
215 /* IUnknown fields */
216 ICOM_VFIELD(IDirectSoundNotify);
218 /* IDirectSoundNotifyImpl fields */
219 IDirectSoundBufferImpl* dsb;
220 IDirectSoundCaptureBufferImpl* dscb;
223 /*****************************************************************************
224 * IDirectSound3DListener implementation structure
226 struct IDirectSound3DListenerImpl
228 /* IUnknown fields */
229 ICOM_VFIELD(IDirectSound3DListener);
231 /* IDirectSound3DListenerImpl fields */
232 PrimaryBufferImpl* dsb;
234 CRITICAL_SECTION lock;
238 HRESULT WINAPI IDirectSound3DListenerImpl_Create(
239 PrimaryBufferImpl *This,
240 IDirectSound3DListenerImpl **pdsl);
242 /*****************************************************************************
243 * IKsPropertySet implementation structure
245 struct IKsPropertySetImpl
247 /* IUnknown fields */
248 ICOM_VFIELD(IKsPropertySet);
250 /* IKsPropertySetImpl fields */
251 IDirectSoundBufferImpl* dsb;
254 HRESULT WINAPI IKsPropertySetImpl_Create(
255 IDirectSoundBufferImpl *This,
256 IKsPropertySetImpl **piks);
258 /*****************************************************************************
259 * IDirectSound3DBuffer implementation structure
261 struct IDirectSound3DBufferImpl
263 /* IUnknown fields */
264 ICOM_VFIELD(IDirectSound3DBuffer);
266 /* IDirectSound3DBufferImpl fields */
267 IDirectSoundBufferImpl* dsb;
270 CRITICAL_SECTION lock;
274 HRESULT WINAPI IDirectSound3DBufferImpl_Create(
275 IDirectSoundBufferImpl *This,
276 IDirectSound3DBufferImpl **pds3db);
278 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
279 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
283 HRESULT DSOUND_PrimaryCreate(IDirectSoundImpl *This);
284 HRESULT DSOUND_PrimaryDestroy(IDirectSoundImpl *This);
285 HRESULT DSOUND_PrimaryPlay(IDirectSoundImpl *This);
286 HRESULT DSOUND_PrimaryStop(IDirectSoundImpl *This);
287 HRESULT DSOUND_PrimaryGetPosition(IDirectSoundImpl *This, LPDWORD playpos, LPDWORD writepos);
291 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
292 DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix);
296 void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len);
297 void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb);
298 void DSOUND_MixCancelAt(IDirectSoundBufferImpl *dsb, DWORD buf_writepos);
299 void DSOUND_WaveQueue(IDirectSoundImpl *dsound, DWORD mixq);
300 void DSOUND_PerformMix(void);
301 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
302 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
304 #define STATE_STOPPED 0
305 #define STATE_STARTING 1
306 #define STATE_PLAYING 2
307 #define STATE_CAPTURING 2
308 #define STATE_STOPPING 3
310 #define DSOUND_FREQSHIFT (14)
312 extern IDirectSoundImpl* dsound;
313 extern IDirectSoundCaptureImpl* dsound_capture;
315 struct PrimaryBuffer {
317 PIDSDRIVERBUFFER hwbuf;
321 extern ICOM_VTABLE(IDirectSoundNotify) dsnvt;
322 extern HRESULT mmErr(UINT err);
323 extern void setup_dsound_options(void);