dsound: Basic COM cleanup for the IDirectSoundBuffer8 iface.
[wine.git] / dlls / dsound / dsound_private.h
blobb552b1af2212ed9c2344d9a3c90ab0410c485f14
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 "wine/list.h"
28 /* direct sound hardware acceleration levels */
29 #define DS_HW_ACCEL_FULL 0 /* default on Windows 98 */
30 #define DS_HW_ACCEL_STANDARD 1 /* default on Windows 2000 */
31 #define DS_HW_ACCEL_BASIC 2
32 #define DS_HW_ACCEL_EMULATION 3
34 extern int ds_emuldriver DECLSPEC_HIDDEN;
35 extern int ds_hel_buflen DECLSPEC_HIDDEN;
36 extern int ds_snd_queue_max DECLSPEC_HIDDEN;
37 extern int ds_snd_queue_min DECLSPEC_HIDDEN;
38 extern int ds_snd_shadow_maxsize DECLSPEC_HIDDEN;
39 extern int ds_hw_accel DECLSPEC_HIDDEN;
40 extern int ds_default_sample_rate DECLSPEC_HIDDEN;
41 extern int ds_default_bits_per_sample DECLSPEC_HIDDEN;
43 /*****************************************************************************
44 * Predeclare the interface implementation structures
46 typedef struct IDirectSoundImpl IDirectSoundImpl;
47 typedef struct IDirectSound_IUnknown IDirectSound_IUnknown;
48 typedef struct IDirectSound_IDirectSound IDirectSound_IDirectSound;
49 typedef struct IDirectSound8_IUnknown IDirectSound8_IUnknown;
50 typedef struct IDirectSound8_IDirectSound IDirectSound8_IDirectSound;
51 typedef struct IDirectSound8_IDirectSound8 IDirectSound8_IDirectSound8;
52 typedef struct IDirectSoundBufferImpl IDirectSoundBufferImpl;
53 typedef struct IDirectSoundCaptureImpl IDirectSoundCaptureImpl;
54 typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl;
55 typedef struct IDirectSoundNotifyImpl IDirectSoundNotifyImpl;
56 typedef struct IDirectSoundCaptureNotifyImpl IDirectSoundCaptureNotifyImpl;
57 typedef struct IDirectSound3DListenerImpl IDirectSound3DListenerImpl;
58 typedef struct IDirectSound3DBufferImpl IDirectSound3DBufferImpl;
59 typedef struct IKsBufferPropertySetImpl IKsBufferPropertySetImpl;
60 typedef struct PrimaryBufferImpl PrimaryBufferImpl;
61 typedef struct SecondaryBufferImpl SecondaryBufferImpl;
62 typedef struct DirectSoundDevice DirectSoundDevice;
63 typedef struct DirectSoundCaptureDevice DirectSoundCaptureDevice;
65 /* dsound_convert.h */
66 typedef void (*bitsconvertfunc)(const void *, void *, UINT, UINT, INT, UINT, UINT);
67 extern const bitsconvertfunc convertbpp[5][4] DECLSPEC_HIDDEN;
68 typedef void (*mixfunc)(const void *, void *, unsigned);
69 extern const mixfunc mixfunctions[4] DECLSPEC_HIDDEN;
70 typedef void (*normfunc)(const void *, void *, unsigned);
71 extern const normfunc normfunctions[4] DECLSPEC_HIDDEN;
73 /*****************************************************************************
74 * IDirectSoundDevice implementation structure
76 struct DirectSoundDevice
78 LONG ref;
80 GUID guid;
81 PIDSDRIVER driver;
82 DSDRIVERDESC drvdesc;
83 DSDRIVERCAPS drvcaps;
84 DWORD priolevel;
85 PWAVEFORMATEX pwfx;
86 HWAVEOUT hwo;
87 LPWAVEHDR pwave;
88 UINT timerID, pwplay, pwqueue, prebuf, helfrags;
89 DWORD fraglen;
90 PIDSDRIVERBUFFER hwbuf;
91 LPBYTE buffer;
92 DWORD writelead, buflen, state, playpos, mixpos;
93 int nrofbuffers;
94 IDirectSoundBufferImpl** buffers;
95 RTL_RWLOCK buffer_list_lock;
96 CRITICAL_SECTION mixlock;
97 PrimaryBufferImpl* primary;
98 DSBUFFERDESC dsbd;
99 DWORD speaker_config;
100 LPBYTE tmp_buffer, mix_buffer;
101 DWORD tmp_buffer_len, mix_buffer_len;
103 DSVOLUMEPAN volpan;
105 mixfunc mixfunction;
106 normfunc normfunction;
108 /* DirectSound3DListener fields */
109 IDirectSound3DListenerImpl* listener;
110 DS3DLISTENER ds3dl;
111 BOOL ds3dl_need_recalc;
114 /* reference counted buffer memory for duplicated buffer memory */
115 typedef struct BufferMemory
117 LONG ref;
118 LPBYTE memory;
119 struct list buffers;
120 } BufferMemory;
122 ULONG DirectSoundDevice_Release(DirectSoundDevice * device) DECLSPEC_HIDDEN;
123 HRESULT DirectSoundDevice_Initialize(
124 DirectSoundDevice ** ppDevice,
125 LPCGUID lpcGUID) DECLSPEC_HIDDEN;
126 HRESULT DirectSoundDevice_AddBuffer(
127 DirectSoundDevice * device,
128 IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
129 HRESULT DirectSoundDevice_RemoveBuffer(
130 DirectSoundDevice * device,
131 IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
132 HRESULT DirectSoundDevice_GetCaps(DirectSoundDevice * device, LPDSCAPS lpDSCaps) DECLSPEC_HIDDEN;
133 HRESULT DirectSoundDevice_CreateSoundBuffer(
134 DirectSoundDevice * device,
135 LPCDSBUFFERDESC dsbd,
136 LPLPDIRECTSOUNDBUFFER ppdsb,
137 LPUNKNOWN lpunk,
138 BOOL from8) DECLSPEC_HIDDEN;
139 HRESULT DirectSoundDevice_DuplicateSoundBuffer(
140 DirectSoundDevice * device,
141 LPDIRECTSOUNDBUFFER psb,
142 LPLPDIRECTSOUNDBUFFER ppdsb) DECLSPEC_HIDDEN;
143 HRESULT DirectSoundDevice_SetCooperativeLevel(
144 DirectSoundDevice * devcie,
145 HWND hwnd,
146 DWORD level) DECLSPEC_HIDDEN;
147 HRESULT DirectSoundDevice_Compact(DirectSoundDevice * device) DECLSPEC_HIDDEN;
148 HRESULT DirectSoundDevice_GetSpeakerConfig(
149 DirectSoundDevice * device,
150 LPDWORD lpdwSpeakerConfig) DECLSPEC_HIDDEN;
151 HRESULT DirectSoundDevice_SetSpeakerConfig(
152 DirectSoundDevice * device,
153 DWORD config) DECLSPEC_HIDDEN;
154 HRESULT DirectSoundDevice_VerifyCertification(DirectSoundDevice * device,
155 LPDWORD pdwCertified) DECLSPEC_HIDDEN;
157 /*****************************************************************************
158 * IDirectSoundBuffer implementation structure
160 struct IDirectSoundBufferImpl
162 IDirectSoundBuffer8 IDirectSoundBuffer8_iface;
163 LONG ref;
164 /* IDirectSoundBufferImpl fields */
165 SecondaryBufferImpl* secondary;
166 DirectSoundDevice* device;
167 RTL_RWLOCK lock;
168 PIDSDRIVERBUFFER hwbuf;
169 PWAVEFORMATEX pwfx;
170 BufferMemory* buffer;
171 LPBYTE tmp_buffer;
172 DWORD playflags,state,leadin;
173 DWORD writelead,buflen;
174 DWORD nAvgBytesPerSec;
175 DWORD freq, tmp_buffer_len, max_buffer_len;
176 DSVOLUMEPAN volpan;
177 DSBUFFERDESC dsbd;
178 /* used for frequency conversion (PerfectPitch) */
179 ULONG freqneeded, freqAdjust, freqAcc, freqAccNext, resampleinmixer;
180 /* used for mixing */
181 DWORD primary_mixpos, buf_mixpos, sec_mixpos;
183 /* IDirectSoundNotifyImpl fields */
184 IDirectSoundNotifyImpl* notify;
185 LPDSBPOSITIONNOTIFY notifies;
186 int nrofnotifies;
187 PIDSDRIVERNOTIFY hwnotify;
189 /* DirectSound3DBuffer fields */
190 IDirectSound3DBufferImpl* ds3db;
191 DS3DBUFFER ds3db_ds3db;
192 LONG ds3db_lVolume;
193 BOOL ds3db_need_recalc;
195 /* IKsPropertySet fields */
196 IKsBufferPropertySetImpl* iks;
197 bitsconvertfunc convert;
198 struct list entry;
201 HRESULT IDirectSoundBufferImpl_Create(
202 DirectSoundDevice *device,
203 IDirectSoundBufferImpl **ppdsb,
204 LPCDSBUFFERDESC dsbd) DECLSPEC_HIDDEN;
205 HRESULT IDirectSoundBufferImpl_Destroy(
206 IDirectSoundBufferImpl *pdsb) DECLSPEC_HIDDEN;
207 HRESULT IDirectSoundBufferImpl_Duplicate(
208 DirectSoundDevice *device,
209 IDirectSoundBufferImpl **ppdsb,
210 IDirectSoundBufferImpl *pdsb) DECLSPEC_HIDDEN;
212 /*****************************************************************************
213 * SecondaryBuffer implementation structure
215 struct SecondaryBufferImpl
217 const IDirectSoundBuffer8Vtbl *lpVtbl;
218 LONG ref;
219 IDirectSoundBufferImpl* dsb;
222 HRESULT SecondaryBufferImpl_Create(
223 IDirectSoundBufferImpl *dsb,
224 SecondaryBufferImpl **pdsb) DECLSPEC_HIDDEN;
226 /*****************************************************************************
227 * PrimaryBuffer implementation structure
229 struct PrimaryBufferImpl
231 const IDirectSoundBufferVtbl *lpVtbl;
232 LONG ref;
233 DirectSoundDevice* device;
236 HRESULT PrimaryBufferImpl_Create(
237 DirectSoundDevice * device,
238 PrimaryBufferImpl **ppdsb,
239 LPCDSBUFFERDESC dsbd) DECLSPEC_HIDDEN;
241 /*****************************************************************************
242 * DirectSoundCaptureDevice implementation structure
244 struct DirectSoundCaptureDevice
246 /* IDirectSoundCaptureImpl fields */
247 GUID guid;
248 LONG ref;
250 /* DirectSound driver stuff */
251 PIDSCDRIVER driver;
252 DSDRIVERDESC drvdesc;
253 DSCDRIVERCAPS drvcaps;
254 PIDSCDRIVERBUFFER hwbuf;
256 /* wave driver info */
257 HWAVEIN hwi;
259 /* more stuff */
260 LPBYTE buffer;
261 DWORD buflen;
263 PWAVEFORMATEX pwfx;
265 IDirectSoundCaptureBufferImpl* capture_buffer;
266 DWORD state;
267 LPWAVEHDR pwave;
268 int nrofpwaves;
269 int index;
270 CRITICAL_SECTION lock;
273 /*****************************************************************************
274 * IDirectSoundCaptureBuffer implementation structure
276 struct IDirectSoundCaptureBufferImpl
278 /* IUnknown fields */
279 const IDirectSoundCaptureBuffer8Vtbl *lpVtbl;
280 LONG ref;
282 /* IDirectSoundCaptureBufferImpl fields */
283 DirectSoundCaptureDevice* device;
284 /* FIXME: don't need this */
285 LPDSCBUFFERDESC pdscbd;
286 DWORD flags;
288 /* IDirectSoundCaptureNotifyImpl fields */
289 IDirectSoundCaptureNotifyImpl* notify;
290 LPDSBPOSITIONNOTIFY notifies;
291 int nrofnotifies;
292 PIDSDRIVERNOTIFY hwnotify;
295 /*****************************************************************************
296 * IDirectSound3DListener implementation structure
298 struct IDirectSound3DListenerImpl
300 /* IUnknown fields */
301 const IDirectSound3DListenerVtbl *lpVtbl;
302 LONG ref;
303 /* IDirectSound3DListenerImpl fields */
304 DirectSoundDevice* device;
307 HRESULT IDirectSound3DListenerImpl_Create(
308 DirectSoundDevice *device,
309 IDirectSound3DListenerImpl **pdsl) DECLSPEC_HIDDEN;
311 /*****************************************************************************
312 * IKsBufferPropertySet implementation structure
314 struct IKsBufferPropertySetImpl
316 /* IUnknown fields */
317 const IKsPropertySetVtbl *lpVtbl;
318 LONG ref;
319 /* IKsPropertySetImpl fields */
320 IDirectSoundBufferImpl* dsb;
323 HRESULT IKsBufferPropertySetImpl_Create(
324 IDirectSoundBufferImpl *dsb,
325 IKsBufferPropertySetImpl **piks) DECLSPEC_HIDDEN;
326 HRESULT IKsBufferPropertySetImpl_Destroy(
327 IKsBufferPropertySetImpl *piks) DECLSPEC_HIDDEN;
329 HRESULT IKsPrivatePropertySetImpl_Create(REFIID riid, IKsPropertySet **piks) DECLSPEC_HIDDEN;
331 /*****************************************************************************
332 * IDirectSound3DBuffer implementation structure
334 struct IDirectSound3DBufferImpl
336 /* IUnknown fields */
337 const IDirectSound3DBufferVtbl *lpVtbl;
338 LONG ref;
339 /* IDirectSound3DBufferImpl fields */
340 IDirectSoundBufferImpl* dsb;
343 HRESULT IDirectSound3DBufferImpl_Create(
344 IDirectSoundBufferImpl *dsb,
345 IDirectSound3DBufferImpl **pds3db) DECLSPEC_HIDDEN;
346 HRESULT IDirectSound3DBufferImpl_Destroy(
347 IDirectSound3DBufferImpl *pds3db) DECLSPEC_HIDDEN;
349 /*******************************************************************************
352 /* dsound.c */
354 HRESULT DSOUND_Create(REFIID riid, LPDIRECTSOUND *ppDS) DECLSPEC_HIDDEN;
355 HRESULT DSOUND_Create8(REFIID riid, LPDIRECTSOUND8 *ppDS) DECLSPEC_HIDDEN;
357 /* primary.c */
359 DWORD DSOUND_fraglen(DWORD nSamplesPerSec, DWORD nBlockAlign) DECLSPEC_HIDDEN;
360 HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device) DECLSPEC_HIDDEN;
361 HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device) DECLSPEC_HIDDEN;
362 HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device) DECLSPEC_HIDDEN;
363 HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device) DECLSPEC_HIDDEN;
364 HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos) DECLSPEC_HIDDEN;
365 LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
366 HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) DECLSPEC_HIDDEN;
368 /* duplex.c */
370 HRESULT DSOUND_FullDuplexCreate(REFIID riid, LPDIRECTSOUNDFULLDUPLEX* ppDSFD) DECLSPEC_HIDDEN;
372 /* mixer.c */
373 DWORD DSOUND_bufpos_to_mixpos(const DirectSoundDevice* device, DWORD pos) DECLSPEC_HIDDEN;
374 void DSOUND_CheckEvent(const IDirectSoundBufferImpl *dsb, DWORD playpos, int len) DECLSPEC_HIDDEN;
375 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
376 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
377 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
378 void DSOUND_MixToTemporary(const IDirectSoundBufferImpl *dsb, DWORD writepos, DWORD mixlen, BOOL inmixer) DECLSPEC_HIDDEN;
379 DWORD DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl *dsb, DWORD secpos, DWORD secmixpos, DWORD* overshot) DECLSPEC_HIDDEN;
381 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) DECLSPEC_HIDDEN;
382 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) DECLSPEC_HIDDEN;
384 /* sound3d.c */
386 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
388 /* capture.c */
390 HRESULT DSOUND_CaptureCreate(REFIID riid, LPDIRECTSOUNDCAPTURE *ppDSC) DECLSPEC_HIDDEN;
391 HRESULT DSOUND_CaptureCreate8(REFIID riid, LPDIRECTSOUNDCAPTURE8 *ppDSC8) DECLSPEC_HIDDEN;
393 #define STATE_STOPPED 0
394 #define STATE_STARTING 1
395 #define STATE_PLAYING 2
396 #define STATE_CAPTURING 2
397 #define STATE_STOPPING 3
399 #define DSOUND_FREQSHIFT (20)
401 extern DirectSoundDevice* DSOUND_renderer[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
402 extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
404 extern DirectSoundCaptureDevice * DSOUND_capture[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
405 extern GUID DSOUND_capture_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
407 HRESULT mmErr(UINT err) DECLSPEC_HIDDEN;
408 void setup_dsound_options(void) DECLSPEC_HIDDEN;
409 const char * dumpCooperativeLevel(DWORD level) DECLSPEC_HIDDEN;