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