dsound: Merge IDirectSound8 into the main DirectSound object.
[wine/multimedia.git] / dlls / dsound / dsound_private.h
blob5892e7ea206ad1f8033403a26fac3ea1f296fd4e
1 /* DirectSound
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 "wingdi.h"
27 #include "mmdeviceapi.h"
28 #include "audioclient.h"
29 #include "mmsystem.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 IDirectSoundBufferImpl IDirectSoundBufferImpl;
44 typedef struct IDirectSoundCaptureImpl IDirectSoundCaptureImpl;
45 typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl;
46 typedef struct DirectSoundDevice DirectSoundDevice;
47 typedef struct DirectSoundCaptureDevice DirectSoundCaptureDevice;
49 /* dsound_convert.h */
50 typedef float (*bitsgetfunc)(const IDirectSoundBufferImpl *, DWORD, DWORD);
51 typedef void (*bitsputfunc)(const IDirectSoundBufferImpl *, DWORD, DWORD, float);
52 extern const bitsgetfunc getbpp[5] DECLSPEC_HIDDEN;
53 void putieee32(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) DECLSPEC_HIDDEN;
54 void mixieee32(float *src, float *dst, unsigned samples) DECLSPEC_HIDDEN;
55 typedef void (*normfunc)(const void *, void *, unsigned);
56 extern const normfunc normfunctions[5] DECLSPEC_HIDDEN;
58 typedef struct _DSVOLUMEPAN
60 DWORD dwTotalLeftAmpFactor;
61 DWORD dwTotalRightAmpFactor;
62 LONG lVolume;
63 DWORD dwVolAmpFactor;
64 LONG lPan;
65 DWORD dwPanLeftAmpFactor;
66 DWORD dwPanRightAmpFactor;
67 } DSVOLUMEPAN,*PDSVOLUMEPAN;
69 /*****************************************************************************
70 * IDirectSoundDevice implementation structure
72 struct DirectSoundDevice
74 LONG ref;
76 GUID guid;
77 DSCAPS drvcaps;
78 DWORD priolevel;
79 PWAVEFORMATEX pwfx;
80 UINT timerID, playing_offs_bytes, in_mmdev_bytes, prebuf, helfrags;
81 DWORD fraglen;
82 LPBYTE buffer;
83 DWORD writelead, buflen, state, playpos, mixpos;
84 int nrofbuffers;
85 IDirectSoundBufferImpl** buffers;
86 RTL_RWLOCK buffer_list_lock;
87 CRITICAL_SECTION mixlock;
88 IDirectSoundBufferImpl *primary;
89 DWORD speaker_config;
90 float *mix_buffer, *tmp_buffer;
91 DWORD tmp_buffer_len, mix_buffer_len;
93 DSVOLUMEPAN volpan;
95 normfunc normfunction;
97 /* DirectSound3DListener fields */
98 DS3DLISTENER ds3dl;
99 BOOL ds3dl_need_recalc;
101 IMMDevice *mmdevice;
102 IAudioClient *client;
103 IAudioClock *clock;
104 IAudioStreamVolume *volume;
105 IAudioRenderClient *render;
107 struct list entry;
110 /* reference counted buffer memory for duplicated buffer memory */
111 typedef struct BufferMemory
113 LONG ref;
114 LPBYTE memory;
115 struct list buffers;
116 } BufferMemory;
118 ULONG DirectSoundDevice_Release(DirectSoundDevice * device) DECLSPEC_HIDDEN;
119 HRESULT DirectSoundDevice_Initialize(
120 DirectSoundDevice ** ppDevice,
121 LPCGUID lpcGUID) DECLSPEC_HIDDEN;
122 HRESULT DirectSoundDevice_AddBuffer(
123 DirectSoundDevice * device,
124 IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
125 HRESULT DirectSoundDevice_RemoveBuffer(
126 DirectSoundDevice * device,
127 IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
128 HRESULT DirectSoundDevice_GetCaps(DirectSoundDevice * device, LPDSCAPS lpDSCaps) DECLSPEC_HIDDEN;
129 HRESULT DirectSoundDevice_CreateSoundBuffer(
130 DirectSoundDevice * device,
131 LPCDSBUFFERDESC dsbd,
132 LPLPDIRECTSOUNDBUFFER ppdsb,
133 LPUNKNOWN lpunk,
134 BOOL from8) DECLSPEC_HIDDEN;
135 HRESULT DirectSoundDevice_DuplicateSoundBuffer(
136 DirectSoundDevice * device,
137 LPDIRECTSOUNDBUFFER psb,
138 LPLPDIRECTSOUNDBUFFER ppdsb) DECLSPEC_HIDDEN;
139 HRESULT DirectSoundDevice_SetCooperativeLevel(
140 DirectSoundDevice * devcie,
141 HWND hwnd,
142 DWORD level) DECLSPEC_HIDDEN;
143 HRESULT DirectSoundDevice_Compact(DirectSoundDevice * device) DECLSPEC_HIDDEN;
144 HRESULT DirectSoundDevice_GetSpeakerConfig(
145 DirectSoundDevice * device,
146 LPDWORD lpdwSpeakerConfig) DECLSPEC_HIDDEN;
147 HRESULT DirectSoundDevice_SetSpeakerConfig(
148 DirectSoundDevice * device,
149 DWORD config) DECLSPEC_HIDDEN;
150 HRESULT DirectSoundDevice_VerifyCertification(DirectSoundDevice * device,
151 LPDWORD pdwCertified) DECLSPEC_HIDDEN;
153 /*****************************************************************************
154 * IDirectSoundBuffer implementation structure
156 struct IDirectSoundBufferImpl
158 IDirectSoundBuffer8 IDirectSoundBuffer8_iface;
159 IDirectSoundNotify IDirectSoundNotify_iface;
160 IDirectSound3DListener IDirectSound3DListener_iface; /* only primary buffer */
161 IDirectSound3DBuffer IDirectSound3DBuffer_iface; /* only secondary buffer */
162 IKsPropertySet IKsPropertySet_iface;
163 LONG numIfaces; /* "in use interfaces" refcount */
164 LONG ref, refn, ref3D, refiks;
165 /* IDirectSoundBufferImpl fields */
166 DirectSoundDevice* device;
167 RTL_RWLOCK lock;
168 PWAVEFORMATEX pwfx;
169 BufferMemory* buffer;
170 DWORD playflags,state,leadin;
171 DWORD writelead,buflen;
172 DWORD nAvgBytesPerSec;
173 DWORD freq;
174 DSVOLUMEPAN volpan;
175 DSBUFFERDESC dsbd;
176 /* used for frequency conversion (PerfectPitch) */
177 ULONG freqneeded;
178 DWORD firstep;
179 float freqAcc, freqAdjust, firgain;
180 /* used for mixing */
181 DWORD sec_mixpos;
183 /* IDirectSoundNotify fields */
184 LPDSBPOSITIONNOTIFY notifies;
185 int nrofnotifies;
186 /* DirectSound3DBuffer fields */
187 DS3DBUFFER ds3db_ds3db;
188 LONG ds3db_lVolume;
189 BOOL ds3db_need_recalc;
190 /* Used for bit depth conversion */
191 int mix_channels;
192 bitsgetfunc get, get_aux;
193 bitsputfunc put, put_aux;
195 struct list entry;
198 float get_mono(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel) DECLSPEC_HIDDEN;
199 void put_mono2stereo(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) DECLSPEC_HIDDEN;
201 HRESULT IDirectSoundBufferImpl_Create(
202 DirectSoundDevice *device,
203 IDirectSoundBufferImpl **ppdsb,
204 LPCDSBUFFERDESC dsbd) DECLSPEC_HIDDEN;
205 HRESULT IDirectSoundBufferImpl_Duplicate(
206 DirectSoundDevice *device,
207 IDirectSoundBufferImpl **ppdsb,
208 IDirectSoundBufferImpl *pdsb) DECLSPEC_HIDDEN;
209 void secondarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
210 const IDirectSound3DListenerVtbl ds3dlvt DECLSPEC_HIDDEN;
211 const IDirectSound3DBufferVtbl ds3dbvt DECLSPEC_HIDDEN;
212 const IKsPropertySetVtbl iksbvt DECLSPEC_HIDDEN;
214 /*****************************************************************************
215 * DirectSoundCaptureDevice implementation structure
217 struct DirectSoundCaptureDevice
219 GUID guid;
220 LONG ref;
222 DSCCAPS drvcaps;
224 LPBYTE buffer;
225 DWORD buflen, write_pos_bytes;
227 PWAVEFORMATEX pwfx;
229 IDirectSoundCaptureBufferImpl* capture_buffer;
230 DWORD state;
231 UINT timerID;
232 CRITICAL_SECTION lock;
234 IMMDevice *mmdevice;
235 IAudioClient *client;
236 IAudioCaptureClient *capture;
238 struct list entry;
241 /*****************************************************************************
242 * IDirectSoundCaptureBuffer implementation structure
244 struct IDirectSoundCaptureBufferImpl
246 IDirectSoundCaptureBuffer8 IDirectSoundCaptureBuffer8_iface;
247 IDirectSoundNotify IDirectSoundNotify_iface;
248 LONG numIfaces; /* "in use interfaces" refcount */
249 LONG ref, refn;
250 /* IDirectSoundCaptureBuffer fields */
251 DirectSoundCaptureDevice* device;
252 LPDSCBUFFERDESC pdscbd;
253 DWORD flags;
254 /* IDirectSoundNotify fields */
255 LPDSBPOSITIONNOTIFY notifies;
256 int nrofnotifies;
259 HRESULT IKsPrivatePropertySetImpl_Create(REFIID riid, IKsPropertySet **piks) DECLSPEC_HIDDEN;
261 /*******************************************************************************
264 /* dsound.c */
266 HRESULT DSOUND_Create(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
267 HRESULT DSOUND_Create8(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
269 /* primary.c */
271 HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device) DECLSPEC_HIDDEN;
272 HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device) DECLSPEC_HIDDEN;
273 HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device) DECLSPEC_HIDDEN;
274 HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device) DECLSPEC_HIDDEN;
275 HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos) DECLSPEC_HIDDEN;
276 LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
277 HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) DECLSPEC_HIDDEN;
278 HRESULT primarybuffer_create(DirectSoundDevice *device, IDirectSoundBufferImpl **ppdsb,
279 const DSBUFFERDESC *dsbd) DECLSPEC_HIDDEN;
280 void primarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
281 HRESULT primarybuffer_SetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
282 LONG capped_refcount_dec(LONG *ref) DECLSPEC_HIDDEN;
284 /* duplex.c */
286 HRESULT DSOUND_FullDuplexCreate(REFIID riid, LPDIRECTSOUNDFULLDUPLEX* ppDSFD) DECLSPEC_HIDDEN;
288 /* mixer.c */
289 void DSOUND_CheckEvent(const IDirectSoundBufferImpl *dsb, DWORD playpos, int len) DECLSPEC_HIDDEN;
290 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
291 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
292 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
293 DWORD DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl *dsb, DWORD secpos, DWORD secmixpos, float *overshot) DECLSPEC_HIDDEN;
295 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) DECLSPEC_HIDDEN;
297 /* sound3d.c */
299 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
301 /* capture.c */
303 HRESULT DSOUND_CaptureCreate(REFIID riid, LPDIRECTSOUNDCAPTURE *ppDSC) DECLSPEC_HIDDEN;
304 HRESULT DSOUND_CaptureCreate8(REFIID riid, LPDIRECTSOUNDCAPTURE8 *ppDSC8) DECLSPEC_HIDDEN;
306 #define STATE_STOPPED 0
307 #define STATE_STARTING 1
308 #define STATE_PLAYING 2
309 #define STATE_CAPTURING 2
310 #define STATE_STOPPING 3
312 extern CRITICAL_SECTION DSOUND_renderers_lock DECLSPEC_HIDDEN;
313 extern CRITICAL_SECTION DSOUND_capturers_lock DECLSPEC_HIDDEN;
314 extern struct list DSOUND_capturers DECLSPEC_HIDDEN;
315 extern struct list DSOUND_renderers DECLSPEC_HIDDEN;
317 extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
318 extern GUID DSOUND_capture_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
320 extern WCHAR wine_vxd_drv[] DECLSPEC_HIDDEN;
322 void setup_dsound_options(void) DECLSPEC_HIDDEN;
323 const char * dumpCooperativeLevel(DWORD level) DECLSPEC_HIDDEN;
325 HRESULT get_mmdevice(EDataFlow flow, const GUID *tgt, IMMDevice **device) DECLSPEC_HIDDEN;
327 BOOL DSOUND_check_supported(IAudioClient *client, DWORD rate,
328 DWORD depth, WORD channels) DECLSPEC_HIDDEN;
329 UINT DSOUND_create_timer(LPTIMECALLBACK cb, DWORD_PTR user) DECLSPEC_HIDDEN;
330 HRESULT enumerate_mmdevices(EDataFlow flow, GUID *guids,
331 LPDSENUMCALLBACKW cb, void *user) DECLSPEC_HIDDEN;