Added special case for "display" in DRIVER_GetDriverName so that
[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 IDirectSound3DListenerImpl IDirectSound3DListenerImpl;
54 typedef struct IDirectSound3DBufferImpl IDirectSound3DBufferImpl;
55 typedef struct IKsPropertySetImpl IKsPropertySetImpl;
56 typedef struct PrimaryBufferImpl PrimaryBufferImpl;
57
58 /*****************************************************************************
59  * IDirectSound implementation structure
60  */
61 struct IDirectSoundImpl
62 {
63     /* IUnknown fields */
64     ICOM_VFIELD(IDirectSound8);
65     DWORD                      ref;
66     /* IDirectSoundImpl fields */
67     GUID                        guid;
68     PIDSDRIVER                  driver;
69     DSDRIVERDESC                drvdesc;
70     DSDRIVERCAPS                drvcaps;
71     DWORD                       priolevel;
72     WAVEFORMATEX                wfx; /* current main waveformat */
73     HWAVEOUT                    hwo;
74     LPWAVEHDR                   pwave[DS_HEL_FRAGS];
75     UINT                        timerID, pwplay, pwwrite, pwqueue, prebuf, precount;
76     DWORD                       fraglen;
77     PIDSDRIVERBUFFER            hwbuf;
78     LPBYTE                      buffer;
79     DWORD                       writelead, buflen, state, playpos, mixpos;
80     BOOL                        need_remix;
81     int                         nrofbuffers;
82     IDirectSoundBufferImpl**    buffers;
83     IDirectSound3DListenerImpl* listener;
84     RTL_RWLOCK                  lock;
85     CRITICAL_SECTION            mixlock;
86     DSVOLUMEPAN                 volpan;
87 };
88
89 /*****************************************************************************
90  * IDirectSoundBuffer implementation structure
91  */
92 struct IDirectSoundBufferImpl
93 {
94     /* FIXME: document */
95     /* IUnknown fields */
96     ICOM_VFIELD(IDirectSoundBuffer8);
97     DWORD                     ref;
98     /* IDirectSoundBufferImpl fields */
99     IDirectSoundImpl*         dsound;
100     IDirectSoundBufferImpl*   parent;         /* for duplicates */
101     IDirectSound3DBufferImpl* ds3db;
102     IKsPropertySetImpl*       iks;
103     CRITICAL_SECTION          lock;
104     PIDSDRIVERBUFFER          hwbuf;
105     WAVEFORMATEX              wfx;
106     LPBYTE                    buffer;
107     DWORD                     playflags,state,leadin;
108     DWORD                     playpos,startpos,writelead,buflen;
109     DWORD                     nAvgBytesPerSec;
110     DWORD                     freq;
111     DSVOLUMEPAN               volpan, cvolpan;
112     DSBUFFERDESC              dsbd;
113     /* used for frequency conversion (PerfectPitch) */
114     ULONG                     freqAdjust, freqAcc;
115     /* used for intelligent (well, sort of) prebuffering */
116     DWORD                     probably_valid_to, last_playpos;
117     DWORD                     primary_mixpos, buf_mixpos;
118     BOOL                      need_remix;
119     /* IDirectSoundNotifyImpl fields */
120     IDirectSoundNotifyImpl    *notify;
121 };
122
123 HRESULT WINAPI SecondaryBuffer_Create(
124         IDirectSoundImpl *This,
125         IDirectSoundBufferImpl **pdsb,
126         LPDSBUFFERDESC dsbd);
127
128 struct PrimaryBufferImpl {
129         ICOM_VFIELD(IDirectSoundBuffer8);
130         DWORD                   ref;
131         IDirectSoundImpl*       dsound;
132         DSBUFFERDESC            dsbd;
133 };
134
135 HRESULT WINAPI PrimaryBuffer_Create(
136         IDirectSoundImpl *This,
137         PrimaryBufferImpl **pdsb,
138         LPDSBUFFERDESC dsbd);
139
140 /*****************************************************************************
141  * IDirectSoundCapture implementation structure
142  */
143 struct IDirectSoundCaptureImpl
144 {
145     /* IUnknown fields */
146     ICOM_VFIELD(IDirectSoundCapture);
147     DWORD                              ref;
148
149     /* IDirectSoundCaptureImpl fields */
150     GUID                               guid;
151     BOOL                               initialized;
152
153     /* DirectSound driver stuff */
154     PIDSCDRIVER                        driver;
155     DSDRIVERDESC                       drvdesc;
156     DSCDRIVERCAPS                      drvcaps;
157     PIDSCDRIVERBUFFER                  hwbuf;
158
159     /* wave driver info */
160     HWAVEIN                            hwi;
161
162     /* more stuff */
163     LPBYTE                             buffer;
164     DWORD                              buflen;
165     DWORD                              read_position;
166
167     /* FIXME: this should be a pointer because it can be bigger */
168     WAVEFORMATEX                       wfx;
169
170     IDirectSoundCaptureBufferImpl*     capture_buffer;
171     DWORD                              state;
172     LPWAVEHDR                          pwave;
173     int                                nrofpwaves;
174     int                                index;
175     CRITICAL_SECTION                   lock;
176 };
177
178 /*****************************************************************************
179  * IDirectSoundCaptureBuffer implementation structure
180  */
181 struct IDirectSoundCaptureBufferImpl
182 {
183     /* IUnknown fields */
184     ICOM_VFIELD(IDirectSoundCaptureBuffer8);
185     DWORD                              ref;
186
187     /* IDirectSoundCaptureBufferImpl fields */
188     IDirectSoundCaptureImpl*           dsound;
189     /* FIXME: don't need this */
190     LPDSCBUFFERDESC                    pdscbd;
191     DWORD                              flags;
192     /* IDirectSoundNotifyImpl fields */
193     IDirectSoundNotifyImpl             *notify;
194 };
195
196 /*****************************************************************************
197  * IDirectSoundFullDuplex implementation structure
198  */
199 struct IDirectSoundFullDuplexImpl
200 {
201     /* IUnknown fields */
202     ICOM_VFIELD(IDirectSoundFullDuplex);
203     DWORD                              ref;
204
205     /* IDirectSoundFullDuplexImpl fields */
206     CRITICAL_SECTION                   lock;
207 };
208
209 /*****************************************************************************
210  * IDirectSoundNotify implementation structure
211  */
212 struct IDirectSoundNotifyImpl
213 {
214     /* IUnknown fields */
215     ICOM_VFIELD(IDirectSoundNotify);
216     DWORD                            ref;
217     /* IDirectSoundNotifyImpl fields */
218     LPDSBPOSITIONNOTIFY              notifies;
219     int                              nrofnotifies;
220
221     PIDSDRIVERNOTIFY                 hwnotify;
222 };
223
224 /*****************************************************************************
225  *  IDirectSound3DListener implementation structure
226  */
227 struct IDirectSound3DListenerImpl
228 {
229     /* IUnknown fields */
230     ICOM_VFIELD(IDirectSound3DListener);
231     DWORD                                ref;
232     /* IDirectSound3DListenerImpl fields */
233     PrimaryBufferImpl*      dsb;
234     DS3DLISTENER            ds3dl;
235     CRITICAL_SECTION        lock;
236     BOOL                    need_recalc;
237 };
238
239 HRESULT WINAPI IDirectSound3DListenerImpl_Create(
240         PrimaryBufferImpl *This,
241         IDirectSound3DListenerImpl **pdsl);
242
243 /*****************************************************************************
244  *  IKsPropertySet implementation structure
245  */
246 struct IKsPropertySetImpl
247 {
248     /* IUnknown fields */
249     ICOM_VFIELD(IKsPropertySet);
250     DWORD                       ref;
251     /* IKsPropertySetImpl fields */
252     IDirectSoundBufferImpl*     dsb;
253 };
254
255 HRESULT WINAPI IKsPropertySetImpl_Create(
256         IDirectSoundBufferImpl *This,
257         IKsPropertySetImpl **piks);
258
259 /*****************************************************************************
260  * IDirectSound3DBuffer implementation structure
261  */
262 struct IDirectSound3DBufferImpl
263 {
264     /* IUnknown fields */
265     ICOM_VFIELD(IDirectSound3DBuffer);
266     DWORD                              ref;
267     /* IDirectSound3DBufferImpl fields */
268     IDirectSoundBufferImpl* dsb;
269     DS3DBUFFER              ds3db;
270     LONG                    lVolume;
271     CRITICAL_SECTION        lock;
272     BOOL                    need_recalc;
273 };
274
275 HRESULT WINAPI IDirectSound3DBufferImpl_Create(
276         IDirectSoundBufferImpl *This,
277         IDirectSound3DBufferImpl **pds3db);
278
279 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
280 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
281
282 /* primary.c */
283
284 HRESULT DSOUND_PrimaryCreate(IDirectSoundImpl *This);
285 HRESULT DSOUND_PrimaryDestroy(IDirectSoundImpl *This);
286 HRESULT DSOUND_PrimaryPlay(IDirectSoundImpl *This);
287 HRESULT DSOUND_PrimaryStop(IDirectSoundImpl *This);
288 HRESULT DSOUND_PrimaryGetPosition(IDirectSoundImpl *This, LPDWORD playpos, LPDWORD writepos);
289
290 /* buffer.c */
291
292 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
293                               DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix);
294
295 /* mixer.c */
296
297 void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len);
298 void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb);
299 void DSOUND_MixCancelAt(IDirectSoundBufferImpl *dsb, DWORD buf_writepos);
300 void DSOUND_WaveQueue(IDirectSoundImpl *dsound, DWORD mixq);
301 void DSOUND_PerformMix(void);
302 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
303 void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
304
305 #define STATE_STOPPED   0
306 #define STATE_STARTING  1
307 #define STATE_PLAYING   2
308 #define STATE_CAPTURING 2
309 #define STATE_STOPPING  3
310
311 #define DSOUND_FREQSHIFT (14)
312
313 extern IDirectSoundImpl* dsound;
314 extern IDirectSoundCaptureImpl* dsound_capture;
315
316 struct PrimaryBuffer {
317         DWORD ref;
318         PIDSDRIVERBUFFER hwbuf;
319         DWORD state;
320 };
321
322 extern ICOM_VTABLE(IDirectSoundNotify) dsnvt;
323 extern HRESULT mmErr(UINT err);
324 extern void setup_dsound_options(void);