dsound: Hack in low latency
[wine/multimedia.git] / dlls / dsound / dsound_private.h
blobf838b87caaf3a83fc19d3d40381508ec8a6d0323
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 1 /* Resolution of multimedia timer */
24 #define DS_TIME_DEL 1 /* 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 IDirectSoundBufferImpl IDirectSoundBufferImpl;
43 typedef struct IDirectSoundCaptureImpl IDirectSoundCaptureImpl;
44 typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl;
45 typedef struct DirectSoundDevice DirectSoundDevice;
46 typedef struct DirectSoundCaptureDevice DirectSoundCaptureDevice;
48 /* dsound_convert.h */
49 typedef float (*bitsgetfunc)(const IDirectSoundBufferImpl *, DWORD, DWORD);
50 typedef void (*bitsputfunc)(const IDirectSoundBufferImpl *, DWORD, DWORD, float);
51 extern const bitsgetfunc getbpp[5] DECLSPEC_HIDDEN;
52 void putieee32(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) DECLSPEC_HIDDEN;
53 void mixieee32(float *src, float *dst, unsigned samples) DECLSPEC_HIDDEN;
54 typedef void (*normfunc)(const void *, void *, unsigned);
55 extern const normfunc normfunctions[5] DECLSPEC_HIDDEN;
57 typedef struct _DSVOLUMEPAN
59 DWORD dwTotalLeftAmpFactor;
60 DWORD dwTotalRightAmpFactor;
61 LONG lVolume;
62 DWORD dwVolAmpFactor;
63 LONG lPan;
64 DWORD dwPanLeftAmpFactor;
65 DWORD dwPanRightAmpFactor;
66 } DSVOLUMEPAN,*PDSVOLUMEPAN;
68 /*****************************************************************************
69 * IDirectSoundDevice implementation structure
71 struct DirectSoundDevice
73 LONG ref;
75 GUID guid;
76 DSCAPS drvcaps;
77 DWORD priolevel;
78 PWAVEFORMATEX pwfx;
79 UINT timerID, playing_offs_bytes, in_mmdev_bytes, prebuf, helfrags;
80 DWORD fraglen;
81 LPBYTE buffer;
82 DWORD writelead, buflen, state, playpos, mixpos;
83 int nrofbuffers;
84 IDirectSoundBufferImpl** buffers;
85 RTL_RWLOCK buffer_list_lock;
86 CRITICAL_SECTION mixlock;
87 IDirectSoundBufferImpl *primary;
88 DWORD speaker_config;
89 float *mix_buffer, *tmp_buffer;
90 DWORD tmp_buffer_len, mix_buffer_len;
92 DSVOLUMEPAN volpan;
94 normfunc normfunction;
96 /* DirectSound3DListener fields */
97 DS3DLISTENER ds3dl;
98 BOOL ds3dl_need_recalc;
100 IMMDevice *mmdevice;
101 IAudioClient *client;
102 IAudioClock *clock;
103 IAudioStreamVolume *volume;
104 IAudioRenderClient *render;
106 struct list entry;
109 /* reference counted buffer memory for duplicated buffer memory */
110 typedef struct BufferMemory
112 LONG ref;
113 LPBYTE memory;
114 struct list buffers;
115 } BufferMemory;
117 ULONG DirectSoundDevice_Release(DirectSoundDevice * device) DECLSPEC_HIDDEN;
118 HRESULT DirectSoundDevice_Initialize(
119 DirectSoundDevice ** ppDevice,
120 LPCGUID lpcGUID) DECLSPEC_HIDDEN;
121 HRESULT DirectSoundDevice_AddBuffer(
122 DirectSoundDevice * device,
123 IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
124 HRESULT DirectSoundDevice_RemoveBuffer(
125 DirectSoundDevice * device,
126 IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
127 HRESULT DirectSoundDevice_GetCaps(DirectSoundDevice * device, LPDSCAPS lpDSCaps) DECLSPEC_HIDDEN;
128 HRESULT DirectSoundDevice_CreateSoundBuffer(
129 DirectSoundDevice * device,
130 LPCDSBUFFERDESC dsbd,
131 LPLPDIRECTSOUNDBUFFER ppdsb,
132 LPUNKNOWN lpunk,
133 BOOL from8) DECLSPEC_HIDDEN;
134 HRESULT DirectSoundDevice_DuplicateSoundBuffer(
135 DirectSoundDevice * device,
136 LPDIRECTSOUNDBUFFER psb,
137 LPLPDIRECTSOUNDBUFFER ppdsb) DECLSPEC_HIDDEN;
138 HRESULT DirectSoundDevice_SetCooperativeLevel(
139 DirectSoundDevice * devcie,
140 HWND hwnd,
141 DWORD level) DECLSPEC_HIDDEN;
142 HRESULT DirectSoundDevice_Compact(DirectSoundDevice * device) DECLSPEC_HIDDEN;
143 HRESULT DirectSoundDevice_GetSpeakerConfig(
144 DirectSoundDevice * device,
145 LPDWORD lpdwSpeakerConfig) DECLSPEC_HIDDEN;
146 HRESULT DirectSoundDevice_SetSpeakerConfig(
147 DirectSoundDevice * device,
148 DWORD config) DECLSPEC_HIDDEN;
149 HRESULT DirectSoundDevice_VerifyCertification(DirectSoundDevice * device,
150 LPDWORD pdwCertified) DECLSPEC_HIDDEN;
152 /*****************************************************************************
153 * IDirectSoundBuffer implementation structure
155 struct IDirectSoundBufferImpl
157 IDirectSoundBuffer8 IDirectSoundBuffer8_iface;
158 IDirectSoundNotify IDirectSoundNotify_iface;
159 IDirectSound3DListener IDirectSound3DListener_iface; /* only primary buffer */
160 IDirectSound3DBuffer IDirectSound3DBuffer_iface; /* only secondary buffer */
161 IKsPropertySet IKsPropertySet_iface;
162 LONG numIfaces; /* "in use interfaces" refcount */
163 LONG ref, refn, ref3D, refiks;
164 /* IDirectSoundBufferImpl fields */
165 DirectSoundDevice* device;
166 RTL_RWLOCK lock;
167 PWAVEFORMATEX pwfx;
168 BufferMemory* buffer;
169 DWORD playflags,state,leadin;
170 DWORD writelead,buflen;
171 DWORD nAvgBytesPerSec;
172 DWORD freq;
173 DSVOLUMEPAN volpan;
174 DSBUFFERDESC dsbd;
175 /* used for frequency conversion (PerfectPitch) */
176 ULONG freqneeded;
177 DWORD firstep;
178 float freqAcc, freqAdjust, firgain;
179 /* used for mixing */
180 DWORD sec_mixpos;
182 /* IDirectSoundNotify fields */
183 LPDSBPOSITIONNOTIFY notifies;
184 int nrofnotifies;
185 /* DirectSound3DBuffer fields */
186 DS3DBUFFER ds3db_ds3db;
187 LONG ds3db_lVolume;
188 BOOL ds3db_need_recalc;
189 /* Used for bit depth conversion */
190 int mix_channels;
191 bitsgetfunc get, get_aux;
192 bitsputfunc put, put_aux;
194 struct list entry;
197 float get_mono(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel) DECLSPEC_HIDDEN;
198 void put_mono2stereo(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) DECLSPEC_HIDDEN;
200 HRESULT IDirectSoundBufferImpl_Create(
201 DirectSoundDevice *device,
202 IDirectSoundBufferImpl **ppdsb,
203 LPCDSBUFFERDESC dsbd) DECLSPEC_HIDDEN;
204 HRESULT IDirectSoundBufferImpl_Duplicate(
205 DirectSoundDevice *device,
206 IDirectSoundBufferImpl **ppdsb,
207 IDirectSoundBufferImpl *pdsb) DECLSPEC_HIDDEN;
208 void secondarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
209 const IDirectSound3DListenerVtbl ds3dlvt DECLSPEC_HIDDEN;
210 const IDirectSound3DBufferVtbl ds3dbvt DECLSPEC_HIDDEN;
211 const IKsPropertySetVtbl iksbvt DECLSPEC_HIDDEN;
213 /*****************************************************************************
214 * DirectSoundCaptureDevice implementation structure
216 struct DirectSoundCaptureDevice
218 GUID guid;
219 LONG ref;
221 DSCCAPS drvcaps;
223 LPBYTE buffer;
224 DWORD buflen, write_pos_bytes;
226 PWAVEFORMATEX pwfx;
228 IDirectSoundCaptureBufferImpl* capture_buffer;
229 DWORD state;
230 UINT timerID;
231 CRITICAL_SECTION lock;
233 IMMDevice *mmdevice;
234 IAudioClient *client;
235 IAudioCaptureClient *capture;
237 struct list entry;
240 /*****************************************************************************
241 * IDirectSoundCaptureBuffer implementation structure
243 struct IDirectSoundCaptureBufferImpl
245 IDirectSoundCaptureBuffer8 IDirectSoundCaptureBuffer8_iface;
246 IDirectSoundNotify IDirectSoundNotify_iface;
247 LONG numIfaces; /* "in use interfaces" refcount */
248 LONG ref, refn;
249 /* IDirectSoundCaptureBuffer fields */
250 DirectSoundCaptureDevice* device;
251 LPDSCBUFFERDESC pdscbd;
252 DWORD flags;
253 /* IDirectSoundNotify fields */
254 LPDSBPOSITIONNOTIFY notifies;
255 int nrofnotifies;
258 HRESULT IKsPrivatePropertySetImpl_Create(REFIID riid, IKsPropertySet **piks) DECLSPEC_HIDDEN;
260 /*******************************************************************************
263 /* dsound.c */
265 HRESULT DSOUND_Create(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
266 HRESULT DSOUND_Create8(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
268 /* primary.c */
270 HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device) DECLSPEC_HIDDEN;
271 HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device) DECLSPEC_HIDDEN;
272 HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device) DECLSPEC_HIDDEN;
273 HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device) DECLSPEC_HIDDEN;
274 HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos) DECLSPEC_HIDDEN;
275 LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
276 HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) DECLSPEC_HIDDEN;
277 HRESULT primarybuffer_create(DirectSoundDevice *device, IDirectSoundBufferImpl **ppdsb,
278 const DSBUFFERDESC *dsbd) DECLSPEC_HIDDEN;
279 void primarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
280 HRESULT primarybuffer_SetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
281 LONG capped_refcount_dec(LONG *ref) DECLSPEC_HIDDEN;
283 /* duplex.c */
285 HRESULT DSOUND_FullDuplexCreate(REFIID riid, LPDIRECTSOUNDFULLDUPLEX* ppDSFD) DECLSPEC_HIDDEN;
287 /* mixer.c */
288 void DSOUND_CheckEvent(const IDirectSoundBufferImpl *dsb, DWORD playpos, int len) DECLSPEC_HIDDEN;
289 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
290 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
291 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
292 DWORD DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl *dsb, DWORD secpos, DWORD secmixpos, float *overshot) DECLSPEC_HIDDEN;
294 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) DECLSPEC_HIDDEN;
296 /* sound3d.c */
298 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
300 /* capture.c */
302 HRESULT DSOUND_CaptureCreate(REFIID riid, LPDIRECTSOUNDCAPTURE *ppDSC) DECLSPEC_HIDDEN;
303 HRESULT DSOUND_CaptureCreate8(REFIID riid, LPDIRECTSOUNDCAPTURE8 *ppDSC8) DECLSPEC_HIDDEN;
305 #define STATE_STOPPED 0
306 #define STATE_STARTING 1
307 #define STATE_PLAYING 2
308 #define STATE_CAPTURING 2
309 #define STATE_STOPPING 3
311 extern CRITICAL_SECTION DSOUND_renderers_lock DECLSPEC_HIDDEN;
312 extern CRITICAL_SECTION DSOUND_capturers_lock DECLSPEC_HIDDEN;
313 extern struct list DSOUND_capturers DECLSPEC_HIDDEN;
314 extern struct list DSOUND_renderers DECLSPEC_HIDDEN;
316 extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
317 extern GUID DSOUND_capture_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
319 extern WCHAR wine_vxd_drv[] DECLSPEC_HIDDEN;
321 void setup_dsound_options(void) DECLSPEC_HIDDEN;
322 const char * dumpCooperativeLevel(DWORD level) DECLSPEC_HIDDEN;
324 HRESULT get_mmdevice(EDataFlow flow, const GUID *tgt, IMMDevice **device) DECLSPEC_HIDDEN;
326 BOOL DSOUND_check_supported(IAudioClient *client, DWORD rate,
327 DWORD depth, WORD channels) DECLSPEC_HIDDEN;
328 UINT DSOUND_create_timer(LPTIMECALLBACK cb, DWORD_PTR user) DECLSPEC_HIDDEN;
329 HRESULT enumerate_mmdevices(EDataFlow flow, GUID *guids,
330 LPDSENUMCALLBACKW cb, void *user) DECLSPEC_HIDDEN;