Move control panel applet enumeration to cpanelfolder.c.
[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 IDirectSoundBufferImpl IDirectSoundBufferImpl;
49 typedef struct IDirectSoundCaptureImpl IDirectSoundCaptureImpl;
50 typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl;
51 typedef struct IDirectSoundFullDuplexImpl IDirectSoundFullDuplexImpl;
52 typedef struct IDirectSoundNotifyImpl IDirectSoundNotifyImpl;
53 typedef struct IDirectSoundCaptureNotifyImpl IDirectSoundCaptureNotifyImpl;
54 typedef struct IDirectSound3DListenerImpl IDirectSound3DListenerImpl;
55 typedef struct IDirectSound3DBufferImpl IDirectSound3DBufferImpl;
56 typedef struct IKsBufferPropertySetImpl IKsBufferPropertySetImpl;
57 typedef struct IKsPrivatePropertySetImpl IKsPrivatePropertySetImpl;
58 typedef struct PrimaryBufferImpl PrimaryBufferImpl;
59 typedef struct SecondaryBufferImpl SecondaryBufferImpl;
60 typedef struct IClassFactoryImpl IClassFactoryImpl;
61
62 /*****************************************************************************
63  * IDirectSound implementation structure
64  */
65 struct IDirectSoundImpl
66 {
67     /* IUnknown fields */
68     ICOM_VFIELD(IDirectSound8);
69     DWORD                       ref;
70     /* IDirectSoundImpl fields */
71     GUID                        guid;
72     PIDSDRIVER                  driver;
73     DSDRIVERDESC                drvdesc;
74     DSDRIVERCAPS                drvcaps;
75     DWORD                       priolevel;
76     WAVEFORMATEX                wfx; /* current main waveformat */
77     HWAVEOUT                    hwo;
78     LPWAVEHDR                   pwave[DS_HEL_FRAGS];
79     UINT                        timerID, pwplay, pwwrite, pwqueue, prebuf, precount;
80     DWORD                       fraglen;
81     PIDSDRIVERBUFFER            hwbuf;
82     LPBYTE                      buffer;
83     DWORD                       writelead, buflen, state, playpos, mixpos;
84     BOOL                        need_remix;
85     int                         nrofbuffers;
86     IDirectSoundBufferImpl**    buffers;
87     RTL_RWLOCK                  lock;
88     CRITICAL_SECTION            mixlock;
89     DSVOLUMEPAN                 volpan;
90     PrimaryBufferImpl*          primary;
91     DSBUFFERDESC                dsbd;
92     DWORD                       speaker_config;
93
94     /* DirectSound3DListener fields */
95     IDirectSound3DListenerImpl* listener;
96     DS3DLISTENER                ds3dl;
97     BOOL                        ds3dl_need_recalc;
98 };
99
100 /* reference counted buffer memory for duplicated buffer memory */
101 typedef struct BufferMemory
102 {
103     DWORD                       ref;
104     LPBYTE                      memory;
105 } BufferMemory;
106
107 /*****************************************************************************
108  * IDirectSoundBuffer implementation structure
109  */
110 struct IDirectSoundBufferImpl
111 {
112     /* FIXME: document */
113     /* IUnknown fields */
114     ICOM_VFIELD(IDirectSoundBuffer8);
115     DWORD                       ref;
116     /* IDirectSoundBufferImpl fields */
117     SecondaryBufferImpl*        dsb;
118     IDirectSoundImpl*           dsound;
119     CRITICAL_SECTION            lock;
120     PIDSDRIVERBUFFER            hwbuf;
121     WAVEFORMATEX                wfx;
122     BufferMemory*               buffer;
123     DWORD                       playflags,state,leadin;
124     DWORD                       playpos,startpos,writelead,buflen;
125     DWORD                       nAvgBytesPerSec;
126     DWORD                       freq;
127     DSVOLUMEPAN                 volpan, cvolpan;
128     DSBUFFERDESC                dsbd;
129     /* used for frequency conversion (PerfectPitch) */
130     ULONG                       freqAdjust, freqAcc;
131     /* used for intelligent (well, sort of) prebuffering */
132     DWORD                       probably_valid_to, last_playpos;
133     DWORD                       primary_mixpos, buf_mixpos;
134     BOOL                        need_remix;
135
136     /* IDirectSoundNotifyImpl fields */
137     IDirectSoundNotifyImpl*     notify;
138     LPDSBPOSITIONNOTIFY         notifies;
139     int                         nrofnotifies;
140     PIDSDRIVERNOTIFY            hwnotify;
141
142     /* DirectSound3DBuffer fields */
143     IDirectSound3DBufferImpl*   ds3db;
144     DS3DBUFFER                  ds3db_ds3db;
145     LONG                        ds3db_lVolume;
146     BOOL                        ds3db_need_recalc;
147
148     /* IKsPropertySet fields */
149     IKsBufferPropertySetImpl*   iks;
150 };
151
152 HRESULT WINAPI IDirectSoundBufferImpl_Create(
153     IDirectSoundImpl *ds,
154     IDirectSoundBufferImpl **pdsb,
155     LPCDSBUFFERDESC dsbd);
156
157 /*****************************************************************************
158  * SecondaryBuffer implementation structure
159  */
160 struct SecondaryBufferImpl
161 {
162     ICOM_VFIELD(IDirectSoundBuffer8);
163     DWORD                       ref;
164     IDirectSoundBufferImpl*     dsb;
165 };
166
167 HRESULT WINAPI SecondaryBufferImpl_Create(
168     IDirectSoundBufferImpl *dsb,
169     SecondaryBufferImpl **pdsb);
170
171 /*****************************************************************************
172  * PrimaryBuffer implementation structure
173  */
174 struct PrimaryBufferImpl
175 {
176     ICOM_VFIELD(IDirectSoundBuffer8);
177     DWORD                       ref;
178     IDirectSoundImpl*           dsound;
179 };
180
181 HRESULT WINAPI PrimaryBufferImpl_Create(
182     IDirectSoundImpl *ds,
183     PrimaryBufferImpl **pdsb,
184     LPCDSBUFFERDESC dsbd);
185
186 /*****************************************************************************
187  * IDirectSoundCapture implementation structure
188  */
189 struct IDirectSoundCaptureImpl
190 {
191     /* IUnknown fields */
192     ICOM_VFIELD(IDirectSoundCapture);
193     DWORD                              ref;
194
195     /* IDirectSoundCaptureImpl fields */
196     GUID                               guid;
197     BOOL                               initialized;
198
199     /* DirectSound driver stuff */
200     PIDSCDRIVER                        driver;
201     DSDRIVERDESC                       drvdesc;
202     DSCDRIVERCAPS                      drvcaps;
203     PIDSCDRIVERBUFFER                  hwbuf;
204
205     /* wave driver info */
206     HWAVEIN                            hwi;
207
208     /* more stuff */
209     LPBYTE                             buffer;
210     DWORD                              buflen;
211     DWORD                              read_position;
212
213     PWAVEFORMATEX                      pwfx;
214
215     IDirectSoundCaptureBufferImpl*     capture_buffer;
216     DWORD                              state;
217     LPWAVEHDR                          pwave;
218     int                                nrofpwaves;
219     int                                index;
220     CRITICAL_SECTION                   lock;
221 };
222
223 /*****************************************************************************
224  * IDirectSoundCaptureBuffer implementation structure
225  */
226 struct IDirectSoundCaptureBufferImpl
227 {
228     /* IUnknown fields */
229     ICOM_VFIELD(IDirectSoundCaptureBuffer8);
230     DWORD                               ref;
231
232     /* IDirectSoundCaptureBufferImpl fields */
233     IDirectSoundCaptureImpl*            dsound;
234     /* FIXME: don't need this */
235     LPDSCBUFFERDESC                     pdscbd;
236     DWORD                               flags;
237
238     /* IDirectSoundCaptureNotifyImpl fields */
239     IDirectSoundCaptureNotifyImpl*      notify;
240     LPDSBPOSITIONNOTIFY                 notifies;
241     int                                 nrofnotifies;
242     PIDSDRIVERNOTIFY                    hwnotify;
243 };
244
245 /*****************************************************************************
246  * IDirectSoundFullDuplex implementation structure
247  */
248 struct IDirectSoundFullDuplexImpl
249 {
250     /* IUnknown fields */
251     ICOM_VFIELD(IDirectSoundFullDuplex);
252     DWORD                       ref;
253
254     /* IDirectSoundFullDuplexImpl fields */
255     CRITICAL_SECTION            lock;
256 };
257
258 /*****************************************************************************
259  * IDirectSoundNotify implementation structure
260  */
261 struct IDirectSoundNotifyImpl
262 {
263     /* IUnknown fields */
264     ICOM_VFIELD(IDirectSoundNotify);
265     DWORD                       ref;
266     IDirectSoundBufferImpl*     dsb;
267 };
268
269 HRESULT WINAPI IDirectSoundNotifyImpl_Create(
270     IDirectSoundBufferImpl *dsb,
271     IDirectSoundNotifyImpl **pdsn);
272
273 /*****************************************************************************
274  * IDirectSoundCaptureNotify implementation structure
275  */
276 struct IDirectSoundCaptureNotifyImpl
277 {
278     /* IUnknown fields */
279     ICOM_VFIELD(IDirectSoundNotify);
280     DWORD                               ref;
281     IDirectSoundCaptureBufferImpl*      dscb;
282 };
283
284 HRESULT WINAPI IDirectSoundCaptureNotifyImpl_Create(
285     IDirectSoundCaptureBufferImpl *dscb,
286     IDirectSoundCaptureNotifyImpl ** pdscn);
287
288 /*****************************************************************************
289  *  IDirectSound3DListener implementation structure
290  */
291 struct IDirectSound3DListenerImpl
292 {
293     /* IUnknown fields */
294     ICOM_VFIELD(IDirectSound3DListener);
295     DWORD                       ref;
296     /* IDirectSound3DListenerImpl fields */
297     IDirectSoundImpl*           dsound;
298 };
299
300 HRESULT WINAPI IDirectSound3DListenerImpl_Create(
301     PrimaryBufferImpl *pb,
302     IDirectSound3DListenerImpl **pdsl);
303
304 /*****************************************************************************
305  *  IKsBufferPropertySet implementation structure
306  */
307 struct IKsBufferPropertySetImpl
308 {
309     /* IUnknown fields */
310     ICOM_VFIELD(IKsPropertySet);
311     DWORD                       ref;
312     /* IKsPropertySetImpl fields */
313     IDirectSoundBufferImpl*     dsb;
314 };
315
316 HRESULT WINAPI IKsBufferPropertySetImpl_Create(
317     IDirectSoundBufferImpl *dsb,
318     IKsBufferPropertySetImpl **piks);
319
320 /*****************************************************************************
321  *  IKsPrivatePropertySet implementation structure
322  */
323 struct IKsPrivatePropertySetImpl
324 {
325     /* IUnknown fields */
326     ICOM_VFIELD(IKsPropertySet);
327     DWORD                       ref;
328 };
329
330 HRESULT WINAPI IKsPrivatePropertySetImpl_Create(
331     IKsPrivatePropertySetImpl **piks);
332
333 /*****************************************************************************
334  * IDirectSound3DBuffer implementation structure
335  */
336 struct IDirectSound3DBufferImpl
337 {
338     /* IUnknown fields */
339     ICOM_VFIELD(IDirectSound3DBuffer);
340     DWORD                       ref;
341     /* IDirectSound3DBufferImpl fields */
342     IDirectSoundBufferImpl*     dsb;
343 };
344
345 HRESULT WINAPI IDirectSound3DBufferImpl_Create(
346     IDirectSoundBufferImpl *dsb,
347     IDirectSound3DBufferImpl **pds3db);
348
349 /*******************************************************************************
350  * DirectSound ClassFactory implementation structure
351  */
352 struct IClassFactoryImpl
353 {
354     /* IUnknown fields */
355     ICOM_VFIELD(IClassFactory);
356     DWORD                       ref;
357 };
358
359 extern IClassFactoryImpl DSOUND_CAPTURE_CF;
360 extern IClassFactoryImpl DSOUND_FULLDUPLEX_CF;
361
362 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
363 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
364
365 /* primary.c */
366
367 HRESULT DSOUND_PrimaryCreate(IDirectSoundImpl *This);
368 HRESULT DSOUND_PrimaryDestroy(IDirectSoundImpl *This);
369 HRESULT DSOUND_PrimaryPlay(IDirectSoundImpl *This);
370 HRESULT DSOUND_PrimaryStop(IDirectSoundImpl *This);
371 HRESULT DSOUND_PrimaryGetPosition(IDirectSoundImpl *This, LPDWORD playpos, LPDWORD writepos);
372
373 /* buffer.c */
374
375 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
376                               DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix);
377
378 /* mixer.c */
379
380 void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len);
381 void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb);
382 void DSOUND_MixCancelAt(IDirectSoundBufferImpl *dsb, DWORD buf_writepos);
383 void DSOUND_WaveQueue(IDirectSoundImpl *dsound, DWORD mixq);
384 void DSOUND_PerformMix(IDirectSoundImpl *dsound);
385 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
386 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
387
388 /* sound3d.c */
389
390 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb);
391
392 #define STATE_STOPPED   0
393 #define STATE_STARTING  1
394 #define STATE_PLAYING   2
395 #define STATE_CAPTURING 2
396 #define STATE_STOPPING  3
397
398 #define DSOUND_FREQSHIFT (14)
399
400 extern IDirectSoundImpl* dsound;
401
402 extern HRESULT mmErr(UINT err);
403 extern void setup_dsound_options(void);