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"
33 #include "wine/list.h"
34 #include "wine/unicode.h"
36 #define DS_MAX_CHANNELS 6
38 extern int ds_hel_buflen DECLSPEC_HIDDEN
;
40 /*****************************************************************************
41 * Predeclare the interface implementation structures
43 typedef struct IDirectSoundBufferImpl IDirectSoundBufferImpl
;
44 typedef struct DirectSoundDevice DirectSoundDevice
;
46 /* dsound_convert.h */
47 typedef float (*bitsgetfunc
)(const IDirectSoundBufferImpl
*, DWORD
, DWORD
);
48 typedef void (*bitsputfunc
)(const IDirectSoundBufferImpl
*, DWORD
, DWORD
, float);
49 extern const bitsgetfunc getbpp
[5] DECLSPEC_HIDDEN
;
50 void putieee32(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
) DECLSPEC_HIDDEN
;
51 void putieee32_sum(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
) DECLSPEC_HIDDEN
;
52 void mixieee32(float *src
, float *dst
, unsigned samples
) DECLSPEC_HIDDEN
;
53 typedef void (*normfunc
)(const void *, void *, unsigned);
54 extern const normfunc normfunctions
[4] DECLSPEC_HIDDEN
;
56 typedef struct _DSVOLUMEPAN
58 DWORD dwTotalAmpFactor
[DS_MAX_CHANNELS
];
61 } DSVOLUMEPAN
,*PDSVOLUMEPAN
;
63 typedef struct DSFilter
{
66 IMediaObjectInPlace
* inplace
;
69 /*****************************************************************************
70 * IDirectSoundDevice implementation structure
72 struct DirectSoundDevice
78 DWORD priolevel
, sleeptime
;
79 PWAVEFORMATEX pwfx
, primary_pwfx
;
81 DWORD writelead
, buflen
, ac_frames
, frag_frames
, playpos
, pad
, stopped
;
83 IDirectSoundBufferImpl
** buffers
;
84 RTL_RWLOCK buffer_list_lock
;
85 CRITICAL_SECTION mixlock
;
86 IDirectSoundBufferImpl
*primary
;
88 float speaker_angles
[DS_MAX_CHANNELS
];
89 int speaker_num
[DS_MAX_CHANNELS
];
92 float *tmp_buffer
, *cp_buffer
;
93 DWORD tmp_buffer_len
, cp_buffer_len
;
97 normfunc normfunction
;
99 /* DirectSound3DListener fields */
101 BOOL ds3dl_need_recalc
;
104 IAudioClient
*client
;
105 IAudioStreamVolume
*volume
;
106 IAudioRenderClient
*render
;
108 HANDLE sleepev
, thread
;
109 HANDLE thread_finished
;
113 /* reference counted buffer memory for duplicated buffer memory */
114 typedef struct BufferMemory
122 HRESULT
DirectSoundDevice_AddBuffer(
123 DirectSoundDevice
* device
,
124 IDirectSoundBufferImpl
* pDSB
) DECLSPEC_HIDDEN
;
125 void DirectSoundDevice_RemoveBuffer(DirectSoundDevice
* device
, IDirectSoundBufferImpl
* pDSB
) DECLSPEC_HIDDEN
;
127 /*****************************************************************************
128 * IDirectSoundBuffer implementation structure
130 struct IDirectSoundBufferImpl
132 IDirectSoundBuffer8 IDirectSoundBuffer8_iface
;
133 IDirectSoundNotify IDirectSoundNotify_iface
;
134 IDirectSound3DListener IDirectSound3DListener_iface
; /* only primary buffer */
135 IDirectSound3DBuffer IDirectSound3DBuffer_iface
; /* only secondary buffer */
136 IKsPropertySet IKsPropertySet_iface
;
137 LONG numIfaces
; /* "in use interfaces" refcount */
138 LONG ref
, refn
, ref3D
, refiks
;
139 /* IDirectSoundBufferImpl fields */
140 DirectSoundDevice
* device
;
143 BufferMemory
* buffer
;
144 DWORD playflags
,state
,leadin
;
145 DWORD writelead
,buflen
;
146 DWORD nAvgBytesPerSec
;
150 /* used for frequency conversion (PerfectPitch) */
154 LONG64 freqAdjustNum
,freqAdjustDen
;
156 /* used for mixing */
159 /* IDirectSoundNotify fields */
160 LPDSBPOSITIONNOTIFY notifies
;
162 /* DirectSound3DBuffer fields */
163 DS3DBUFFER ds3db_ds3db
;
165 BOOL ds3db_need_recalc
;
166 /* Used for bit depth conversion */
168 bitsgetfunc get
, get_aux
;
169 bitsputfunc put
, put_aux
;
176 float get_mono(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
) DECLSPEC_HIDDEN
;
177 void put_mono2stereo(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
) DECLSPEC_HIDDEN
;
178 void put_mono2quad(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
) DECLSPEC_HIDDEN
;
179 void put_stereo2quad(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
) DECLSPEC_HIDDEN
;
180 void put_mono2surround51(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
) DECLSPEC_HIDDEN
;
181 void put_stereo2surround51(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
) DECLSPEC_HIDDEN
;
182 void put_surround512stereo(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
) DECLSPEC_HIDDEN
;
183 void put_quad2stereo(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
) DECLSPEC_HIDDEN
;
185 HRESULT
secondarybuffer_create(DirectSoundDevice
*device
, const DSBUFFERDESC
*dsbd
,
186 IDirectSoundBuffer
**buffer
) DECLSPEC_HIDDEN
;
187 HRESULT
IDirectSoundBufferImpl_Duplicate(
188 DirectSoundDevice
*device
,
189 IDirectSoundBufferImpl
**ppdsb
,
190 IDirectSoundBufferImpl
*pdsb
) DECLSPEC_HIDDEN
;
191 void secondarybuffer_destroy(IDirectSoundBufferImpl
*This
) DECLSPEC_HIDDEN
;
192 const IDirectSound3DListenerVtbl ds3dlvt DECLSPEC_HIDDEN
;
193 const IDirectSound3DBufferVtbl ds3dbvt DECLSPEC_HIDDEN
;
194 const IKsPropertySetVtbl iksbvt DECLSPEC_HIDDEN
;
196 HRESULT
IKsPrivatePropertySetImpl_Create(REFIID riid
, void **ppv
) DECLSPEC_HIDDEN
;
198 /*******************************************************************************
203 HRESULT
DSOUND_Create(REFIID riid
, void **ppv
) DECLSPEC_HIDDEN
;
204 HRESULT
DSOUND_Create8(REFIID riid
, void **ppv
) DECLSPEC_HIDDEN
;
205 HRESULT
IDirectSoundImpl_Create(IUnknown
*outer_unk
, REFIID riid
, void **ppv
, BOOL has_ds8
) DECLSPEC_HIDDEN
;
206 void DSOUND_ParseSpeakerConfig(DirectSoundDevice
*device
) DECLSPEC_HIDDEN
;
210 HRESULT
DSOUND_PrimaryDestroy(DirectSoundDevice
*device
) DECLSPEC_HIDDEN
;
211 HRESULT
DSOUND_PrimaryPlay(DirectSoundDevice
*device
) DECLSPEC_HIDDEN
;
212 HRESULT
DSOUND_PrimaryStop(DirectSoundDevice
*device
) DECLSPEC_HIDDEN
;
213 LPWAVEFORMATEX
DSOUND_CopyFormat(LPCWAVEFORMATEX wfex
) DECLSPEC_HIDDEN
;
214 HRESULT
DSOUND_ReopenDevice(DirectSoundDevice
*device
, BOOL forcewave
) DECLSPEC_HIDDEN
;
215 HRESULT
primarybuffer_create(DirectSoundDevice
*device
, IDirectSoundBufferImpl
**ppdsb
,
216 const DSBUFFERDESC
*dsbd
) DECLSPEC_HIDDEN
;
217 void primarybuffer_destroy(IDirectSoundBufferImpl
*This
) DECLSPEC_HIDDEN
;
218 HRESULT
primarybuffer_SetFormat(DirectSoundDevice
*device
, LPCWAVEFORMATEX wfex
) DECLSPEC_HIDDEN
;
219 LONG
capped_refcount_dec(LONG
*ref
) DECLSPEC_HIDDEN
;
223 HRESULT
DSOUND_FullDuplexCreate(REFIID riid
, void **ppv
) DECLSPEC_HIDDEN
;
226 void DSOUND_CheckEvent(const IDirectSoundBufferImpl
*dsb
, DWORD playpos
, int len
) DECLSPEC_HIDDEN
;
227 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan
) DECLSPEC_HIDDEN
;
228 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan
) DECLSPEC_HIDDEN
;
229 void DSOUND_RecalcFormat(IDirectSoundBufferImpl
*dsb
) DECLSPEC_HIDDEN
;
230 DWORD
DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl
*dsb
, DWORD secpos
, DWORD secmixpos
, float *overshot
) DECLSPEC_HIDDEN
;
232 DWORD CALLBACK
DSOUND_mixthread(void *ptr
) DECLSPEC_HIDDEN
;
236 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl
*dsb
) DECLSPEC_HIDDEN
;
240 HRESULT
DSOUND_CaptureCreate(REFIID riid
, void **ppv
) DECLSPEC_HIDDEN
;
241 HRESULT
DSOUND_CaptureCreate8(REFIID riid
, void **ppv
) DECLSPEC_HIDDEN
;
242 HRESULT
IDirectSoundCaptureImpl_Create(IUnknown
*outer_unk
, REFIID riid
, void **ppv
, BOOL has_dsc8
) DECLSPEC_HIDDEN
;
244 #define STATE_STOPPED 0
245 #define STATE_STARTING 1
246 #define STATE_PLAYING 2
247 #define STATE_CAPTURING 2
248 #define STATE_STOPPING 3
250 extern CRITICAL_SECTION DSOUND_renderers_lock DECLSPEC_HIDDEN
;
251 extern CRITICAL_SECTION DSOUND_capturers_lock DECLSPEC_HIDDEN
;
252 extern struct list DSOUND_capturers DECLSPEC_HIDDEN
;
253 extern struct list DSOUND_renderers DECLSPEC_HIDDEN
;
255 extern GUID DSOUND_renderer_guids
[MAXWAVEDRIVERS
] DECLSPEC_HIDDEN
;
256 extern GUID DSOUND_capture_guids
[MAXWAVEDRIVERS
] DECLSPEC_HIDDEN
;
258 extern const WCHAR wine_vxd_drv
[] DECLSPEC_HIDDEN
;
260 void setup_dsound_options(void) DECLSPEC_HIDDEN
;
262 HRESULT
get_mmdevice(EDataFlow flow
, const GUID
*tgt
, IMMDevice
**device
) DECLSPEC_HIDDEN
;
264 BOOL
DSOUND_check_supported(IAudioClient
*client
, DWORD rate
,
265 DWORD depth
, WORD channels
) DECLSPEC_HIDDEN
;
266 HRESULT
enumerate_mmdevices(EDataFlow flow
, GUID
*guids
,
267 LPDSENUMCALLBACKW cb
, void *user
) DECLSPEC_HIDDEN
;
269 static inline WCHAR
*strdupW( const WCHAR
*str
)
274 if (!str
) return NULL
;
275 size
= (strlenW( str
) + 1) * sizeof(WCHAR
);
276 ret
= HeapAlloc( GetProcessHeap(), 0, size
);
277 if (ret
) memcpy( ret
, str
, size
);