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 LPCDSBUFFERDESC 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 LPCDSBUFFERDESC 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 */
216 IDirectSoundCaptureBufferImpl
* capture_buffer
;
221 CRITICAL_SECTION lock
;
224 /*****************************************************************************
225 * IDirectSoundCaptureBuffer implementation structure
227 struct IDirectSoundCaptureBufferImpl
229 /* IUnknown fields */
230 ICOM_VFIELD(IDirectSoundCaptureBuffer8
);
233 /* IDirectSoundCaptureBufferImpl fields */
234 IDirectSoundCaptureImpl
* dsound
;
235 /* FIXME: don't need this */
236 LPDSCBUFFERDESC pdscbd
;
239 /* IDirectSoundCaptureNotifyImpl fields */
240 IDirectSoundCaptureNotifyImpl
* notify
;
241 LPDSBPOSITIONNOTIFY notifies
;
243 PIDSDRIVERNOTIFY hwnotify
;
246 /*****************************************************************************
247 * IDirectSoundFullDuplex implementation structure
249 struct IDirectSoundFullDuplexImpl
251 /* IUnknown fields */
252 ICOM_VFIELD(IDirectSoundFullDuplex
);
255 /* IDirectSoundFullDuplexImpl fields */
256 CRITICAL_SECTION lock
;
259 /*****************************************************************************
260 * IDirectSoundNotify implementation structure
262 struct IDirectSoundNotifyImpl
264 /* IUnknown fields */
265 ICOM_VFIELD(IDirectSoundNotify
);
267 IDirectSoundBufferImpl
* dsb
;
270 HRESULT WINAPI
IDirectSoundNotifyImpl_Create(
271 IDirectSoundBufferImpl
*dsb
,
272 IDirectSoundNotifyImpl
**pdsn
);
274 /*****************************************************************************
275 * IDirectSoundCaptureNotify implementation structure
277 struct IDirectSoundCaptureNotifyImpl
279 /* IUnknown fields */
280 ICOM_VFIELD(IDirectSoundNotify
);
282 IDirectSoundCaptureBufferImpl
* dscb
;
285 HRESULT WINAPI
IDirectSoundCaptureNotifyImpl_Create(
286 IDirectSoundCaptureBufferImpl
*dscb
,
287 IDirectSoundCaptureNotifyImpl
** pdscn
);
289 /*****************************************************************************
290 * IDirectSound3DListener implementation structure
292 struct IDirectSound3DListenerImpl
294 /* IUnknown fields */
295 ICOM_VFIELD(IDirectSound3DListener
);
297 /* IDirectSound3DListenerImpl fields */
298 IDirectSoundImpl
* dsound
;
301 HRESULT WINAPI
IDirectSound3DListenerImpl_Create(
302 PrimaryBufferImpl
*pb
,
303 IDirectSound3DListenerImpl
**pdsl
);
305 /*****************************************************************************
306 * IKsBufferPropertySet implementation structure
308 struct IKsBufferPropertySetImpl
310 /* IUnknown fields */
311 ICOM_VFIELD(IKsPropertySet
);
313 /* IKsPropertySetImpl fields */
314 IDirectSoundBufferImpl
* dsb
;
317 HRESULT WINAPI
IKsBufferPropertySetImpl_Create(
318 IDirectSoundBufferImpl
*dsb
,
319 IKsBufferPropertySetImpl
**piks
);
321 /*****************************************************************************
322 * IKsPrivatePropertySet implementation structure
324 struct IKsPrivatePropertySetImpl
326 /* IUnknown fields */
327 ICOM_VFIELD(IKsPropertySet
);
331 HRESULT WINAPI
IKsPrivatePropertySetImpl_Create(
332 IKsPrivatePropertySetImpl
**piks
);
334 /*****************************************************************************
335 * IDirectSound3DBuffer implementation structure
337 struct IDirectSound3DBufferImpl
339 /* IUnknown fields */
340 ICOM_VFIELD(IDirectSound3DBuffer
);
342 /* IDirectSound3DBufferImpl fields */
343 IDirectSoundBufferImpl
* dsb
;
346 HRESULT WINAPI
IDirectSound3DBufferImpl_Create(
347 IDirectSoundBufferImpl
*dsb
,
348 IDirectSound3DBufferImpl
**pds3db
);
350 /*******************************************************************************
351 * DirectSound ClassFactory implementation structure
353 struct IClassFactoryImpl
355 /* IUnknown fields */
356 ICOM_VFIELD(IClassFactory
);
360 extern IClassFactoryImpl DSOUND_CAPTURE_CF
;
361 extern IClassFactoryImpl DSOUND_FULLDUPLEX_CF
;
363 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan
);
364 void DSOUND_RecalcFormat(IDirectSoundBufferImpl
*dsb
);
368 HRESULT
DSOUND_PrimaryCreate(IDirectSoundImpl
*This
);
369 HRESULT
DSOUND_PrimaryDestroy(IDirectSoundImpl
*This
);
370 HRESULT
DSOUND_PrimaryPlay(IDirectSoundImpl
*This
);
371 HRESULT
DSOUND_PrimaryStop(IDirectSoundImpl
*This
);
372 HRESULT
DSOUND_PrimaryGetPosition(IDirectSoundImpl
*This
, LPDWORD playpos
, LPDWORD writepos
);
376 DWORD
DSOUND_CalcPlayPosition(IDirectSoundBufferImpl
*This
,
377 DWORD state
, DWORD pplay
, DWORD pwrite
, DWORD pmix
, DWORD bmix
);
381 void DSOUND_CheckEvent(IDirectSoundBufferImpl
*dsb
, int len
);
382 void DSOUND_ForceRemix(IDirectSoundBufferImpl
*dsb
);
383 void DSOUND_MixCancelAt(IDirectSoundBufferImpl
*dsb
, DWORD buf_writepos
);
384 void DSOUND_WaveQueue(IDirectSoundImpl
*dsound
, DWORD mixq
);
385 void DSOUND_PerformMix(IDirectSoundImpl
*dsound
);
386 void CALLBACK
DSOUND_timer(UINT timerID
, UINT msg
, DWORD dwUser
, DWORD dw1
, DWORD dw2
);
387 void CALLBACK
DSOUND_callback(HWAVEOUT hwo
, UINT msg
, DWORD dwUser
, DWORD dw1
, DWORD dw2
);
391 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl
*dsb
);
393 #define STATE_STOPPED 0
394 #define STATE_STARTING 1
395 #define STATE_PLAYING 2
396 #define STATE_CAPTURING 2
397 #define STATE_STOPPING 3
399 #define DSOUND_FREQSHIFT (14)
401 extern IDirectSoundImpl
* dsound
;
403 extern HRESULT
mmErr(UINT err
);
404 extern void setup_dsound_options(void);