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"
35 #define DS_MAX_CHANNELS 6
37 extern int ds_hel_buflen
;
39 /*****************************************************************************
40 * Predeclare the interface implementation structures
42 typedef struct IDirectSoundBufferImpl IDirectSoundBufferImpl
;
43 typedef struct DirectSoundDevice DirectSoundDevice
;
45 /* dsound_convert.h */
46 typedef float (*bitsgetfunc
)(const IDirectSoundBufferImpl
*, BYTE
*, DWORD
);
47 typedef void (*bitsputfunc
)(const IDirectSoundBufferImpl
*, DWORD
, DWORD
, float);
48 extern const bitsgetfunc getbpp
[5];
49 void putieee32(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
);
50 void putieee32_sum(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
);
51 void mixieee32(float *src
, float *dst
, unsigned samples
);
52 typedef void (*normfunc
)(const void *, void *, unsigned);
53 extern const normfunc normfunctions
[4];
55 typedef struct _DSVOLUMEPAN
57 DWORD dwTotalAmpFactor
[DS_MAX_CHANNELS
];
60 } DSVOLUMEPAN
,*PDSVOLUMEPAN
;
62 typedef struct DSFilter
{
65 IMediaObjectInPlace
* inplace
;
68 /*****************************************************************************
69 * IDirectSoundDevice implementation structure
71 struct DirectSoundDevice
77 DWORD priolevel
, sleeptime
;
78 PWAVEFORMATEX pwfx
, primary_pwfx
;
80 DWORD writelead
, buflen
, ac_frames
, frag_frames
, playpos
, pad
, stopped
;
82 IDirectSoundBufferImpl
** buffers
;
83 SRWLOCK buffer_list_lock
;
84 CRITICAL_SECTION mixlock
;
85 IDirectSoundBufferImpl
*primary
;
87 float speaker_angles
[DS_MAX_CHANNELS
];
88 int speaker_num
[DS_MAX_CHANNELS
];
91 float *tmp_buffer
, *cp_buffer
;
92 DWORD tmp_buffer_len
, cp_buffer_len
;
96 normfunc normfunction
;
98 /* DirectSound3DListener fields */
100 BOOL ds3dl_need_recalc
;
103 IAudioClient
*client
;
104 IAudioStreamVolume
*volume
;
105 IAudioRenderClient
*render
;
107 HANDLE sleepev
, thread
;
111 /* reference counted buffer memory for duplicated buffer memory */
112 typedef struct BufferMemory
120 HRESULT
DirectSoundDevice_AddBuffer(
121 DirectSoundDevice
* device
,
122 IDirectSoundBufferImpl
* pDSB
);
123 void DirectSoundDevice_RemoveBuffer(DirectSoundDevice
* device
, IDirectSoundBufferImpl
* pDSB
);
125 /*****************************************************************************
126 * IDirectSoundBuffer implementation structure
128 struct IDirectSoundBufferImpl
130 IDirectSoundBuffer8 IDirectSoundBuffer8_iface
;
131 IDirectSoundNotify IDirectSoundNotify_iface
;
132 IDirectSound3DListener IDirectSound3DListener_iface
; /* only primary buffer */
133 IDirectSound3DBuffer IDirectSound3DBuffer_iface
; /* only secondary buffer */
134 IKsPropertySet IKsPropertySet_iface
;
135 LONG numIfaces
; /* "in use interfaces" refcount */
136 LONG ref
, refn
, ref3D
, refiks
;
137 /* IDirectSoundBufferImpl fields */
138 DirectSoundDevice
* device
;
141 BufferMemory
* buffer
;
142 DWORD playflags
,state
,leadin
;
143 DWORD writelead
,maxwritelead
,buflen
;
147 /* used for frequency conversion (PerfectPitch) */
151 LONG64 freqAdjustNum
,freqAdjustDen
;
153 /* used for mixing */
155 /* Holds a copy of the next 'writelead' bytes, to be used for mixing. This makes it
156 * so that these bytes get played once even if this region of the buffer gets overwritten,
157 * which is more in-line with native DirectSound behavior. */
159 LPVOID committedbuff
;
160 DWORD committed_mixpos
;
161 /* IDirectSoundNotify fields */
162 LPDSBPOSITIONNOTIFY notifies
;
164 /* DirectSound3DBuffer fields */
165 DS3DBUFFER ds3db_ds3db
;
168 BOOL ds3db_need_recalc
;
169 /* Used for bit depth conversion */
171 bitsgetfunc get
, get_aux
;
172 bitsputfunc put
, put_aux
;
179 float get_mono(const IDirectSoundBufferImpl
*dsb
, BYTE
*base
, DWORD channel
);
180 void put_mono2stereo(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
);
181 void put_mono2quad(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
);
182 void put_stereo2quad(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
);
183 void put_mono2surround51(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
);
184 void put_stereo2surround51(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
);
185 void put_surround512stereo(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
);
186 void put_surround712stereo(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
);
187 void put_quad2stereo(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
);
189 HRESULT
secondarybuffer_create(DirectSoundDevice
*device
, const DSBUFFERDESC
*dsbd
,
190 IDirectSoundBuffer
**buffer
);
191 HRESULT
IDirectSoundBufferImpl_Duplicate(
192 DirectSoundDevice
*device
,
193 IDirectSoundBufferImpl
**ppdsb
,
194 IDirectSoundBufferImpl
*pdsb
);
195 void secondarybuffer_destroy(IDirectSoundBufferImpl
*This
);
196 BOOL
secondarybuffer_is_audible(IDirectSoundBufferImpl
*This
);
197 extern const IDirectSound3DListenerVtbl ds3dlvt
;
198 extern const IDirectSound3DBufferVtbl ds3dbvt
;
199 extern const IKsPropertySetVtbl iksbvt
;
201 HRESULT
IKsPrivatePropertySetImpl_Create(REFIID riid
, void **ppv
);
203 /*******************************************************************************
208 HRESULT
DSOUND_Create(REFIID riid
, void **ppv
);
209 HRESULT
DSOUND_Create8(REFIID riid
, void **ppv
);
210 HRESULT
IDirectSoundImpl_Create(IUnknown
*outer_unk
, REFIID riid
, void **ppv
, BOOL has_ds8
);
211 void DSOUND_ParseSpeakerConfig(DirectSoundDevice
*device
);
215 HRESULT
DSOUND_PrimaryDestroy(DirectSoundDevice
*device
);
216 HRESULT
DSOUND_PrimaryPlay(DirectSoundDevice
*device
);
217 HRESULT
DSOUND_PrimaryStop(DirectSoundDevice
*device
);
218 LPWAVEFORMATEX
DSOUND_CopyFormat(LPCWAVEFORMATEX wfex
);
219 HRESULT
DSOUND_ReopenDevice(DirectSoundDevice
*device
, BOOL forcewave
);
220 HRESULT
primarybuffer_create(DirectSoundDevice
*device
, IDirectSoundBufferImpl
**ppdsb
,
221 const DSBUFFERDESC
*dsbd
);
222 void primarybuffer_destroy(IDirectSoundBufferImpl
*This
);
223 HRESULT
primarybuffer_SetFormat(DirectSoundDevice
*device
, LPCWAVEFORMATEX wfex
);
224 LONG
capped_refcount_dec(LONG
*ref
);
228 HRESULT
DSOUND_FullDuplexCreate(REFIID riid
, void **ppv
);
231 void DSOUND_CheckEvent(const IDirectSoundBufferImpl
*dsb
, DWORD playpos
, int len
);
232 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan
);
233 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan
);
234 void DSOUND_RecalcFormat(IDirectSoundBufferImpl
*dsb
);
235 DWORD
DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl
*dsb
, DWORD secpos
, DWORD secmixpos
, float *overshot
);
237 DWORD CALLBACK
DSOUND_mixthread(void *ptr
);
241 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl
*dsb
);
245 HRESULT
DSOUND_CaptureCreate(REFIID riid
, void **ppv
);
246 HRESULT
DSOUND_CaptureCreate8(REFIID riid
, void **ppv
);
247 HRESULT
IDirectSoundCaptureImpl_Create(IUnknown
*outer_unk
, REFIID riid
, void **ppv
, BOOL has_dsc8
);
249 #define STATE_STOPPED 0
250 #define STATE_STARTING 1
251 #define STATE_PLAYING 2
252 #define STATE_CAPTURING 2
253 #define STATE_STOPPING 3
255 extern CRITICAL_SECTION DSOUND_renderers_lock
;
256 extern struct list DSOUND_renderers
;
258 extern const WCHAR wine_vxd_drv
[];
260 void setup_dsound_options(void);
262 HRESULT
get_mmdevice(EDataFlow flow
, const GUID
*tgt
, IMMDevice
**device
);
264 BOOL
DSOUND_check_supported(IAudioClient
*client
, DWORD rate
,
265 DWORD depth
, WORD channels
);
266 HRESULT
enumerate_mmdevices(EDataFlow flow
, LPDSENUMCALLBACKW cb
, void *user
);