0b5fde9b82c9fc5d15b29cd6a1f2b53849ec43b5
[reactos.git] / reactos / dll / directx / wine / dsound / dsound_private.h
1 /* DirectSound
2 *
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998 Rob Riggs
5 * Copyright 2000-2001 TransGaming Technologies, Inc.
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #ifndef _DSOUND_PRIVATE_H_
23 #define _DSOUND_PRIVATE_H_
24
25 #include <wine/config.h>
26
27 #include <assert.h>
28 #include <math.h>
29 #include <stdarg.h>
30
31 #define WIN32_NO_STATUS
32 #define _INC_WINDOWS
33 #define COM_NO_WINDOWS_H
34
35 #define COBJMACROS
36 #define NONAMELESSSTRUCT
37 #define NONAMELESSUNION
38
39 #include <windef.h>
40 #include <winbase.h>
41 #include <winnls.h>
42 #include <wingdi.h>
43 #include <winternl.h>
44 #include <objbase.h>
45 #include <mmdeviceapi.h>
46 #include <audioclient.h>
47 #include <mmsystem.h>
48 #include <dsound.h>
49 #include <dsconf.h>
50 #include <vfwmsgs.h>
51 #include <devpkey.h>
52
53 #include <wine/debug.h>
54 #include <wine/list.h>
55
56 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
57
58 /* Linux does not support better timing than 10ms */
59 #define DS_TIME_RES 2 /* Resolution of multimedia timer */
60 #define DS_TIME_DEL 10 /* Delay of multimedia timer callback, and duration of HEL fragment */
61
62 extern int ds_hel_buflen DECLSPEC_HIDDEN;
63 extern int ds_snd_queue_max DECLSPEC_HIDDEN;
64
65 /*****************************************************************************
66 * Predeclare the interface implementation structures
67 */
68 typedef struct IDirectSoundBufferImpl IDirectSoundBufferImpl;
69 typedef struct DirectSoundDevice DirectSoundDevice;
70
71 /* dsound_convert.h */
72 typedef float (*bitsgetfunc)(const IDirectSoundBufferImpl *, DWORD, DWORD);
73 typedef void (*bitsputfunc)(const IDirectSoundBufferImpl *, DWORD, DWORD, float);
74 extern const bitsgetfunc getbpp[5] DECLSPEC_HIDDEN;
75 void putieee32(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) DECLSPEC_HIDDEN;
76 void mixieee32(float *src, float *dst, unsigned samples) DECLSPEC_HIDDEN;
77 typedef void (*normfunc)(const void *, void *, unsigned);
78 extern const normfunc normfunctions[5] DECLSPEC_HIDDEN;
79
80 typedef struct _DSVOLUMEPAN
81 {
82 DWORD dwTotalLeftAmpFactor;
83 DWORD dwTotalRightAmpFactor;
84 LONG lVolume;
85 DWORD dwVolAmpFactor;
86 LONG lPan;
87 DWORD dwPanLeftAmpFactor;
88 DWORD dwPanRightAmpFactor;
89 } DSVOLUMEPAN,*PDSVOLUMEPAN;
90
91 /*****************************************************************************
92 * IDirectSoundDevice implementation structure
93 */
94 struct DirectSoundDevice
95 {
96 LONG ref;
97
98 GUID guid;
99 DSCAPS drvcaps;
100 DWORD priolevel, sleeptime;
101 PWAVEFORMATEX pwfx, primary_pwfx;
102 UINT playing_offs_bytes, in_mmdev_bytes, prebuf;
103 DWORD fraglen;
104 LPBYTE buffer;
105 DWORD writelead, buflen, state, playpos, mixpos;
106 int nrofbuffers;
107 IDirectSoundBufferImpl** buffers;
108 RTL_RWLOCK buffer_list_lock;
109 CRITICAL_SECTION mixlock;
110 IDirectSoundBufferImpl *primary;
111 DWORD speaker_config;
112 float *mix_buffer, *tmp_buffer;
113 DWORD tmp_buffer_len, mix_buffer_len;
114
115 DSVOLUMEPAN volpan;
116
117 normfunc normfunction;
118
119 /* DirectSound3DListener fields */
120 DS3DLISTENER ds3dl;
121 BOOL ds3dl_need_recalc;
122
123 IMMDevice *mmdevice;
124 IAudioClient *client;
125 IAudioClock *clock;
126 IAudioStreamVolume *volume;
127 IAudioRenderClient *render;
128
129 HANDLE sleepev, thread;
130 struct list entry;
131 };
132
133 /* reference counted buffer memory for duplicated buffer memory */
134 typedef struct BufferMemory
135 {
136 LONG ref;
137 LPBYTE memory;
138 struct list buffers;
139 } BufferMemory;
140
141 ULONG DirectSoundDevice_Release(DirectSoundDevice * device) DECLSPEC_HIDDEN;
142 HRESULT DirectSoundDevice_Initialize(
143 DirectSoundDevice ** ppDevice,
144 LPCGUID lpcGUID) DECLSPEC_HIDDEN;
145 HRESULT DirectSoundDevice_AddBuffer(
146 DirectSoundDevice * device,
147 IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
148 void DirectSoundDevice_RemoveBuffer(DirectSoundDevice * device, IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
149 HRESULT DirectSoundDevice_CreateSoundBuffer(
150 DirectSoundDevice * device,
151 LPCDSBUFFERDESC dsbd,
152 LPLPDIRECTSOUNDBUFFER ppdsb,
153 LPUNKNOWN lpunk,
154 BOOL from8) DECLSPEC_HIDDEN;
155 HRESULT DirectSoundDevice_DuplicateSoundBuffer(
156 DirectSoundDevice * device,
157 LPDIRECTSOUNDBUFFER psb,
158 LPLPDIRECTSOUNDBUFFER ppdsb) DECLSPEC_HIDDEN;
159
160 /*****************************************************************************
161 * IDirectSoundBuffer implementation structure
162 */
163 struct IDirectSoundBufferImpl
164 {
165 IDirectSoundBuffer8 IDirectSoundBuffer8_iface;
166 IDirectSoundNotify IDirectSoundNotify_iface;
167 IDirectSound3DListener IDirectSound3DListener_iface; /* only primary buffer */
168 IDirectSound3DBuffer IDirectSound3DBuffer_iface; /* only secondary buffer */
169 IKsPropertySet IKsPropertySet_iface;
170 LONG numIfaces; /* "in use interfaces" refcount */
171 LONG ref, refn, ref3D, refiks;
172 /* IDirectSoundBufferImpl fields */
173 DirectSoundDevice* device;
174 RTL_RWLOCK lock;
175 PWAVEFORMATEX pwfx;
176 BufferMemory* buffer;
177 DWORD playflags,state,leadin;
178 DWORD writelead,buflen;
179 DWORD nAvgBytesPerSec;
180 DWORD freq;
181 DSVOLUMEPAN volpan;
182 DSBUFFERDESC dsbd;
183 /* used for frequency conversion (PerfectPitch) */
184 ULONG freqneeded;
185 DWORD firstep;
186 float freqAcc, freqAdjust, firgain;
187 /* used for mixing */
188 DWORD sec_mixpos;
189
190 /* IDirectSoundNotify fields */
191 LPDSBPOSITIONNOTIFY notifies;
192 int nrofnotifies;
193 /* DirectSound3DBuffer fields */
194 DS3DBUFFER ds3db_ds3db;
195 LONG ds3db_lVolume;
196 BOOL ds3db_need_recalc;
197 /* Used for bit depth conversion */
198 int mix_channels;
199 bitsgetfunc get, get_aux;
200 bitsputfunc put, put_aux;
201
202 struct list entry;
203 };
204
205 float get_mono(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel) DECLSPEC_HIDDEN;
206 void put_mono2stereo(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) DECLSPEC_HIDDEN;
207
208 HRESULT IDirectSoundBufferImpl_Create(
209 DirectSoundDevice *device,
210 IDirectSoundBufferImpl **ppdsb,
211 LPCDSBUFFERDESC dsbd) DECLSPEC_HIDDEN;
212 HRESULT IDirectSoundBufferImpl_Duplicate(
213 DirectSoundDevice *device,
214 IDirectSoundBufferImpl **ppdsb,
215 IDirectSoundBufferImpl *pdsb) DECLSPEC_HIDDEN;
216 void secondarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
217 const IDirectSound3DListenerVtbl ds3dlvt DECLSPEC_HIDDEN;
218 const IDirectSound3DBufferVtbl ds3dbvt DECLSPEC_HIDDEN;
219 const IKsPropertySetVtbl iksbvt DECLSPEC_HIDDEN;
220
221 HRESULT IKsPrivatePropertySetImpl_Create(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
222
223 /*******************************************************************************
224 */
225
226 /* dsound.c */
227
228 HRESULT DSOUND_Create(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
229 HRESULT DSOUND_Create8(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
230 HRESULT IDirectSoundImpl_Create(IUnknown *outer_unk, REFIID riid, void **ppv, BOOL has_ds8) DECLSPEC_HIDDEN;
231
232 /* primary.c */
233
234 HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device) DECLSPEC_HIDDEN;
235 HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device) DECLSPEC_HIDDEN;
236 HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device) DECLSPEC_HIDDEN;
237 HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device) DECLSPEC_HIDDEN;
238 HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos) DECLSPEC_HIDDEN;
239 LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
240 HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) DECLSPEC_HIDDEN;
241 HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device) DECLSPEC_HIDDEN;
242 HRESULT primarybuffer_create(DirectSoundDevice *device, IDirectSoundBufferImpl **ppdsb,
243 const DSBUFFERDESC *dsbd) DECLSPEC_HIDDEN;
244 void primarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
245 HRESULT primarybuffer_SetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
246 LONG capped_refcount_dec(LONG *ref) DECLSPEC_HIDDEN;
247
248 /* duplex.c */
249
250 HRESULT DSOUND_FullDuplexCreate(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
251
252 /* mixer.c */
253 void DSOUND_CheckEvent(const IDirectSoundBufferImpl *dsb, DWORD playpos, int len) DECLSPEC_HIDDEN;
254 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
255 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
256 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
257 DWORD DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl *dsb, DWORD secpos, DWORD secmixpos, float *overshot) DECLSPEC_HIDDEN;
258
259 DWORD CALLBACK DSOUND_mixthread(void *ptr) DECLSPEC_HIDDEN;
260
261 /* sound3d.c */
262
263 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
264
265 /* capture.c */
266
267 HRESULT DSOUND_CaptureCreate(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
268 HRESULT DSOUND_CaptureCreate8(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
269 HRESULT IDirectSoundCaptureImpl_Create(IUnknown *outer_unk, REFIID riid, void **ppv, BOOL has_dsc8) DECLSPEC_HIDDEN;
270
271 #define STATE_STOPPED 0
272 #define STATE_STARTING 1
273 #define STATE_PLAYING 2
274 #define STATE_CAPTURING 2
275 #define STATE_STOPPING 3
276
277 extern CRITICAL_SECTION DSOUND_renderers_lock DECLSPEC_HIDDEN;
278 extern CRITICAL_SECTION DSOUND_capturers_lock DECLSPEC_HIDDEN;
279 extern struct list DSOUND_capturers DECLSPEC_HIDDEN;
280 extern struct list DSOUND_renderers DECLSPEC_HIDDEN;
281
282 extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
283 extern GUID DSOUND_capture_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
284
285 extern WCHAR wine_vxd_drv[] DECLSPEC_HIDDEN;
286
287 void setup_dsound_options(void) DECLSPEC_HIDDEN;
288
289 HRESULT get_mmdevice(EDataFlow flow, const GUID *tgt, IMMDevice **device) DECLSPEC_HIDDEN;
290
291 BOOL DSOUND_check_supported(IAudioClient *client, DWORD rate,
292 DWORD depth, WORD channels) DECLSPEC_HIDDEN;
293 UINT DSOUND_create_timer(LPTIMECALLBACK cb, DWORD_PTR user) DECLSPEC_HIDDEN;
294 HRESULT enumerate_mmdevices(EDataFlow flow, GUID *guids,
295 LPDSENUMCALLBACKW cb, void *user) DECLSPEC_HIDDEN;
296
297 #endif /* _DSOUND_PRIVATE_H_ */