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 IDirectSoundNotifyImpl *notify;
123 HRESULT WINAPI SecondaryBuffer_Create(
124 IDirectSoundImpl *This,
125 IDirectSoundBufferImpl **pdsb,
126 LPDSBUFFERDESC dsbd);
128 struct PrimaryBufferImpl {
129 ICOM_VFIELD(IDirectSoundBuffer8);
131 IDirectSoundImpl* dsound;
135 HRESULT WINAPI PrimaryBuffer_Create(
136 IDirectSoundImpl *This,
137 PrimaryBufferImpl **pdsb,
138 LPDSBUFFERDESC dsbd);
140 /*****************************************************************************
141 * IDirectSoundCapture implementation structure
143 struct IDirectSoundCaptureImpl
145 /* IUnknown fields */
146 ICOM_VFIELD(IDirectSoundCapture);
149 /* IDirectSoundCaptureImpl fields */
153 /* DirectSound driver stuff */
155 DSDRIVERDESC drvdesc;
156 DSCDRIVERCAPS drvcaps;
157 PIDSCDRIVERBUFFER hwbuf;
159 /* wave driver info */
167 /* FIXME: this should be a pointer because it can be bigger */
170 IDirectSoundCaptureBufferImpl* capture_buffer;
175 CRITICAL_SECTION lock;
178 /*****************************************************************************
179 * IDirectSoundCaptureBuffer implementation structure
181 struct IDirectSoundCaptureBufferImpl
183 /* IUnknown fields */
184 ICOM_VFIELD(IDirectSoundCaptureBuffer8);
187 /* IDirectSoundCaptureBufferImpl fields */
188 IDirectSoundCaptureImpl* dsound;
189 /* FIXME: don't need this */
190 LPDSCBUFFERDESC pdscbd;
192 /* IDirectSoundNotifyImpl fields */
193 IDirectSoundNotifyImpl *notify;
196 /*****************************************************************************
197 * IDirectSoundFullDuplex implementation structure
199 struct IDirectSoundFullDuplexImpl
201 /* IUnknown fields */
202 ICOM_VFIELD(IDirectSoundFullDuplex);
205 /* IDirectSoundFullDuplexImpl fields */
206 CRITICAL_SECTION lock;
209 /*****************************************************************************
210 * IDirectSoundNotify implementation structure
212 struct IDirectSoundNotifyImpl
214 /* IUnknown fields */
215 ICOM_VFIELD(IDirectSoundNotify);
217 /* IDirectSoundNotifyImpl fields */
218 LPDSBPOSITIONNOTIFY notifies;
221 PIDSDRIVERNOTIFY hwnotify;
224 /*****************************************************************************
225 * IDirectSound3DListener implementation structure
227 struct IDirectSound3DListenerImpl
229 /* IUnknown fields */
230 ICOM_VFIELD(IDirectSound3DListener);
232 /* IDirectSound3DListenerImpl fields */
233 PrimaryBufferImpl* dsb;
235 CRITICAL_SECTION lock;
239 HRESULT WINAPI IDirectSound3DListenerImpl_Create(
240 PrimaryBufferImpl *This,
241 IDirectSound3DListenerImpl **pdsl);
243 /*****************************************************************************
244 * IKsPropertySet implementation structure
246 struct IKsPropertySetImpl
248 /* IUnknown fields */
249 ICOM_VFIELD(IKsPropertySet);
251 /* IKsPropertySetImpl fields */
252 IDirectSoundBufferImpl* dsb;
255 HRESULT WINAPI IKsPropertySetImpl_Create(
256 IDirectSoundBufferImpl *This,
257 IKsPropertySetImpl **piks);
259 /*****************************************************************************
260 * IDirectSound3DBuffer implementation structure
262 struct IDirectSound3DBufferImpl
264 /* IUnknown fields */
265 ICOM_VFIELD(IDirectSound3DBuffer);
267 /* IDirectSound3DBufferImpl fields */
268 IDirectSoundBufferImpl* dsb;
271 CRITICAL_SECTION lock;
275 HRESULT WINAPI IDirectSound3DBufferImpl_Create(
276 IDirectSoundBufferImpl *This,
277 IDirectSound3DBufferImpl **pds3db);
279 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
280 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
284 HRESULT DSOUND_PrimaryCreate(IDirectSoundImpl *This);
285 HRESULT DSOUND_PrimaryDestroy(IDirectSoundImpl *This);
286 HRESULT DSOUND_PrimaryPlay(IDirectSoundImpl *This);
287 HRESULT DSOUND_PrimaryStop(IDirectSoundImpl *This);
288 HRESULT DSOUND_PrimaryGetPosition(IDirectSoundImpl *This, LPDWORD playpos, LPDWORD writepos);
292 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
293 DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix);
297 void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len);
298 void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb);
299 void DSOUND_MixCancelAt(IDirectSoundBufferImpl *dsb, DWORD buf_writepos);
300 void DSOUND_WaveQueue(IDirectSoundImpl *dsound, DWORD mixq);
301 void DSOUND_PerformMix(void);
302 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
303 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
305 #define STATE_STOPPED 0
306 #define STATE_STARTING 1
307 #define STATE_PLAYING 2
308 #define STATE_CAPTURING 2
309 #define STATE_STOPPING 3
311 #define DSOUND_FREQSHIFT (14)
313 extern IDirectSoundImpl* dsound;
314 extern IDirectSoundCaptureImpl* dsound_capture;
316 struct PrimaryBuffer {
318 PIDSDRIVERBUFFER hwbuf;
322 extern ICOM_VTABLE(IDirectSoundNotify) dsnvt;
323 extern HRESULT mmErr(UINT err);
324 extern void setup_dsound_options(void);