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 #define DS_MAX_CHANNELS 6
35 extern int ds_hel_buflen DECLSPEC_HIDDEN
;
36 extern int ds_snd_queue_max DECLSPEC_HIDDEN
;
38 /*****************************************************************************
39 * Predeclare the interface implementation structures
41 typedef struct IDirectSoundBufferImpl IDirectSoundBufferImpl
;
42 typedef struct DirectSoundDevice DirectSoundDevice
;
44 /* dsound_convert.h */
45 typedef float (*bitsgetfunc
)(const IDirectSoundBufferImpl
*, DWORD
, DWORD
);
46 typedef void (*bitsputfunc
)(const IDirectSoundBufferImpl
*, DWORD
, DWORD
, float);
47 extern const bitsgetfunc getbpp
[5] DECLSPEC_HIDDEN
;
48 void putieee32(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
) DECLSPEC_HIDDEN
;
49 void mixieee32(float *src
, float *dst
, unsigned samples
) DECLSPEC_HIDDEN
;
50 typedef void (*normfunc
)(const void *, void *, unsigned);
51 extern const normfunc normfunctions
[5] DECLSPEC_HIDDEN
;
53 typedef struct _DSVOLUMEPAN
55 DWORD dwTotalAmpFactor
[DS_MAX_CHANNELS
];
58 } DSVOLUMEPAN
,*PDSVOLUMEPAN
;
60 /*****************************************************************************
61 * IDirectSoundDevice implementation structure
63 struct DirectSoundDevice
69 DWORD priolevel
, sleeptime
;
70 PWAVEFORMATEX pwfx
, primary_pwfx
;
71 UINT playing_offs_bytes
, in_mmdev_bytes
, prebuf
;
74 DWORD writelead
, buflen
, state
, playpos
, mixpos
;
76 IDirectSoundBufferImpl
** buffers
;
77 RTL_RWLOCK buffer_list_lock
;
78 CRITICAL_SECTION mixlock
;
79 IDirectSoundBufferImpl
*primary
;
81 float speaker_angles
[DS_MAX_CHANNELS
];
82 int speaker_num
[DS_MAX_CHANNELS
];
85 float *mix_buffer
, *tmp_buffer
;
86 DWORD tmp_buffer_len
, mix_buffer_len
;
90 normfunc normfunction
;
92 /* DirectSound3DListener fields */
94 BOOL ds3dl_need_recalc
;
99 IAudioStreamVolume
*volume
;
100 IAudioRenderClient
*render
;
102 HANDLE sleepev
, thread
;
106 /* reference counted buffer memory for duplicated buffer memory */
107 typedef struct BufferMemory
114 HRESULT
DirectSoundDevice_AddBuffer(
115 DirectSoundDevice
* device
,
116 IDirectSoundBufferImpl
* pDSB
) DECLSPEC_HIDDEN
;
117 void DirectSoundDevice_RemoveBuffer(DirectSoundDevice
* device
, IDirectSoundBufferImpl
* pDSB
) DECLSPEC_HIDDEN
;
119 /*****************************************************************************
120 * IDirectSoundBuffer implementation structure
122 struct IDirectSoundBufferImpl
124 IDirectSoundBuffer8 IDirectSoundBuffer8_iface
;
125 IDirectSoundNotify IDirectSoundNotify_iface
;
126 IDirectSound3DListener IDirectSound3DListener_iface
; /* only primary buffer */
127 IDirectSound3DBuffer IDirectSound3DBuffer_iface
; /* only secondary buffer */
128 IKsPropertySet IKsPropertySet_iface
;
129 LONG numIfaces
; /* "in use interfaces" refcount */
130 LONG ref
, refn
, ref3D
, refiks
;
131 /* IDirectSoundBufferImpl fields */
132 DirectSoundDevice
* device
;
135 BufferMemory
* buffer
;
136 DWORD playflags
,state
,leadin
;
137 DWORD writelead
,buflen
;
138 DWORD nAvgBytesPerSec
;
142 /* used for frequency conversion (PerfectPitch) */
146 LONG64 freqAdjustNum
,freqAdjustDen
;
148 /* used for mixing */
151 /* IDirectSoundNotify fields */
152 LPDSBPOSITIONNOTIFY notifies
;
154 /* DirectSound3DBuffer fields */
155 DS3DBUFFER ds3db_ds3db
;
157 BOOL ds3db_need_recalc
;
158 /* Used for bit depth conversion */
160 bitsgetfunc get
, get_aux
;
161 bitsputfunc put
, put_aux
;
166 float get_mono(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
) DECLSPEC_HIDDEN
;
167 void put_mono2stereo(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
) DECLSPEC_HIDDEN
;
168 void put_mono2quad(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
) DECLSPEC_HIDDEN
;
169 void put_stereo2quad(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
) DECLSPEC_HIDDEN
;
170 void put_mono2surround51(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
) DECLSPEC_HIDDEN
;
171 void put_stereo2surround51(const IDirectSoundBufferImpl
*dsb
, DWORD pos
, DWORD channel
, float value
) DECLSPEC_HIDDEN
;
173 HRESULT
IDirectSoundBufferImpl_Create(
174 DirectSoundDevice
*device
,
175 IDirectSoundBufferImpl
**ppdsb
,
176 LPCDSBUFFERDESC dsbd
) DECLSPEC_HIDDEN
;
177 HRESULT
IDirectSoundBufferImpl_Duplicate(
178 DirectSoundDevice
*device
,
179 IDirectSoundBufferImpl
**ppdsb
,
180 IDirectSoundBufferImpl
*pdsb
) DECLSPEC_HIDDEN
;
181 void secondarybuffer_destroy(IDirectSoundBufferImpl
*This
) DECLSPEC_HIDDEN
;
182 const IDirectSound3DListenerVtbl ds3dlvt DECLSPEC_HIDDEN
;
183 const IDirectSound3DBufferVtbl ds3dbvt DECLSPEC_HIDDEN
;
184 const IKsPropertySetVtbl iksbvt DECLSPEC_HIDDEN
;
186 HRESULT
IKsPrivatePropertySetImpl_Create(REFIID riid
, void **ppv
) DECLSPEC_HIDDEN
;
188 /*******************************************************************************
193 HRESULT
DSOUND_Create(REFIID riid
, void **ppv
) DECLSPEC_HIDDEN
;
194 HRESULT
DSOUND_Create8(REFIID riid
, void **ppv
) DECLSPEC_HIDDEN
;
195 HRESULT
IDirectSoundImpl_Create(IUnknown
*outer_unk
, REFIID riid
, void **ppv
, BOOL has_ds8
) DECLSPEC_HIDDEN
;
196 void DSOUND_ParseSpeakerConfig(DirectSoundDevice
*device
) DECLSPEC_HIDDEN
;
200 HRESULT
DSOUND_PrimaryCreate(DirectSoundDevice
*device
) DECLSPEC_HIDDEN
;
201 HRESULT
DSOUND_PrimaryDestroy(DirectSoundDevice
*device
) DECLSPEC_HIDDEN
;
202 HRESULT
DSOUND_PrimaryPlay(DirectSoundDevice
*device
) DECLSPEC_HIDDEN
;
203 HRESULT
DSOUND_PrimaryStop(DirectSoundDevice
*device
) DECLSPEC_HIDDEN
;
204 HRESULT
DSOUND_PrimaryGetPosition(DirectSoundDevice
*device
, LPDWORD playpos
, LPDWORD writepos
) DECLSPEC_HIDDEN
;
205 LPWAVEFORMATEX
DSOUND_CopyFormat(LPCWAVEFORMATEX wfex
) DECLSPEC_HIDDEN
;
206 HRESULT
DSOUND_ReopenDevice(DirectSoundDevice
*device
, BOOL forcewave
) DECLSPEC_HIDDEN
;
207 HRESULT
DSOUND_PrimaryOpen(DirectSoundDevice
*device
) DECLSPEC_HIDDEN
;
208 HRESULT
primarybuffer_create(DirectSoundDevice
*device
, IDirectSoundBufferImpl
**ppdsb
,
209 const DSBUFFERDESC
*dsbd
) DECLSPEC_HIDDEN
;
210 void primarybuffer_destroy(IDirectSoundBufferImpl
*This
) DECLSPEC_HIDDEN
;
211 HRESULT
primarybuffer_SetFormat(DirectSoundDevice
*device
, LPCWAVEFORMATEX wfex
) DECLSPEC_HIDDEN
;
212 LONG
capped_refcount_dec(LONG
*ref
) DECLSPEC_HIDDEN
;
216 HRESULT
DSOUND_FullDuplexCreate(REFIID riid
, void **ppv
) DECLSPEC_HIDDEN
;
219 void DSOUND_CheckEvent(const IDirectSoundBufferImpl
*dsb
, DWORD playpos
, int len
) DECLSPEC_HIDDEN
;
220 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan
) DECLSPEC_HIDDEN
;
221 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan
) DECLSPEC_HIDDEN
;
222 void DSOUND_RecalcFormat(IDirectSoundBufferImpl
*dsb
) DECLSPEC_HIDDEN
;
223 DWORD
DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl
*dsb
, DWORD secpos
, DWORD secmixpos
, float *overshot
) DECLSPEC_HIDDEN
;
225 DWORD CALLBACK
DSOUND_mixthread(void *ptr
) DECLSPEC_HIDDEN
;
229 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl
*dsb
) DECLSPEC_HIDDEN
;
233 HRESULT
DSOUND_CaptureCreate(REFIID riid
, void **ppv
) DECLSPEC_HIDDEN
;
234 HRESULT
DSOUND_CaptureCreate8(REFIID riid
, void **ppv
) DECLSPEC_HIDDEN
;
235 HRESULT
IDirectSoundCaptureImpl_Create(IUnknown
*outer_unk
, REFIID riid
, void **ppv
, BOOL has_dsc8
) DECLSPEC_HIDDEN
;
237 #define STATE_STOPPED 0
238 #define STATE_STARTING 1
239 #define STATE_PLAYING 2
240 #define STATE_CAPTURING 2
241 #define STATE_STOPPING 3
243 extern CRITICAL_SECTION DSOUND_renderers_lock DECLSPEC_HIDDEN
;
244 extern CRITICAL_SECTION DSOUND_capturers_lock DECLSPEC_HIDDEN
;
245 extern struct list DSOUND_capturers DECLSPEC_HIDDEN
;
246 extern struct list DSOUND_renderers DECLSPEC_HIDDEN
;
248 extern GUID DSOUND_renderer_guids
[MAXWAVEDRIVERS
] DECLSPEC_HIDDEN
;
249 extern GUID DSOUND_capture_guids
[MAXWAVEDRIVERS
] DECLSPEC_HIDDEN
;
251 extern WCHAR wine_vxd_drv
[] DECLSPEC_HIDDEN
;
253 void setup_dsound_options(void) DECLSPEC_HIDDEN
;
255 HRESULT
get_mmdevice(EDataFlow flow
, const GUID
*tgt
, IMMDevice
**device
) DECLSPEC_HIDDEN
;
257 BOOL
DSOUND_check_supported(IAudioClient
*client
, DWORD rate
,
258 DWORD depth
, WORD channels
) DECLSPEC_HIDDEN
;
259 HRESULT
enumerate_mmdevices(EDataFlow flow
, GUID
*guids
,
260 LPDSENUMCALLBACKW cb
, void *user
) DECLSPEC_HIDDEN
;