gdi32: Don't use the DC colors when drawing a monochrome pattern to a monochrome...
[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 "wingdi.h"
27 #include "mmdeviceapi.h"
28 #include "audioclient.h"
29 #include "mmsystem.h"
30
31 #include "wine/list.h"
32
33 extern int ds_hel_buflen DECLSPEC_HIDDEN;
34 extern int ds_snd_queue_max DECLSPEC_HIDDEN;
35 extern int ds_snd_shadow_maxsize DECLSPEC_HIDDEN;
36 extern int ds_default_sample_rate DECLSPEC_HIDDEN;
37 extern int ds_default_bits_per_sample DECLSPEC_HIDDEN;
38
39 /*****************************************************************************
40  * Predeclare the interface implementation structures
41  */
42 typedef struct IDirectSoundImpl              IDirectSoundImpl;
43 typedef struct IDirectSound_IUnknown         IDirectSound_IUnknown;
44 typedef struct IDirectSound_IDirectSound     IDirectSound_IDirectSound;
45 typedef struct IDirectSound8_IUnknown        IDirectSound8_IUnknown;
46 typedef struct IDirectSound8_IDirectSound    IDirectSound8_IDirectSound;
47 typedef struct IDirectSound8_IDirectSound8   IDirectSound8_IDirectSound8;
48 typedef struct IDirectSoundBufferImpl        IDirectSoundBufferImpl;
49 typedef struct IDirectSoundCaptureImpl       IDirectSoundCaptureImpl;
50 typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl;
51 typedef struct DirectSoundDevice             DirectSoundDevice;
52 typedef struct DirectSoundCaptureDevice      DirectSoundCaptureDevice;
53
54 /* dsound_convert.h */
55 typedef float (*bitsgetfunc)(const IDirectSoundBufferImpl *, DWORD, DWORD);
56 typedef void (*bitsputfunc)(const IDirectSoundBufferImpl *, DWORD, DWORD, float);
57 extern const bitsgetfunc getbpp[5] DECLSPEC_HIDDEN;
58 void putieee32(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) DECLSPEC_HIDDEN;
59 void mixieee32(float *src, float *dst, unsigned samples) DECLSPEC_HIDDEN;
60 typedef void (*normfunc)(const void *, void *, unsigned);
61 extern const normfunc normfunctions[5] DECLSPEC_HIDDEN;
62
63 typedef struct _DSVOLUMEPAN
64 {
65     DWORD       dwTotalLeftAmpFactor;
66     DWORD       dwTotalRightAmpFactor;
67     LONG        lVolume;
68     DWORD       dwVolAmpFactor;
69     LONG        lPan;
70     DWORD       dwPanLeftAmpFactor;
71     DWORD       dwPanRightAmpFactor;
72 } DSVOLUMEPAN,*PDSVOLUMEPAN;
73
74 /*****************************************************************************
75  * IDirectSoundDevice implementation structure
76  */
77 struct DirectSoundDevice
78 {
79     LONG                        ref;
80
81     GUID                        guid;
82     DSCAPS                      drvcaps;
83     DWORD                       priolevel;
84     PWAVEFORMATEX               pwfx;
85     UINT                        timerID, playing_offs_bytes, in_mmdev_bytes, prebuf, helfrags;
86     DWORD                       fraglen;
87     LPBYTE                      buffer;
88     DWORD                       writelead, buflen, state, playpos, mixpos;
89     int                         nrofbuffers;
90     IDirectSoundBufferImpl**    buffers;
91     RTL_RWLOCK                  buffer_list_lock;
92     CRITICAL_SECTION            mixlock;
93     IDirectSoundBufferImpl     *primary;
94     DWORD                       speaker_config;
95     float *mix_buffer, *tmp_buffer;
96     DWORD                       tmp_buffer_len, mix_buffer_len;
97
98     DSVOLUMEPAN                 volpan;
99
100     normfunc normfunction;
101
102     /* DirectSound3DListener fields */
103     DS3DLISTENER                ds3dl;
104     BOOL                        ds3dl_need_recalc;
105
106     IMMDevice *mmdevice;
107     IAudioClient *client;
108     IAudioClock *clock;
109     IAudioStreamVolume *volume;
110     IAudioRenderClient *render;
111
112     struct list entry;
113 };
114
115 /* reference counted buffer memory for duplicated buffer memory */
116 typedef struct BufferMemory
117 {
118     LONG                        ref;
119     LPBYTE                      memory;
120     struct list buffers;
121 } BufferMemory;
122
123 ULONG DirectSoundDevice_Release(DirectSoundDevice * device) DECLSPEC_HIDDEN;
124 HRESULT DirectSoundDevice_Initialize(
125     DirectSoundDevice ** ppDevice,
126     LPCGUID lpcGUID) DECLSPEC_HIDDEN;
127 HRESULT DirectSoundDevice_AddBuffer(
128     DirectSoundDevice * device,
129     IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
130 HRESULT DirectSoundDevice_RemoveBuffer(
131     DirectSoundDevice * device,
132     IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
133 HRESULT DirectSoundDevice_GetCaps(DirectSoundDevice * device, LPDSCAPS lpDSCaps) DECLSPEC_HIDDEN;
134 HRESULT DirectSoundDevice_CreateSoundBuffer(
135     DirectSoundDevice * device,
136     LPCDSBUFFERDESC dsbd,
137     LPLPDIRECTSOUNDBUFFER ppdsb,
138     LPUNKNOWN lpunk,
139     BOOL from8) DECLSPEC_HIDDEN;
140 HRESULT DirectSoundDevice_DuplicateSoundBuffer(
141     DirectSoundDevice * device,
142     LPDIRECTSOUNDBUFFER psb,
143     LPLPDIRECTSOUNDBUFFER ppdsb) DECLSPEC_HIDDEN;
144 HRESULT DirectSoundDevice_SetCooperativeLevel(
145     DirectSoundDevice * devcie,
146     HWND hwnd,
147     DWORD level) DECLSPEC_HIDDEN;
148 HRESULT DirectSoundDevice_Compact(DirectSoundDevice * device) DECLSPEC_HIDDEN;
149 HRESULT DirectSoundDevice_GetSpeakerConfig(
150     DirectSoundDevice * device,
151     LPDWORD lpdwSpeakerConfig) DECLSPEC_HIDDEN;
152 HRESULT DirectSoundDevice_SetSpeakerConfig(
153     DirectSoundDevice * device,
154     DWORD config) DECLSPEC_HIDDEN;
155 HRESULT DirectSoundDevice_VerifyCertification(DirectSoundDevice * device,
156     LPDWORD pdwCertified) DECLSPEC_HIDDEN;
157
158 /*****************************************************************************
159  * IDirectSoundBuffer implementation structure
160  */
161 struct IDirectSoundBufferImpl
162 {
163     IDirectSoundBuffer8         IDirectSoundBuffer8_iface;
164     IDirectSoundNotify          IDirectSoundNotify_iface;
165     IDirectSound3DListener      IDirectSound3DListener_iface; /* only primary buffer */
166     IDirectSound3DBuffer        IDirectSound3DBuffer_iface; /* only secondary buffer */
167     IKsPropertySet              IKsPropertySet_iface;
168     LONG                        numIfaces; /* "in use interfaces" refcount */
169     LONG                        ref, refn, ref3D, refiks;
170     /* IDirectSoundBufferImpl fields */
171     DirectSoundDevice*          device;
172     RTL_RWLOCK                  lock;
173     PWAVEFORMATEX               pwfx;
174     BufferMemory*               buffer;
175     DWORD                       playflags,state,leadin;
176     DWORD                       writelead,buflen;
177     DWORD                       nAvgBytesPerSec;
178     DWORD                       freq;
179     DSVOLUMEPAN                 volpan;
180     DSBUFFERDESC                dsbd;
181     /* used for frequency conversion (PerfectPitch) */
182     ULONG                       freqneeded;
183     DWORD                       firstep;
184     float freqAcc, freqAdjust, firgain;
185     /* used for mixing */
186     DWORD                       sec_mixpos;
187
188     /* IDirectSoundNotify fields */
189     LPDSBPOSITIONNOTIFY         notifies;
190     int                         nrofnotifies;
191     /* DirectSound3DBuffer fields */
192     DS3DBUFFER                  ds3db_ds3db;
193     LONG                        ds3db_lVolume;
194     BOOL                        ds3db_need_recalc;
195     /* Used for bit depth conversion */
196     int                         mix_channels;
197     bitsgetfunc get, get_aux;
198     bitsputfunc put, put_aux;
199
200     struct list entry;
201 };
202
203 float get_mono(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel) DECLSPEC_HIDDEN;
204 void put_mono2stereo(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) DECLSPEC_HIDDEN;
205
206 HRESULT IDirectSoundBufferImpl_Create(
207     DirectSoundDevice *device,
208     IDirectSoundBufferImpl **ppdsb,
209     LPCDSBUFFERDESC dsbd) DECLSPEC_HIDDEN;
210 HRESULT IDirectSoundBufferImpl_Duplicate(
211     DirectSoundDevice *device,
212     IDirectSoundBufferImpl **ppdsb,
213     IDirectSoundBufferImpl *pdsb) DECLSPEC_HIDDEN;
214 void secondarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
215 const IDirectSound3DListenerVtbl ds3dlvt DECLSPEC_HIDDEN;
216 const IDirectSound3DBufferVtbl ds3dbvt DECLSPEC_HIDDEN;
217 const IKsPropertySetVtbl iksbvt DECLSPEC_HIDDEN;
218
219 /*****************************************************************************
220  * DirectSoundCaptureDevice implementation structure
221  */
222 struct DirectSoundCaptureDevice
223 {
224     GUID                               guid;
225     LONG                               ref;
226
227     DSCCAPS                            drvcaps;
228
229     LPBYTE                             buffer;
230     DWORD                              buflen, write_pos_bytes;
231
232     PWAVEFORMATEX                      pwfx;
233
234     IDirectSoundCaptureBufferImpl*     capture_buffer;
235     DWORD                              state;
236     UINT timerID;
237     CRITICAL_SECTION                   lock;
238
239     IMMDevice *mmdevice;
240     IAudioClient *client;
241     IAudioCaptureClient *capture;
242
243     struct list entry;
244 };
245
246 /*****************************************************************************
247  * IDirectSoundCaptureBuffer implementation structure
248  */
249 struct IDirectSoundCaptureBufferImpl
250 {
251     IDirectSoundCaptureBuffer8          IDirectSoundCaptureBuffer8_iface;
252     IDirectSoundNotify                  IDirectSoundNotify_iface;
253     LONG                                numIfaces; /* "in use interfaces" refcount */
254     LONG                                ref, refn;
255     /* IDirectSoundCaptureBuffer fields */
256     DirectSoundCaptureDevice*           device;
257     LPDSCBUFFERDESC                     pdscbd;
258     DWORD                               flags;
259     /* IDirectSoundNotify fields */
260     LPDSBPOSITIONNOTIFY                 notifies;
261     int                                 nrofnotifies;
262 };
263
264 HRESULT IKsPrivatePropertySetImpl_Create(REFIID riid, IKsPropertySet **piks) DECLSPEC_HIDDEN;
265
266 /*******************************************************************************
267  */
268
269 /* dsound.c */
270
271 HRESULT DSOUND_Create(REFIID riid, LPDIRECTSOUND *ppDS) DECLSPEC_HIDDEN;
272 HRESULT DSOUND_Create8(REFIID riid, LPDIRECTSOUND8 *ppDS) DECLSPEC_HIDDEN;
273
274 /* primary.c */
275
276 HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device) DECLSPEC_HIDDEN;
277 HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device) DECLSPEC_HIDDEN;
278 HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device) DECLSPEC_HIDDEN;
279 HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device) DECLSPEC_HIDDEN;
280 HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos) DECLSPEC_HIDDEN;
281 LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
282 HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) DECLSPEC_HIDDEN;
283 HRESULT primarybuffer_create(DirectSoundDevice *device, IDirectSoundBufferImpl **ppdsb,
284     const DSBUFFERDESC *dsbd) DECLSPEC_HIDDEN;
285 void primarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
286 HRESULT primarybuffer_SetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
287 LONG capped_refcount_dec(LONG *ref) DECLSPEC_HIDDEN;
288
289 /* duplex.c */
290  
291 HRESULT DSOUND_FullDuplexCreate(REFIID riid, LPDIRECTSOUNDFULLDUPLEX* ppDSFD) DECLSPEC_HIDDEN;
292
293 /* mixer.c */
294 void DSOUND_CheckEvent(const IDirectSoundBufferImpl *dsb, DWORD playpos, int len) DECLSPEC_HIDDEN;
295 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
296 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
297 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
298 DWORD DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl *dsb, DWORD secpos, DWORD secmixpos, float *overshot) DECLSPEC_HIDDEN;
299
300 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) DECLSPEC_HIDDEN;
301
302 /* sound3d.c */
303
304 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
305
306 /* capture.c */
307  
308 HRESULT DSOUND_CaptureCreate(REFIID riid, LPDIRECTSOUNDCAPTURE *ppDSC) DECLSPEC_HIDDEN;
309 HRESULT DSOUND_CaptureCreate8(REFIID riid, LPDIRECTSOUNDCAPTURE8 *ppDSC8) DECLSPEC_HIDDEN;
310
311 #define STATE_STOPPED   0
312 #define STATE_STARTING  1
313 #define STATE_PLAYING   2
314 #define STATE_CAPTURING 2
315 #define STATE_STOPPING  3
316
317 extern CRITICAL_SECTION DSOUND_renderers_lock DECLSPEC_HIDDEN;
318 extern CRITICAL_SECTION DSOUND_capturers_lock DECLSPEC_HIDDEN;
319 extern struct list DSOUND_capturers DECLSPEC_HIDDEN;
320 extern struct list DSOUND_renderers DECLSPEC_HIDDEN;
321
322 extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
323 extern GUID DSOUND_capture_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
324
325 extern WCHAR wine_vxd_drv[] DECLSPEC_HIDDEN;
326
327 void setup_dsound_options(void) DECLSPEC_HIDDEN;
328 const char * dumpCooperativeLevel(DWORD level) DECLSPEC_HIDDEN;
329
330 HRESULT get_mmdevice(EDataFlow flow, const GUID *tgt, IMMDevice **device) DECLSPEC_HIDDEN;
331
332 BOOL DSOUND_check_supported(IAudioClient *client, DWORD rate,
333         DWORD depth, WORD channels) DECLSPEC_HIDDEN;
334 UINT DSOUND_create_timer(LPTIMECALLBACK cb, DWORD_PTR user) DECLSPEC_HIDDEN;
335 HRESULT enumerate_mmdevices(EDataFlow flow, GUID *guids,
336         LPDSENUMCALLBACKW cb, void *user) DECLSPEC_HIDDEN;