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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 /* Linux does not support better timing than 10ms */
23 #define DS_TIME_RES 2 /* Resolution of multimedia timer */
24 #define DS_TIME_DEL 10 /* Delay of multimedia timer callback, and duration of HEL fragment */
26 #include "wine/list.h"
28 /* direct sound hardware acceleration levels */
29 #define DS_HW_ACCEL_FULL 0 /* default on Windows 98 */
30 #define DS_HW_ACCEL_STANDARD 1 /* default on Windows 2000 */
31 #define DS_HW_ACCEL_BASIC 2
32 #define DS_HW_ACCEL_EMULATION 3
34 extern int ds_emuldriver DECLSPEC_HIDDEN;
35 extern int ds_hel_buflen DECLSPEC_HIDDEN;
36 extern int ds_snd_queue_max DECLSPEC_HIDDEN;
37 extern int ds_snd_queue_min DECLSPEC_HIDDEN;
38 extern int ds_snd_shadow_maxsize DECLSPEC_HIDDEN;
39 extern int ds_hw_accel DECLSPEC_HIDDEN;
40 extern int ds_default_sample_rate DECLSPEC_HIDDEN;
41 extern int ds_default_bits_per_sample DECLSPEC_HIDDEN;
43 /*****************************************************************************
44 * Predeclare the interface implementation structures
46 typedef struct IDirectSoundImpl IDirectSoundImpl;
47 typedef struct IDirectSound_IUnknown IDirectSound_IUnknown;
48 typedef struct IDirectSound_IDirectSound IDirectSound_IDirectSound;
49 typedef struct IDirectSound8_IUnknown IDirectSound8_IUnknown;
50 typedef struct IDirectSound8_IDirectSound IDirectSound8_IDirectSound;
51 typedef struct IDirectSound8_IDirectSound8 IDirectSound8_IDirectSound8;
52 typedef struct IDirectSoundBufferImpl IDirectSoundBufferImpl;
53 typedef struct IDirectSoundCaptureImpl IDirectSoundCaptureImpl;
54 typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl;
55 typedef struct IDirectSoundNotifyImpl IDirectSoundNotifyImpl;
56 typedef struct IDirectSoundCaptureNotifyImpl IDirectSoundCaptureNotifyImpl;
57 typedef struct IDirectSound3DListenerImpl IDirectSound3DListenerImpl;
58 typedef struct IDirectSound3DBufferImpl IDirectSound3DBufferImpl;
59 typedef struct IKsBufferPropertySetImpl IKsBufferPropertySetImpl;
60 typedef struct PrimaryBufferImpl PrimaryBufferImpl;
61 typedef struct DirectSoundDevice DirectSoundDevice;
62 typedef struct DirectSoundCaptureDevice DirectSoundCaptureDevice;
64 /* dsound_convert.h */
65 typedef void (*bitsconvertfunc)(const void *, void *, UINT, UINT, INT, UINT, UINT);
66 extern const bitsconvertfunc convertbpp[5][4] DECLSPEC_HIDDEN;
67 typedef void (*mixfunc)(const void *, void *, unsigned);
68 extern const mixfunc mixfunctions[4] DECLSPEC_HIDDEN;
69 typedef void (*normfunc)(const void *, void *, unsigned);
70 extern const normfunc normfunctions[4] DECLSPEC_HIDDEN;
72 /*****************************************************************************
73 * IDirectSoundDevice implementation structure
75 struct DirectSoundDevice
87 UINT timerID, pwplay, pwqueue, prebuf, helfrags;
89 PIDSDRIVERBUFFER hwbuf;
91 DWORD writelead, buflen, state, playpos, mixpos;
93 IDirectSoundBufferImpl** buffers;
94 RTL_RWLOCK buffer_list_lock;
95 CRITICAL_SECTION mixlock;
96 PrimaryBufferImpl* primary;
99 LPBYTE tmp_buffer, mix_buffer;
100 DWORD tmp_buffer_len, mix_buffer_len;
105 normfunc normfunction;
107 /* DirectSound3DListener fields */
108 IDirectSound3DListenerImpl* listener;
110 BOOL ds3dl_need_recalc;
113 /* reference counted buffer memory for duplicated buffer memory */
114 typedef struct BufferMemory
121 ULONG DirectSoundDevice_Release(DirectSoundDevice * device) DECLSPEC_HIDDEN;
122 HRESULT DirectSoundDevice_Initialize(
123 DirectSoundDevice ** ppDevice,
124 LPCGUID lpcGUID) DECLSPEC_HIDDEN;
125 HRESULT DirectSoundDevice_AddBuffer(
126 DirectSoundDevice * device,
127 IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
128 HRESULT DirectSoundDevice_RemoveBuffer(
129 DirectSoundDevice * device,
130 IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
131 HRESULT DirectSoundDevice_GetCaps(DirectSoundDevice * device, LPDSCAPS lpDSCaps) DECLSPEC_HIDDEN;
132 HRESULT DirectSoundDevice_CreateSoundBuffer(
133 DirectSoundDevice * device,
134 LPCDSBUFFERDESC dsbd,
135 LPLPDIRECTSOUNDBUFFER ppdsb,
137 BOOL from8) DECLSPEC_HIDDEN;
138 HRESULT DirectSoundDevice_DuplicateSoundBuffer(
139 DirectSoundDevice * device,
140 LPDIRECTSOUNDBUFFER psb,
141 LPLPDIRECTSOUNDBUFFER ppdsb) DECLSPEC_HIDDEN;
142 HRESULT DirectSoundDevice_SetCooperativeLevel(
143 DirectSoundDevice * devcie,
145 DWORD level) DECLSPEC_HIDDEN;
146 HRESULT DirectSoundDevice_Compact(DirectSoundDevice * device) DECLSPEC_HIDDEN;
147 HRESULT DirectSoundDevice_GetSpeakerConfig(
148 DirectSoundDevice * device,
149 LPDWORD lpdwSpeakerConfig) DECLSPEC_HIDDEN;
150 HRESULT DirectSoundDevice_SetSpeakerConfig(
151 DirectSoundDevice * device,
152 DWORD config) DECLSPEC_HIDDEN;
153 HRESULT DirectSoundDevice_VerifyCertification(DirectSoundDevice * device,
154 LPDWORD pdwCertified) DECLSPEC_HIDDEN;
156 /*****************************************************************************
157 * IDirectSoundBuffer implementation structure
159 struct IDirectSoundBufferImpl
161 IDirectSoundBuffer8 IDirectSoundBuffer8_iface;
162 LONG numIfaces; /* "in use interfaces" refcount */
164 /* IDirectSoundBufferImpl fields */
165 DirectSoundDevice* device;
167 PIDSDRIVERBUFFER hwbuf;
169 BufferMemory* buffer;
171 DWORD playflags,state,leadin;
172 DWORD writelead,buflen;
173 DWORD nAvgBytesPerSec;
174 DWORD freq, tmp_buffer_len, max_buffer_len;
177 /* used for frequency conversion (PerfectPitch) */
178 ULONG freqneeded, freqAdjust, freqAcc, freqAccNext, resampleinmixer;
179 /* used for mixing */
180 DWORD primary_mixpos, buf_mixpos, sec_mixpos;
182 /* IDirectSoundNotifyImpl fields */
183 IDirectSoundNotifyImpl* notify;
184 LPDSBPOSITIONNOTIFY notifies;
186 PIDSDRIVERNOTIFY hwnotify;
188 /* DirectSound3DBuffer fields */
189 IDirectSound3DBufferImpl* ds3db;
190 DS3DBUFFER ds3db_ds3db;
192 BOOL ds3db_need_recalc;
194 /* IKsPropertySet fields */
195 IKsBufferPropertySetImpl* iks;
196 bitsconvertfunc convert;
200 HRESULT IDirectSoundBufferImpl_Create(
201 DirectSoundDevice *device,
202 IDirectSoundBufferImpl **ppdsb,
203 LPCDSBUFFERDESC dsbd) DECLSPEC_HIDDEN;
204 HRESULT IDirectSoundBufferImpl_Destroy(
205 IDirectSoundBufferImpl *pdsb) DECLSPEC_HIDDEN;
206 HRESULT IDirectSoundBufferImpl_Duplicate(
207 DirectSoundDevice *device,
208 IDirectSoundBufferImpl **ppdsb,
209 IDirectSoundBufferImpl *pdsb) DECLSPEC_HIDDEN;
210 void secondarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
212 /*****************************************************************************
213 * PrimaryBuffer implementation structure
215 struct PrimaryBufferImpl
217 const IDirectSoundBufferVtbl *lpVtbl;
219 DirectSoundDevice* device;
222 HRESULT PrimaryBufferImpl_Create(
223 DirectSoundDevice * device,
224 PrimaryBufferImpl **ppdsb,
225 LPCDSBUFFERDESC dsbd) DECLSPEC_HIDDEN;
227 /*****************************************************************************
228 * DirectSoundCaptureDevice implementation structure
230 struct DirectSoundCaptureDevice
232 /* IDirectSoundCaptureImpl fields */
236 /* DirectSound driver stuff */
238 DSDRIVERDESC drvdesc;
239 DSCDRIVERCAPS drvcaps;
240 PIDSCDRIVERBUFFER hwbuf;
242 /* wave driver info */
251 IDirectSoundCaptureBufferImpl* capture_buffer;
256 CRITICAL_SECTION lock;
259 /*****************************************************************************
260 * IDirectSoundCaptureBuffer implementation structure
262 struct IDirectSoundCaptureBufferImpl
264 /* IUnknown fields */
265 const IDirectSoundCaptureBuffer8Vtbl *lpVtbl;
268 /* IDirectSoundCaptureBufferImpl fields */
269 DirectSoundCaptureDevice* device;
270 /* FIXME: don't need this */
271 LPDSCBUFFERDESC pdscbd;
274 /* IDirectSoundCaptureNotifyImpl fields */
275 IDirectSoundCaptureNotifyImpl* notify;
276 LPDSBPOSITIONNOTIFY notifies;
278 PIDSDRIVERNOTIFY hwnotify;
281 /*****************************************************************************
282 * IDirectSound3DListener implementation structure
284 struct IDirectSound3DListenerImpl
286 /* IUnknown fields */
287 const IDirectSound3DListenerVtbl *lpVtbl;
289 /* IDirectSound3DListenerImpl fields */
290 DirectSoundDevice* device;
293 HRESULT IDirectSound3DListenerImpl_Create(
294 DirectSoundDevice *device,
295 IDirectSound3DListenerImpl **pdsl) DECLSPEC_HIDDEN;
297 /*****************************************************************************
298 * IKsBufferPropertySet implementation structure
300 struct IKsBufferPropertySetImpl
302 /* IUnknown fields */
303 const IKsPropertySetVtbl *lpVtbl;
305 /* IKsPropertySetImpl fields */
306 IDirectSoundBufferImpl* dsb;
309 HRESULT IKsBufferPropertySetImpl_Create(
310 IDirectSoundBufferImpl *dsb,
311 IKsBufferPropertySetImpl **piks) DECLSPEC_HIDDEN;
312 HRESULT IKsBufferPropertySetImpl_Destroy(
313 IKsBufferPropertySetImpl *piks) DECLSPEC_HIDDEN;
315 HRESULT IKsPrivatePropertySetImpl_Create(REFIID riid, IKsPropertySet **piks) DECLSPEC_HIDDEN;
317 /*****************************************************************************
318 * IDirectSound3DBuffer implementation structure
320 struct IDirectSound3DBufferImpl
322 /* IUnknown fields */
323 const IDirectSound3DBufferVtbl *lpVtbl;
325 /* IDirectSound3DBufferImpl fields */
326 IDirectSoundBufferImpl* dsb;
329 HRESULT IDirectSound3DBufferImpl_Create(
330 IDirectSoundBufferImpl *dsb,
331 IDirectSound3DBufferImpl **pds3db) DECLSPEC_HIDDEN;
332 HRESULT IDirectSound3DBufferImpl_Destroy(
333 IDirectSound3DBufferImpl *pds3db) DECLSPEC_HIDDEN;
335 /*******************************************************************************
340 HRESULT DSOUND_Create(REFIID riid, LPDIRECTSOUND *ppDS) DECLSPEC_HIDDEN;
341 HRESULT DSOUND_Create8(REFIID riid, LPDIRECTSOUND8 *ppDS) DECLSPEC_HIDDEN;
345 DWORD DSOUND_fraglen(DWORD nSamplesPerSec, DWORD nBlockAlign) DECLSPEC_HIDDEN;
346 HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device) DECLSPEC_HIDDEN;
347 HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device) DECLSPEC_HIDDEN;
348 HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device) DECLSPEC_HIDDEN;
349 HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device) DECLSPEC_HIDDEN;
350 HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos) DECLSPEC_HIDDEN;
351 LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
352 HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) DECLSPEC_HIDDEN;
356 HRESULT DSOUND_FullDuplexCreate(REFIID riid, LPDIRECTSOUNDFULLDUPLEX* ppDSFD) DECLSPEC_HIDDEN;
359 DWORD DSOUND_bufpos_to_mixpos(const DirectSoundDevice* device, DWORD pos) DECLSPEC_HIDDEN;
360 void DSOUND_CheckEvent(const IDirectSoundBufferImpl *dsb, DWORD playpos, int len) DECLSPEC_HIDDEN;
361 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
362 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
363 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
364 void DSOUND_MixToTemporary(const IDirectSoundBufferImpl *dsb, DWORD writepos, DWORD mixlen, BOOL inmixer) DECLSPEC_HIDDEN;
365 DWORD DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl *dsb, DWORD secpos, DWORD secmixpos, DWORD* overshot) DECLSPEC_HIDDEN;
367 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) DECLSPEC_HIDDEN;
368 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) DECLSPEC_HIDDEN;
372 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
376 HRESULT DSOUND_CaptureCreate(REFIID riid, LPDIRECTSOUNDCAPTURE *ppDSC) DECLSPEC_HIDDEN;
377 HRESULT DSOUND_CaptureCreate8(REFIID riid, LPDIRECTSOUNDCAPTURE8 *ppDSC8) DECLSPEC_HIDDEN;
379 #define STATE_STOPPED 0
380 #define STATE_STARTING 1
381 #define STATE_PLAYING 2
382 #define STATE_CAPTURING 2
383 #define STATE_STOPPING 3
385 #define DSOUND_FREQSHIFT (20)
387 extern DirectSoundDevice* DSOUND_renderer[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
388 extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
390 extern DirectSoundCaptureDevice * DSOUND_capture[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
391 extern GUID DSOUND_capture_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
393 HRESULT mmErr(UINT err) DECLSPEC_HIDDEN;
394 void setup_dsound_options(void) DECLSPEC_HIDDEN;
395 const char * dumpCooperativeLevel(DWORD level) DECLSPEC_HIDDEN;