comctl32: Fix a logical operator typo.
[wine] / dlls / 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 /* 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 */
25
26 #include "wine/list.h"
27
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
33
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;
42
43 /*****************************************************************************
44  * Predeclare the interface implementation structures
45  */
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 DirectSoundDevice             DirectSoundDevice;
62 typedef struct DirectSoundCaptureDevice      DirectSoundCaptureDevice;
63
64 /* dsound_convert.h */
65 typedef void (*bitsconvertfunc)(const void *, void *, UINT, UINT, INT, UINT, UINT);
66 extern const bitsconvertfunc convertbpp[5][4] DECLSPEC_HIDDEN;
67 typedef void (*mixfunc)(const void *, void *, unsigned);
68 extern const mixfunc mixfunctions[4] DECLSPEC_HIDDEN;
69 typedef void (*normfunc)(const void *, void *, unsigned);
70 extern const normfunc normfunctions[4] DECLSPEC_HIDDEN;
71
72 /*****************************************************************************
73  * IDirectSoundDevice implementation structure
74  */
75 struct DirectSoundDevice
76 {
77     LONG                        ref;
78
79     GUID                        guid;
80     PIDSDRIVER                  driver;
81     DSDRIVERDESC                drvdesc;
82     DSDRIVERCAPS                drvcaps;
83     DWORD                       priolevel;
84     PWAVEFORMATEX               pwfx;
85     HWAVEOUT                    hwo;
86     LPWAVEHDR                   pwave;
87     UINT                        timerID, pwplay, pwqueue, prebuf, helfrags;
88     DWORD                       fraglen;
89     PIDSDRIVERBUFFER            hwbuf;
90     LPBYTE                      buffer;
91     DWORD                       writelead, buflen, state, playpos, mixpos;
92     int                         nrofbuffers;
93     IDirectSoundBufferImpl**    buffers;
94     RTL_RWLOCK                  buffer_list_lock;
95     CRITICAL_SECTION            mixlock;
96     PrimaryBufferImpl*          primary;
97     DSBUFFERDESC                dsbd;
98     DWORD                       speaker_config;
99     LPBYTE                      tmp_buffer, mix_buffer;
100     DWORD                       tmp_buffer_len, mix_buffer_len;
101
102     DSVOLUMEPAN                 volpan;
103
104     mixfunc mixfunction;
105     normfunc normfunction;
106
107     /* DirectSound3DListener fields */
108     IDirectSound3DListenerImpl* listener;
109     DS3DLISTENER                ds3dl;
110     BOOL                        ds3dl_need_recalc;
111 };
112
113 /* reference counted buffer memory for duplicated buffer memory */
114 typedef struct BufferMemory
115 {
116     LONG                        ref;
117     LPBYTE                      memory;
118     struct list buffers;
119 } BufferMemory;
120
121 ULONG DirectSoundDevice_Release(DirectSoundDevice * device) DECLSPEC_HIDDEN;
122 HRESULT DirectSoundDevice_Initialize(
123     DirectSoundDevice ** ppDevice,
124     LPCGUID lpcGUID) DECLSPEC_HIDDEN;
125 HRESULT DirectSoundDevice_AddBuffer(
126     DirectSoundDevice * device,
127     IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
128 HRESULT DirectSoundDevice_RemoveBuffer(
129     DirectSoundDevice * device,
130     IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
131 HRESULT DirectSoundDevice_GetCaps(DirectSoundDevice * device, LPDSCAPS lpDSCaps) DECLSPEC_HIDDEN;
132 HRESULT DirectSoundDevice_CreateSoundBuffer(
133     DirectSoundDevice * device,
134     LPCDSBUFFERDESC dsbd,
135     LPLPDIRECTSOUNDBUFFER ppdsb,
136     LPUNKNOWN lpunk,
137     BOOL from8) DECLSPEC_HIDDEN;
138 HRESULT DirectSoundDevice_DuplicateSoundBuffer(
139     DirectSoundDevice * device,
140     LPDIRECTSOUNDBUFFER psb,
141     LPLPDIRECTSOUNDBUFFER ppdsb) DECLSPEC_HIDDEN;
142 HRESULT DirectSoundDevice_SetCooperativeLevel(
143     DirectSoundDevice * devcie,
144     HWND hwnd,
145     DWORD level) DECLSPEC_HIDDEN;
146 HRESULT DirectSoundDevice_Compact(DirectSoundDevice * device) DECLSPEC_HIDDEN;
147 HRESULT DirectSoundDevice_GetSpeakerConfig(
148     DirectSoundDevice * device,
149     LPDWORD lpdwSpeakerConfig) DECLSPEC_HIDDEN;
150 HRESULT DirectSoundDevice_SetSpeakerConfig(
151     DirectSoundDevice * device,
152     DWORD config) DECLSPEC_HIDDEN;
153 HRESULT DirectSoundDevice_VerifyCertification(DirectSoundDevice * device,
154     LPDWORD pdwCertified) DECLSPEC_HIDDEN;
155
156 /*****************************************************************************
157  * IDirectSoundBuffer implementation structure
158  */
159 struct IDirectSoundBufferImpl
160 {
161     IDirectSoundBuffer8         IDirectSoundBuffer8_iface;
162     LONG                        numIfaces; /* "in use interfaces" refcount */
163     LONG                        ref;
164     /* IDirectSoundBufferImpl fields */
165     DirectSoundDevice*          device;
166     RTL_RWLOCK                  lock;
167     PIDSDRIVERBUFFER            hwbuf;
168     PWAVEFORMATEX               pwfx;
169     BufferMemory*               buffer;
170     LPBYTE                      tmp_buffer;
171     DWORD                       playflags,state,leadin;
172     DWORD                       writelead,buflen;
173     DWORD                       nAvgBytesPerSec;
174     DWORD                       freq, tmp_buffer_len, max_buffer_len;
175     DSVOLUMEPAN                 volpan;
176     DSBUFFERDESC                dsbd;
177     /* used for frequency conversion (PerfectPitch) */
178     ULONG                       freqneeded, freqAdjust, freqAcc, freqAccNext, resampleinmixer;
179     /* used for mixing */
180     DWORD                       primary_mixpos, buf_mixpos, sec_mixpos;
181
182     /* IDirectSoundNotifyImpl fields */
183     IDirectSoundNotifyImpl*     notify;
184     LPDSBPOSITIONNOTIFY         notifies;
185     int                         nrofnotifies;
186     PIDSDRIVERNOTIFY            hwnotify;
187
188     /* DirectSound3DBuffer fields */
189     IDirectSound3DBufferImpl*   ds3db;
190     DS3DBUFFER                  ds3db_ds3db;
191     LONG                        ds3db_lVolume;
192     BOOL                        ds3db_need_recalc;
193
194     /* IKsPropertySet fields */
195     IKsBufferPropertySetImpl*   iks;
196     bitsconvertfunc convert;
197     struct list entry;
198 };
199
200 HRESULT IDirectSoundBufferImpl_Create(
201     DirectSoundDevice *device,
202     IDirectSoundBufferImpl **ppdsb,
203     LPCDSBUFFERDESC dsbd) DECLSPEC_HIDDEN;
204 HRESULT IDirectSoundBufferImpl_Destroy(
205     IDirectSoundBufferImpl *pdsb) DECLSPEC_HIDDEN;
206 HRESULT IDirectSoundBufferImpl_Duplicate(
207     DirectSoundDevice *device,
208     IDirectSoundBufferImpl **ppdsb,
209     IDirectSoundBufferImpl *pdsb) DECLSPEC_HIDDEN;
210 void secondarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
211
212 /*****************************************************************************
213  * PrimaryBuffer implementation structure
214  */
215 struct PrimaryBufferImpl
216 {
217     const IDirectSoundBufferVtbl *lpVtbl;
218     LONG                        ref;
219     DirectSoundDevice*          device;
220 };
221
222 HRESULT PrimaryBufferImpl_Create(
223     DirectSoundDevice * device,
224     PrimaryBufferImpl **ppdsb,
225     LPCDSBUFFERDESC dsbd) DECLSPEC_HIDDEN;
226
227 /*****************************************************************************
228  * DirectSoundCaptureDevice implementation structure
229  */
230 struct DirectSoundCaptureDevice
231 {
232     /* IDirectSoundCaptureImpl fields */
233     GUID                               guid;
234     LONG                               ref;
235
236     /* DirectSound driver stuff */
237     PIDSCDRIVER                        driver;
238     DSDRIVERDESC                       drvdesc;
239     DSCDRIVERCAPS                      drvcaps;
240     PIDSCDRIVERBUFFER                  hwbuf;
241
242     /* wave driver info */
243     HWAVEIN                            hwi;
244
245     /* more stuff */
246     LPBYTE                             buffer;
247     DWORD                              buflen;
248
249     PWAVEFORMATEX                      pwfx;
250
251     IDirectSoundCaptureBufferImpl*     capture_buffer;
252     DWORD                              state;
253     LPWAVEHDR                          pwave;
254     int                                nrofpwaves;
255     int                                index;
256     CRITICAL_SECTION                   lock;
257 };
258
259 /*****************************************************************************
260  * IDirectSoundCaptureBuffer implementation structure
261  */
262 struct IDirectSoundCaptureBufferImpl
263 {
264     /* IUnknown fields */
265     const IDirectSoundCaptureBuffer8Vtbl *lpVtbl;
266     LONG                                ref;
267
268     /* IDirectSoundCaptureBufferImpl fields */
269     DirectSoundCaptureDevice*           device;
270     /* FIXME: don't need this */
271     LPDSCBUFFERDESC                     pdscbd;
272     DWORD                               flags;
273
274     /* IDirectSoundCaptureNotifyImpl fields */
275     IDirectSoundCaptureNotifyImpl*      notify;
276     LPDSBPOSITIONNOTIFY                 notifies;
277     int                                 nrofnotifies;
278     PIDSDRIVERNOTIFY                    hwnotify;
279 };
280
281 /*****************************************************************************
282  *  IDirectSound3DListener implementation structure
283  */
284 struct IDirectSound3DListenerImpl
285 {
286     /* IUnknown fields */
287     const IDirectSound3DListenerVtbl *lpVtbl;
288     LONG                        ref;
289     /* IDirectSound3DListenerImpl fields */
290     DirectSoundDevice*          device;
291 };
292
293 HRESULT IDirectSound3DListenerImpl_Create(
294     DirectSoundDevice           *device,
295     IDirectSound3DListenerImpl **pdsl) DECLSPEC_HIDDEN;
296
297 /*****************************************************************************
298  *  IKsBufferPropertySet implementation structure
299  */
300 struct IKsBufferPropertySetImpl
301 {
302     /* IUnknown fields */
303     const IKsPropertySetVtbl   *lpVtbl;
304     LONG                        ref;
305     /* IKsPropertySetImpl fields */
306     IDirectSoundBufferImpl*     dsb;
307 };
308
309 HRESULT IKsBufferPropertySetImpl_Create(
310     IDirectSoundBufferImpl *dsb,
311     IKsBufferPropertySetImpl **piks) DECLSPEC_HIDDEN;
312 HRESULT IKsBufferPropertySetImpl_Destroy(
313     IKsBufferPropertySetImpl *piks) DECLSPEC_HIDDEN;
314
315 HRESULT IKsPrivatePropertySetImpl_Create(REFIID riid, IKsPropertySet **piks) DECLSPEC_HIDDEN;
316
317 /*****************************************************************************
318  * IDirectSound3DBuffer implementation structure
319  */
320 struct IDirectSound3DBufferImpl
321 {
322     /* IUnknown fields */
323     const IDirectSound3DBufferVtbl *lpVtbl;
324     LONG                        ref;
325     /* IDirectSound3DBufferImpl fields */
326     IDirectSoundBufferImpl*     dsb;
327 };
328
329 HRESULT IDirectSound3DBufferImpl_Create(
330     IDirectSoundBufferImpl *dsb,
331     IDirectSound3DBufferImpl **pds3db) DECLSPEC_HIDDEN;
332 HRESULT IDirectSound3DBufferImpl_Destroy(
333     IDirectSound3DBufferImpl *pds3db) DECLSPEC_HIDDEN;
334
335 /*******************************************************************************
336  */
337
338 /* dsound.c */
339
340 HRESULT DSOUND_Create(REFIID riid, LPDIRECTSOUND *ppDS) DECLSPEC_HIDDEN;
341 HRESULT DSOUND_Create8(REFIID riid, LPDIRECTSOUND8 *ppDS) DECLSPEC_HIDDEN;
342
343 /* primary.c */
344
345 DWORD DSOUND_fraglen(DWORD nSamplesPerSec, DWORD nBlockAlign) DECLSPEC_HIDDEN;
346 HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device) DECLSPEC_HIDDEN;
347 HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device) DECLSPEC_HIDDEN;
348 HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device) DECLSPEC_HIDDEN;
349 HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device) DECLSPEC_HIDDEN;
350 HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos) DECLSPEC_HIDDEN;
351 LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
352 HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) DECLSPEC_HIDDEN;
353
354 /* duplex.c */
355  
356 HRESULT DSOUND_FullDuplexCreate(REFIID riid, LPDIRECTSOUNDFULLDUPLEX* ppDSFD) DECLSPEC_HIDDEN;
357
358 /* mixer.c */
359 DWORD DSOUND_bufpos_to_mixpos(const DirectSoundDevice* device, DWORD pos) DECLSPEC_HIDDEN;
360 void DSOUND_CheckEvent(const IDirectSoundBufferImpl *dsb, DWORD playpos, int len) DECLSPEC_HIDDEN;
361 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
362 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
363 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
364 void DSOUND_MixToTemporary(const IDirectSoundBufferImpl *dsb, DWORD writepos, DWORD mixlen, BOOL inmixer) DECLSPEC_HIDDEN;
365 DWORD DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl *dsb, DWORD secpos, DWORD secmixpos, DWORD* overshot) DECLSPEC_HIDDEN;
366
367 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) DECLSPEC_HIDDEN;
368 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) DECLSPEC_HIDDEN;
369
370 /* sound3d.c */
371
372 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
373
374 /* capture.c */
375  
376 HRESULT DSOUND_CaptureCreate(REFIID riid, LPDIRECTSOUNDCAPTURE *ppDSC) DECLSPEC_HIDDEN;
377 HRESULT DSOUND_CaptureCreate8(REFIID riid, LPDIRECTSOUNDCAPTURE8 *ppDSC8) DECLSPEC_HIDDEN;
378
379 #define STATE_STOPPED   0
380 #define STATE_STARTING  1
381 #define STATE_PLAYING   2
382 #define STATE_CAPTURING 2
383 #define STATE_STOPPING  3
384
385 #define DSOUND_FREQSHIFT (20)
386
387 extern DirectSoundDevice* DSOUND_renderer[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
388 extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
389
390 extern DirectSoundCaptureDevice * DSOUND_capture[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
391 extern GUID DSOUND_capture_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
392
393 HRESULT mmErr(UINT err) DECLSPEC_HIDDEN;
394 void setup_dsound_options(void) DECLSPEC_HIDDEN;
395 const char * dumpCooperativeLevel(DWORD level) DECLSPEC_HIDDEN;