Removed W->A from DEFWND_ImmIsUIMessageW.
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 /* Linux does not support better timing than 10ms */
23 #define DS_TIME_RES 10  /* Resolution of multimedia timer */
24 #define DS_TIME_DEL 10  /* Delay of multimedia timer callback, and duration of HEL fragment */
25
26 #define DS_HEL_FRAGS 48 /* HEL only: number of waveOut fragments in primary buffer
27                          * (changing this won't help you) */
28
29 /* direct sound hardware acceleration levels */
30 #define DS_HW_ACCEL_FULL        0       /* default on Windows 98 */
31 #define DS_HW_ACCEL_STANDARD    1       /* default on Windows 2000 */
32 #define DS_HW_ACCEL_BASIC       2
33 #define DS_HW_ACCEL_EMULATION   3
34
35 extern int ds_emuldriver;
36 extern int ds_hel_margin;
37 extern int ds_hel_queue;
38 extern int ds_snd_queue_max;
39 extern int ds_snd_queue_min;
40 extern int ds_hw_accel;
41 extern int ds_default_playback;
42 extern int ds_default_capture;
43
44 /*****************************************************************************
45  * Predeclare the interface implementation structures
46  */
47 typedef struct IDirectSoundImpl              IDirectSoundImpl;
48 typedef struct IDirectSound_IUnknown         IDirectSound_IUnknown;
49 typedef struct IDirectSound_IDirectSound     IDirectSound_IDirectSound;
50 typedef struct IDirectSound8_IUnknown        IDirectSound8_IUnknown;
51 typedef struct IDirectSound8_IDirectSound    IDirectSound8_IDirectSound;
52 typedef struct IDirectSound8_IDirectSound8   IDirectSound8_IDirectSound8;
53 typedef struct IDirectSoundBufferImpl        IDirectSoundBufferImpl;
54 typedef struct IDirectSoundCaptureImpl       IDirectSoundCaptureImpl;
55 typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl;
56 typedef struct IDirectSoundFullDuplexImpl    IDirectSoundFullDuplexImpl;
57 typedef struct IDirectSoundNotifyImpl        IDirectSoundNotifyImpl;
58 typedef struct IDirectSoundCaptureNotifyImpl IDirectSoundCaptureNotifyImpl;
59 typedef struct IDirectSound3DListenerImpl    IDirectSound3DListenerImpl;
60 typedef struct IDirectSound3DBufferImpl      IDirectSound3DBufferImpl;
61 typedef struct IKsBufferPropertySetImpl      IKsBufferPropertySetImpl;
62 typedef struct IKsPrivatePropertySetImpl     IKsPrivatePropertySetImpl;
63 typedef struct PrimaryBufferImpl             PrimaryBufferImpl;
64 typedef struct SecondaryBufferImpl           SecondaryBufferImpl;
65 typedef struct IClassFactoryImpl             IClassFactoryImpl;
66
67 /*****************************************************************************
68  * IDirectSound implementation structure
69  */
70 struct IDirectSoundImpl
71 {
72     /* IUnknown fields */
73     IDirectSound8Vtbl          *lpVtbl;
74     DWORD                       ref;
75     /* IDirectSoundImpl fields */
76     GUID                        guid;
77     PIDSDRIVER                  driver;
78     DSDRIVERDESC                drvdesc;
79     DSDRIVERCAPS                drvcaps;
80     DWORD                       priolevel;
81     PWAVEFORMATEX               pwfx;
82     HWAVEOUT                    hwo;
83     LPWAVEHDR                   pwave[DS_HEL_FRAGS];
84     UINT                        timerID, pwplay, pwwrite, pwqueue, prebuf, precount;
85     DWORD                       fraglen;
86     PIDSDRIVERBUFFER            hwbuf;
87     LPBYTE                      buffer;
88     DWORD                       writelead, buflen, state, playpos, mixpos;
89     BOOL                        need_remix;
90     int                         nrofbuffers;
91     IDirectSoundBufferImpl**    buffers;
92     RTL_RWLOCK                  buffer_list_lock;
93     CRITICAL_SECTION            mixlock;
94     PrimaryBufferImpl*          primary;
95     DSBUFFERDESC                dsbd;
96     DWORD                       speaker_config;
97     BOOL                        initialized;
98
99     /* DirectSound3DListener fields */
100     IDirectSound3DListenerImpl* listener;
101     DS3DLISTENER                ds3dl;
102     BOOL                        ds3dl_need_recalc;
103
104     LPUNKNOWN                   pUnknown;
105     LPDIRECTSOUND               pDS;
106     LPDIRECTSOUND8              pDS8;
107 };
108
109 /* reference counted buffer memory for duplicated buffer memory */
110 typedef struct BufferMemory
111 {
112     DWORD                       ref;
113     LPBYTE                      memory;
114 } BufferMemory;
115
116 HRESULT WINAPI IDirectSoundImpl_Create(
117     LPCGUID lpcGUID,
118     LPDIRECTSOUND8 * ppds);
119
120 HRESULT WINAPI DSOUND_Create(
121     LPCGUID lpcGUID,
122     LPDIRECTSOUND *ppDS,
123     IUnknown *pUnkOuter);
124
125 HRESULT WINAPI DSOUND_Create8(
126     LPCGUID lpcGUID,
127     LPDIRECTSOUND8 *ppDS,
128     IUnknown *pUnkOuter);
129
130 /*****************************************************************************
131  * IDirectSound COM components
132  */
133 struct IDirectSound_IUnknown {
134     IUnknownVtbl               *lpVtbl;
135     DWORD                       ref;
136     LPDIRECTSOUND8              pds;
137 };
138
139 HRESULT WINAPI IDirectSound_IUnknown_Create(
140     LPDIRECTSOUND8 pds,
141     LPUNKNOWN * ppunk);
142
143 struct IDirectSound_IDirectSound {
144     IDirectSoundVtbl           *lpVtbl;
145     DWORD                       ref;
146     LPDIRECTSOUND8              pds;
147 };
148
149 HRESULT WINAPI IDirectSound_IDirectSound_Create(
150     LPDIRECTSOUND8 pds,
151     LPDIRECTSOUND * ppds);
152
153 /*****************************************************************************
154  * IDirectSound8 COM components
155  */
156 struct IDirectSound8_IUnknown {
157     IUnknownVtbl               *lpVtbl;
158     DWORD                       ref;
159     LPDIRECTSOUND8              pds;
160 };
161
162 HRESULT WINAPI IDirectSound8_IUnknown_Create(
163     LPDIRECTSOUND8 pds,
164     LPUNKNOWN * ppunk);
165
166 struct IDirectSound8_IDirectSound {
167     IDirectSoundVtbl           *lpVtbl;
168     DWORD                       ref;
169     LPDIRECTSOUND8              pds;
170 };
171
172 HRESULT WINAPI IDirectSound8_IDirectSound_Create(
173     LPDIRECTSOUND8 pds,
174     LPDIRECTSOUND * ppds);
175
176 struct IDirectSound8_IDirectSound8 {
177     IDirectSound8Vtbl          *lpVtbl;
178     DWORD                       ref;
179     LPDIRECTSOUND8              pds;
180 };
181
182 HRESULT WINAPI IDirectSound8_IDirectSound8_Create(
183     LPDIRECTSOUND8 pds,
184     LPDIRECTSOUND8 * ppds);
185
186 /*****************************************************************************
187  * IDirectSoundBuffer implementation structure
188  */
189 struct IDirectSoundBufferImpl
190 {
191     /* FIXME: document */
192     /* IUnknown fields */
193     IDirectSoundBuffer8Vtbl    *lpVtbl;
194     DWORD                       ref;
195     /* IDirectSoundBufferImpl fields */
196     SecondaryBufferImpl*        dsb;
197     IDirectSoundImpl*           dsound;
198     CRITICAL_SECTION            lock;
199     PIDSDRIVERBUFFER            hwbuf;
200     PWAVEFORMATEX               pwfx;
201     BufferMemory*               buffer;
202     DWORD                       playflags,state,leadin;
203     DWORD                       playpos,startpos,writelead,buflen;
204     DWORD                       nAvgBytesPerSec;
205     DWORD                       freq;
206     DSVOLUMEPAN                 volpan, cvolpan;
207     DSBUFFERDESC                dsbd;
208     /* used for frequency conversion (PerfectPitch) */
209     ULONG                       freqAdjust, freqAcc;
210     /* used for intelligent (well, sort of) prebuffering */
211     DWORD                       probably_valid_to, last_playpos;
212     DWORD                       primary_mixpos, buf_mixpos;
213     BOOL                        need_remix;
214
215     /* IDirectSoundNotifyImpl fields */
216     IDirectSoundNotifyImpl*     notify;
217     LPDSBPOSITIONNOTIFY         notifies;
218     int                         nrofnotifies;
219     PIDSDRIVERNOTIFY            hwnotify;
220
221     /* DirectSound3DBuffer fields */
222     IDirectSound3DBufferImpl*   ds3db;
223     DS3DBUFFER                  ds3db_ds3db;
224     LONG                        ds3db_lVolume;
225     BOOL                        ds3db_need_recalc;
226
227     /* IKsPropertySet fields */
228     IKsBufferPropertySetImpl*   iks;
229 };
230
231 HRESULT WINAPI IDirectSoundBufferImpl_Create(
232     IDirectSoundImpl *ds,
233     IDirectSoundBufferImpl **pdsb,
234     LPCDSBUFFERDESC dsbd);
235 HRESULT WINAPI IDirectSoundBufferImpl_Destroy(
236     IDirectSoundBufferImpl *pdsb);
237
238 /*****************************************************************************
239  * SecondaryBuffer implementation structure
240  */
241 struct SecondaryBufferImpl
242 {
243     IDirectSoundBuffer8Vtbl    *lpVtbl;
244     DWORD                       ref;
245     IDirectSoundBufferImpl*     dsb;
246 };
247
248 HRESULT WINAPI SecondaryBufferImpl_Create(
249     IDirectSoundBufferImpl *dsb,
250     SecondaryBufferImpl **pdsb);
251 HRESULT WINAPI SecondaryBufferImpl_Destroy(
252     SecondaryBufferImpl *pdsb);
253
254 /*****************************************************************************
255  * PrimaryBuffer implementation structure
256  */
257 struct PrimaryBufferImpl
258 {
259     IDirectSoundBuffer8Vtbl    *lpVtbl;
260     DWORD                       ref;
261     IDirectSoundImpl*           dsound;
262 };
263
264 HRESULT WINAPI PrimaryBufferImpl_Create(
265     IDirectSoundImpl *ds,
266     PrimaryBufferImpl **pdsb,
267     LPCDSBUFFERDESC dsbd);
268
269 /*****************************************************************************
270  * IDirectSoundCapture implementation structure
271  */
272 struct IDirectSoundCaptureImpl
273 {
274     /* IUnknown fields */
275     IDirectSoundCaptureVtbl           *lpVtbl;
276     DWORD                              ref;
277
278     /* IDirectSoundCaptureImpl fields */
279     GUID                               guid;
280     BOOL                               initialized;
281
282     /* DirectSound driver stuff */
283     PIDSCDRIVER                        driver;
284     DSDRIVERDESC                       drvdesc;
285     DSCDRIVERCAPS                      drvcaps;
286     PIDSCDRIVERBUFFER                  hwbuf;
287
288     /* wave driver info */
289     HWAVEIN                            hwi;
290
291     /* more stuff */
292     LPBYTE                             buffer;
293     DWORD                              buflen;
294     DWORD                              read_position;
295
296     PWAVEFORMATEX                      pwfx;
297
298     IDirectSoundCaptureBufferImpl*     capture_buffer;
299     DWORD                              state;
300     LPWAVEHDR                          pwave;
301     int                                nrofpwaves;
302     int                                index;
303     CRITICAL_SECTION                   lock;
304 };
305
306 /*****************************************************************************
307  * IDirectSoundCaptureBuffer implementation structure
308  */
309 struct IDirectSoundCaptureBufferImpl
310 {
311     /* IUnknown fields */
312     IDirectSoundCaptureBuffer8Vtbl     *lpVtbl;
313     DWORD                               ref;
314
315     /* IDirectSoundCaptureBufferImpl fields */
316     IDirectSoundCaptureImpl*            dsound;
317     /* FIXME: don't need this */
318     LPDSCBUFFERDESC                     pdscbd;
319     DWORD                               flags;
320
321     /* IDirectSoundCaptureNotifyImpl fields */
322     IDirectSoundCaptureNotifyImpl*      notify;
323     LPDSBPOSITIONNOTIFY                 notifies;
324     int                                 nrofnotifies;
325     PIDSDRIVERNOTIFY                    hwnotify;
326 };
327
328 /*****************************************************************************
329  * IDirectSoundFullDuplex implementation structure
330  */
331 struct IDirectSoundFullDuplexImpl
332 {
333     /* IUnknown fields */
334     IDirectSoundFullDuplexVtbl *lpVtbl;
335     DWORD                       ref;
336
337     /* IDirectSoundFullDuplexImpl fields */
338     CRITICAL_SECTION            lock;
339 };
340
341 /*****************************************************************************
342  * IDirectSoundNotify implementation structure
343  */
344 struct IDirectSoundNotifyImpl
345 {
346     /* IUnknown fields */
347     IDirectSoundNotifyVtbl     *lpVtbl;
348     DWORD                       ref;
349     IDirectSoundBufferImpl*     dsb;
350 };
351
352 HRESULT WINAPI IDirectSoundNotifyImpl_Create(
353     IDirectSoundBufferImpl *dsb,
354     IDirectSoundNotifyImpl **pdsn);
355 HRESULT WINAPI IDirectSoundNotifyImpl_Destroy(
356     IDirectSoundNotifyImpl *pdsn);
357
358 /*****************************************************************************
359  * IDirectSoundCaptureNotify implementation structure
360  */
361 struct IDirectSoundCaptureNotifyImpl
362 {
363     /* IUnknown fields */
364     IDirectSoundNotifyVtbl             *lpVtbl;
365     DWORD                               ref;
366     IDirectSoundCaptureBufferImpl*      dscb;
367 };
368
369 HRESULT WINAPI IDirectSoundCaptureNotifyImpl_Create(
370     IDirectSoundCaptureBufferImpl *dscb,
371     IDirectSoundCaptureNotifyImpl ** pdscn);
372
373 /*****************************************************************************
374  *  IDirectSound3DListener implementation structure
375  */
376 struct IDirectSound3DListenerImpl
377 {
378     /* IUnknown fields */
379     IDirectSound3DListenerVtbl *lpVtbl;
380     DWORD                       ref;
381     /* IDirectSound3DListenerImpl fields */
382     IDirectSoundImpl*           dsound;
383 };
384
385 HRESULT WINAPI IDirectSound3DListenerImpl_Create(
386     PrimaryBufferImpl *pb,
387     IDirectSound3DListenerImpl **pdsl);
388
389 /*****************************************************************************
390  *  IKsBufferPropertySet implementation structure
391  */
392 struct IKsBufferPropertySetImpl
393 {
394     /* IUnknown fields */
395     IKsPropertySetVtbl         *lpVtbl;
396     DWORD                       ref;
397     /* IKsPropertySetImpl fields */
398     IDirectSoundBufferImpl*     dsb;
399 };
400
401 HRESULT WINAPI IKsBufferPropertySetImpl_Create(
402     IDirectSoundBufferImpl *dsb,
403     IKsBufferPropertySetImpl **piks);
404 HRESULT WINAPI IKsBufferPropertySetImpl_Destroy(
405     IKsBufferPropertySetImpl *piks);
406
407 /*****************************************************************************
408  *  IKsPrivatePropertySet implementation structure
409  */
410 struct IKsPrivatePropertySetImpl
411 {
412     /* IUnknown fields */
413     IKsPropertySetVtbl         *lpVtbl;
414     DWORD                       ref;
415 };
416
417 HRESULT WINAPI IKsPrivatePropertySetImpl_Create(
418     IKsPrivatePropertySetImpl **piks);
419
420 /*****************************************************************************
421  * IDirectSound3DBuffer implementation structure
422  */
423 struct IDirectSound3DBufferImpl
424 {
425     /* IUnknown fields */
426     IDirectSound3DBufferVtbl   *lpVtbl;
427     DWORD                       ref;
428     /* IDirectSound3DBufferImpl fields */
429     IDirectSoundBufferImpl*     dsb;
430 };
431
432 HRESULT WINAPI IDirectSound3DBufferImpl_Create(
433     IDirectSoundBufferImpl *dsb,
434     IDirectSound3DBufferImpl **pds3db);
435 HRESULT WINAPI IDirectSound3DBufferImpl_Destroy(
436     IDirectSound3DBufferImpl *pds3db);
437
438 /*******************************************************************************
439  * DirectSound ClassFactory implementation structure
440  */
441 struct IClassFactoryImpl
442 {
443     /* IUnknown fields */
444     IClassFactoryVtbl          *lpVtbl;
445     DWORD                       ref;
446 };
447
448 extern IClassFactoryImpl DSOUND_CAPTURE_CF;
449 extern IClassFactoryImpl DSOUND_FULLDUPLEX_CF;
450
451 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
452 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan);
453 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
454
455 /* dsound.c */
456
457 HRESULT DSOUND_AddBuffer(IDirectSoundImpl * pDS, IDirectSoundBufferImpl * pDSB);
458 HRESULT DSOUND_RemoveBuffer(IDirectSoundImpl * pDS, IDirectSoundBufferImpl * pDSB);
459
460 /* primary.c */
461
462 HRESULT DSOUND_PrimaryCreate(IDirectSoundImpl *This);
463 HRESULT DSOUND_PrimaryDestroy(IDirectSoundImpl *This);
464 HRESULT DSOUND_PrimaryPlay(IDirectSoundImpl *This);
465 HRESULT DSOUND_PrimaryStop(IDirectSoundImpl *This);
466 HRESULT DSOUND_PrimaryGetPosition(IDirectSoundImpl *This, LPDWORD playpos, LPDWORD writepos);
467
468 /* buffer.c */
469
470 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
471                               DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix);
472
473 /* mixer.c */
474
475 void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len);
476 void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb);
477 void DSOUND_MixCancelAt(IDirectSoundBufferImpl *dsb, DWORD buf_writepos);
478 void DSOUND_WaveQueue(IDirectSoundImpl *dsound, DWORD mixq);
479 void DSOUND_PerformMix(IDirectSoundImpl *dsound);
480 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
481 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
482
483 /* sound3d.c */
484
485 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb);
486
487 #define STATE_STOPPED   0
488 #define STATE_STARTING  1
489 #define STATE_PLAYING   2
490 #define STATE_CAPTURING 2
491 #define STATE_STOPPING  3
492
493 #define DSOUND_FREQSHIFT (14)
494
495 extern IDirectSoundImpl* dsound;
496
497 extern GUID renderer_guids[MAXWAVEDRIVERS];
498 extern GUID capture_guids[MAXWAVEDRIVERS];
499
500 extern HRESULT mmErr(UINT err);
501 extern void setup_dsound_options(void);
502 extern const char * get_device_id(LPCGUID pGuid);