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 */
27 #include "mmdeviceapi.h"
28 #include "audioclient.h"
31 #include "wine/list.h"
33 extern int ds_hel_buflen DECLSPEC_HIDDEN
;
34 extern int ds_snd_queue_max DECLSPEC_HIDDEN
;
35 extern int ds_snd_shadow_maxsize DECLSPEC_HIDDEN
;
36 extern int ds_default_sample_rate DECLSPEC_HIDDEN
;
37 extern int ds_default_bits_per_sample DECLSPEC_HIDDEN
;
39 /*****************************************************************************
40 * Predeclare the interface implementation structures
42 typedef struct IDirectSound_IDirectSound IDirectSound_IDirectSound
;
43 typedef struct IDirectSound8_IDirectSound8 IDirectSound8_IDirectSound8
;
44 typedef struct IDirectSoundBufferImpl IDirectSoundBufferImpl
;
45 typedef struct IDirectSoundCaptureImpl IDirectSoundCaptureImpl
;
46 typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl
;
47 typedef struct DirectSoundDevice DirectSoundDevice
;
48 typedef struct DirectSoundCaptureDevice DirectSoundCaptureDevice
;
50 /* dsound_convert.h */
51 typedef float (*bitsgetfunc
)(const IDirectSoundBufferImpl
*, DWORD
, DWORD
);
52 typedef void (*bitsputfunc
)(const IDirectSoundBufferImpl
*, DWORD
, DWORD
, float);
53 extern const bitsgetfunc getbpp
[5] DECLSPEC_HIDDEN
;
54 void putieee32(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
) DECLSPEC_HIDDEN
;
55 void mixieee32(float *src
, float *dst
, unsigned samples
) DECLSPEC_HIDDEN
;
56 typedef void (*normfunc
)(const void *, void *, unsigned);
57 extern const normfunc normfunctions
[5] DECLSPEC_HIDDEN
;
59 typedef struct _DSVOLUMEPAN
61 DWORD dwTotalLeftAmpFactor
;
62 DWORD dwTotalRightAmpFactor
;
66 DWORD dwPanLeftAmpFactor
;
67 DWORD dwPanRightAmpFactor
;
68 } DSVOLUMEPAN
,*PDSVOLUMEPAN
;
70 /*****************************************************************************
71 * IDirectSoundDevice implementation structure
73 struct DirectSoundDevice
81 UINT timerID
, playing_offs_bytes
, in_mmdev_bytes
, prebuf
, helfrags
;
84 DWORD writelead
, buflen
, state
, playpos
, mixpos
;
86 IDirectSoundBufferImpl
** buffers
;
87 RTL_RWLOCK buffer_list_lock
;
88 CRITICAL_SECTION mixlock
;
89 IDirectSoundBufferImpl
*primary
;
91 float *mix_buffer
, *tmp_buffer
;
92 DWORD tmp_buffer_len
, mix_buffer_len
;
96 normfunc normfunction
;
98 /* DirectSound3DListener fields */
100 BOOL ds3dl_need_recalc
;
103 IAudioClient
*client
;
105 IAudioStreamVolume
*volume
;
106 IAudioRenderClient
*render
;
111 /* reference counted buffer memory for duplicated buffer memory */
112 typedef struct BufferMemory
119 ULONG
DirectSoundDevice_Release(DirectSoundDevice
* device
) DECLSPEC_HIDDEN
;
120 HRESULT
DirectSoundDevice_Initialize(
121 DirectSoundDevice
** ppDevice
,
122 LPCGUID lpcGUID
) DECLSPEC_HIDDEN
;
123 HRESULT
DirectSoundDevice_AddBuffer(
124 DirectSoundDevice
* device
,
125 IDirectSoundBufferImpl
* pDSB
) DECLSPEC_HIDDEN
;
126 HRESULT
DirectSoundDevice_RemoveBuffer(
127 DirectSoundDevice
* device
,
128 IDirectSoundBufferImpl
* pDSB
) DECLSPEC_HIDDEN
;
129 HRESULT
DirectSoundDevice_GetCaps(DirectSoundDevice
* device
, LPDSCAPS lpDSCaps
) DECLSPEC_HIDDEN
;
130 HRESULT
DirectSoundDevice_CreateSoundBuffer(
131 DirectSoundDevice
* device
,
132 LPCDSBUFFERDESC dsbd
,
133 LPLPDIRECTSOUNDBUFFER ppdsb
,
135 BOOL from8
) DECLSPEC_HIDDEN
;
136 HRESULT
DirectSoundDevice_DuplicateSoundBuffer(
137 DirectSoundDevice
* device
,
138 LPDIRECTSOUNDBUFFER psb
,
139 LPLPDIRECTSOUNDBUFFER ppdsb
) DECLSPEC_HIDDEN
;
140 HRESULT
DirectSoundDevice_SetCooperativeLevel(
141 DirectSoundDevice
* devcie
,
143 DWORD level
) DECLSPEC_HIDDEN
;
144 HRESULT
DirectSoundDevice_Compact(DirectSoundDevice
* device
) DECLSPEC_HIDDEN
;
145 HRESULT
DirectSoundDevice_GetSpeakerConfig(
146 DirectSoundDevice
* device
,
147 LPDWORD lpdwSpeakerConfig
) DECLSPEC_HIDDEN
;
148 HRESULT
DirectSoundDevice_SetSpeakerConfig(
149 DirectSoundDevice
* device
,
150 DWORD config
) DECLSPEC_HIDDEN
;
151 HRESULT
DirectSoundDevice_VerifyCertification(DirectSoundDevice
* device
,
152 LPDWORD pdwCertified
) DECLSPEC_HIDDEN
;
154 /*****************************************************************************
155 * IDirectSoundBuffer implementation structure
157 struct IDirectSoundBufferImpl
159 IDirectSoundBuffer8 IDirectSoundBuffer8_iface
;
160 IDirectSoundNotify IDirectSoundNotify_iface
;
161 IDirectSound3DListener IDirectSound3DListener_iface
; /* only primary buffer */
162 IDirectSound3DBuffer IDirectSound3DBuffer_iface
; /* only secondary buffer */
163 IKsPropertySet IKsPropertySet_iface
;
164 LONG numIfaces
; /* "in use interfaces" refcount */
165 LONG ref
, refn
, ref3D
, refiks
;
166 /* IDirectSoundBufferImpl fields */
167 DirectSoundDevice
* device
;
170 BufferMemory
* buffer
;
171 DWORD playflags
,state
,leadin
;
172 DWORD writelead
,buflen
;
173 DWORD nAvgBytesPerSec
;
177 /* used for frequency conversion (PerfectPitch) */
180 float freqAcc
, freqAdjust
, firgain
;
181 /* used for mixing */
184 /* IDirectSoundNotify fields */
185 LPDSBPOSITIONNOTIFY notifies
;
187 /* DirectSound3DBuffer fields */
188 DS3DBUFFER ds3db_ds3db
;
190 BOOL ds3db_need_recalc
;
191 /* Used for bit depth conversion */
193 bitsgetfunc get
, get_aux
;
194 bitsputfunc put
, put_aux
;
199 float get_mono(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
) DECLSPEC_HIDDEN
;
200 void put_mono2stereo(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
) DECLSPEC_HIDDEN
;
202 HRESULT
IDirectSoundBufferImpl_Create(
203 DirectSoundDevice
*device
,
204 IDirectSoundBufferImpl
**ppdsb
,
205 LPCDSBUFFERDESC dsbd
) 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
;
211 const IDirectSound3DListenerVtbl ds3dlvt DECLSPEC_HIDDEN
;
212 const IDirectSound3DBufferVtbl ds3dbvt DECLSPEC_HIDDEN
;
213 const IKsPropertySetVtbl iksbvt DECLSPEC_HIDDEN
;
215 /*****************************************************************************
216 * DirectSoundCaptureDevice implementation structure
218 struct DirectSoundCaptureDevice
226 DWORD buflen
, write_pos_bytes
;
230 IDirectSoundCaptureBufferImpl
* capture_buffer
;
233 CRITICAL_SECTION lock
;
236 IAudioClient
*client
;
237 IAudioCaptureClient
*capture
;
242 /*****************************************************************************
243 * IDirectSoundCaptureBuffer implementation structure
245 struct IDirectSoundCaptureBufferImpl
247 IDirectSoundCaptureBuffer8 IDirectSoundCaptureBuffer8_iface
;
248 IDirectSoundNotify IDirectSoundNotify_iface
;
249 LONG numIfaces
; /* "in use interfaces" refcount */
251 /* IDirectSoundCaptureBuffer fields */
252 DirectSoundCaptureDevice
* device
;
253 LPDSCBUFFERDESC pdscbd
;
255 /* IDirectSoundNotify fields */
256 LPDSBPOSITIONNOTIFY notifies
;
260 HRESULT
IKsPrivatePropertySetImpl_Create(REFIID riid
, IKsPropertySet
**piks
) DECLSPEC_HIDDEN
;
262 /*******************************************************************************
267 HRESULT
DSOUND_Create(REFIID riid
, void **ppv
) DECLSPEC_HIDDEN
;
268 HRESULT
DSOUND_Create8(REFIID riid
, void **ppv
) DECLSPEC_HIDDEN
;
272 HRESULT
DSOUND_PrimaryCreate(DirectSoundDevice
*device
) DECLSPEC_HIDDEN
;
273 HRESULT
DSOUND_PrimaryDestroy(DirectSoundDevice
*device
) DECLSPEC_HIDDEN
;
274 HRESULT
DSOUND_PrimaryPlay(DirectSoundDevice
*device
) DECLSPEC_HIDDEN
;
275 HRESULT
DSOUND_PrimaryStop(DirectSoundDevice
*device
) DECLSPEC_HIDDEN
;
276 HRESULT
DSOUND_PrimaryGetPosition(DirectSoundDevice
*device
, LPDWORD playpos
, LPDWORD writepos
) DECLSPEC_HIDDEN
;
277 LPWAVEFORMATEX
DSOUND_CopyFormat(LPCWAVEFORMATEX wfex
) DECLSPEC_HIDDEN
;
278 HRESULT
DSOUND_ReopenDevice(DirectSoundDevice
*device
, BOOL forcewave
) DECLSPEC_HIDDEN
;
279 HRESULT
primarybuffer_create(DirectSoundDevice
*device
, IDirectSoundBufferImpl
**ppdsb
,
280 const DSBUFFERDESC
*dsbd
) DECLSPEC_HIDDEN
;
281 void primarybuffer_destroy(IDirectSoundBufferImpl
*This
) DECLSPEC_HIDDEN
;
282 HRESULT
primarybuffer_SetFormat(DirectSoundDevice
*device
, LPCWAVEFORMATEX wfex
) DECLSPEC_HIDDEN
;
283 LONG
capped_refcount_dec(LONG
*ref
) DECLSPEC_HIDDEN
;
287 HRESULT
DSOUND_FullDuplexCreate(REFIID riid
, LPDIRECTSOUNDFULLDUPLEX
* ppDSFD
) DECLSPEC_HIDDEN
;
290 void DSOUND_CheckEvent(const IDirectSoundBufferImpl
*dsb
, DWORD playpos
, int len
) DECLSPEC_HIDDEN
;
291 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan
) DECLSPEC_HIDDEN
;
292 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan
) DECLSPEC_HIDDEN
;
293 void DSOUND_RecalcFormat(IDirectSoundBufferImpl
*dsb
) DECLSPEC_HIDDEN
;
294 DWORD
DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl
*dsb
, DWORD secpos
, DWORD secmixpos
, float *overshot
) DECLSPEC_HIDDEN
;
296 void CALLBACK
DSOUND_timer(UINT timerID
, UINT msg
, DWORD_PTR dwUser
, DWORD_PTR dw1
, DWORD_PTR dw2
) DECLSPEC_HIDDEN
;
300 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl
*dsb
) DECLSPEC_HIDDEN
;
304 HRESULT
DSOUND_CaptureCreate(REFIID riid
, LPDIRECTSOUNDCAPTURE
*ppDSC
) DECLSPEC_HIDDEN
;
305 HRESULT
DSOUND_CaptureCreate8(REFIID riid
, LPDIRECTSOUNDCAPTURE8
*ppDSC8
) DECLSPEC_HIDDEN
;
307 #define STATE_STOPPED 0
308 #define STATE_STARTING 1
309 #define STATE_PLAYING 2
310 #define STATE_CAPTURING 2
311 #define STATE_STOPPING 3
313 extern CRITICAL_SECTION DSOUND_renderers_lock DECLSPEC_HIDDEN
;
314 extern CRITICAL_SECTION DSOUND_capturers_lock DECLSPEC_HIDDEN
;
315 extern struct list DSOUND_capturers DECLSPEC_HIDDEN
;
316 extern struct list DSOUND_renderers DECLSPEC_HIDDEN
;
318 extern GUID DSOUND_renderer_guids
[MAXWAVEDRIVERS
] DECLSPEC_HIDDEN
;
319 extern GUID DSOUND_capture_guids
[MAXWAVEDRIVERS
] DECLSPEC_HIDDEN
;
321 extern WCHAR wine_vxd_drv
[] DECLSPEC_HIDDEN
;
323 void setup_dsound_options(void) DECLSPEC_HIDDEN
;
324 const char * dumpCooperativeLevel(DWORD level
) DECLSPEC_HIDDEN
;
326 HRESULT
get_mmdevice(EDataFlow flow
, const GUID
*tgt
, IMMDevice
**device
) DECLSPEC_HIDDEN
;
328 BOOL
DSOUND_check_supported(IAudioClient
*client
, DWORD rate
,
329 DWORD depth
, WORD channels
) DECLSPEC_HIDDEN
;
330 UINT
DSOUND_create_timer(LPTIMECALLBACK cb
, DWORD_PTR user
) DECLSPEC_HIDDEN
;
331 HRESULT
enumerate_mmdevices(EDataFlow flow
, GUID
*guids
,
332 LPDSENUMCALLBACKW cb
, void *user
) DECLSPEC_HIDDEN
;