ole32: Store destination context data in channel buffer.
[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 IDirectSoundBufferImpl        IDirectSoundBufferImpl;
43 typedef struct DirectSoundDevice             DirectSoundDevice;
44
45 /* dsound_convert.h */
46 typedef float (*bitsgetfunc)(const IDirectSoundBufferImpl *, DWORD, DWORD);
47 typedef void (*bitsputfunc)(const IDirectSoundBufferImpl *, DWORD, DWORD, float);
48 extern const bitsgetfunc getbpp[5] DECLSPEC_HIDDEN;
49 void putieee32(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) DECLSPEC_HIDDEN;
50 void mixieee32(float *src, float *dst, unsigned samples) DECLSPEC_HIDDEN;
51 typedef void (*normfunc)(const void *, void *, unsigned);
52 extern const normfunc normfunctions[5] DECLSPEC_HIDDEN;
53
54 typedef struct _DSVOLUMEPAN
55 {
56     DWORD       dwTotalLeftAmpFactor;
57     DWORD       dwTotalRightAmpFactor;
58     LONG        lVolume;
59     DWORD       dwVolAmpFactor;
60     LONG        lPan;
61     DWORD       dwPanLeftAmpFactor;
62     DWORD       dwPanRightAmpFactor;
63 } DSVOLUMEPAN,*PDSVOLUMEPAN;
64
65 /*****************************************************************************
66  * IDirectSoundDevice implementation structure
67  */
68 struct DirectSoundDevice
69 {
70     LONG                        ref;
71
72     GUID                        guid;
73     DSCAPS                      drvcaps;
74     DWORD                       priolevel;
75     PWAVEFORMATEX               pwfx;
76     UINT                        timerID, playing_offs_bytes, in_mmdev_bytes, prebuf, helfrags;
77     DWORD                       fraglen;
78     LPBYTE                      buffer;
79     DWORD                       writelead, buflen, state, playpos, mixpos;
80     int                         nrofbuffers;
81     IDirectSoundBufferImpl**    buffers;
82     RTL_RWLOCK                  buffer_list_lock;
83     CRITICAL_SECTION            mixlock;
84     IDirectSoundBufferImpl     *primary;
85     DWORD                       speaker_config;
86     float *mix_buffer, *tmp_buffer;
87     DWORD                       tmp_buffer_len, mix_buffer_len;
88
89     DSVOLUMEPAN                 volpan;
90
91     normfunc normfunction;
92
93     /* DirectSound3DListener fields */
94     DS3DLISTENER                ds3dl;
95     BOOL                        ds3dl_need_recalc;
96
97     IMMDevice *mmdevice;
98     IAudioClient *client;
99     IAudioClock *clock;
100     IAudioStreamVolume *volume;
101     IAudioRenderClient *render;
102
103     struct list entry;
104 };
105
106 /* reference counted buffer memory for duplicated buffer memory */
107 typedef struct BufferMemory
108 {
109     LONG                        ref;
110     LPBYTE                      memory;
111     struct list buffers;
112 } BufferMemory;
113
114 ULONG DirectSoundDevice_Release(DirectSoundDevice * device) DECLSPEC_HIDDEN;
115 HRESULT DirectSoundDevice_Initialize(
116     DirectSoundDevice ** ppDevice,
117     LPCGUID lpcGUID) DECLSPEC_HIDDEN;
118 HRESULT DirectSoundDevice_AddBuffer(
119     DirectSoundDevice * device,
120     IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
121 void DirectSoundDevice_RemoveBuffer(DirectSoundDevice * device, IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
122 HRESULT DirectSoundDevice_CreateSoundBuffer(
123     DirectSoundDevice * device,
124     LPCDSBUFFERDESC dsbd,
125     LPLPDIRECTSOUNDBUFFER ppdsb,
126     LPUNKNOWN lpunk,
127     BOOL from8) DECLSPEC_HIDDEN;
128 HRESULT DirectSoundDevice_DuplicateSoundBuffer(
129     DirectSoundDevice * device,
130     LPDIRECTSOUNDBUFFER psb,
131     LPLPDIRECTSOUNDBUFFER ppdsb) DECLSPEC_HIDDEN;
132
133 /*****************************************************************************
134  * IDirectSoundBuffer implementation structure
135  */
136 struct IDirectSoundBufferImpl
137 {
138     IDirectSoundBuffer8         IDirectSoundBuffer8_iface;
139     IDirectSoundNotify          IDirectSoundNotify_iface;
140     IDirectSound3DListener      IDirectSound3DListener_iface; /* only primary buffer */
141     IDirectSound3DBuffer        IDirectSound3DBuffer_iface; /* only secondary buffer */
142     IKsPropertySet              IKsPropertySet_iface;
143     LONG                        numIfaces; /* "in use interfaces" refcount */
144     LONG                        ref, refn, ref3D, refiks;
145     /* IDirectSoundBufferImpl fields */
146     DirectSoundDevice*          device;
147     RTL_RWLOCK                  lock;
148     PWAVEFORMATEX               pwfx;
149     BufferMemory*               buffer;
150     DWORD                       playflags,state,leadin;
151     DWORD                       writelead,buflen;
152     DWORD                       nAvgBytesPerSec;
153     DWORD                       freq;
154     DSVOLUMEPAN                 volpan;
155     DSBUFFERDESC                dsbd;
156     /* used for frequency conversion (PerfectPitch) */
157     ULONG                       freqneeded;
158     DWORD                       firstep;
159     float freqAcc, freqAdjust, firgain;
160     /* used for mixing */
161     DWORD                       sec_mixpos;
162
163     /* IDirectSoundNotify fields */
164     LPDSBPOSITIONNOTIFY         notifies;
165     int                         nrofnotifies;
166     /* DirectSound3DBuffer fields */
167     DS3DBUFFER                  ds3db_ds3db;
168     LONG                        ds3db_lVolume;
169     BOOL                        ds3db_need_recalc;
170     /* Used for bit depth conversion */
171     int                         mix_channels;
172     bitsgetfunc get, get_aux;
173     bitsputfunc put, put_aux;
174
175     struct list entry;
176 };
177
178 float get_mono(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel) DECLSPEC_HIDDEN;
179 void put_mono2stereo(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) DECLSPEC_HIDDEN;
180
181 HRESULT IDirectSoundBufferImpl_Create(
182     DirectSoundDevice *device,
183     IDirectSoundBufferImpl **ppdsb,
184     LPCDSBUFFERDESC dsbd) DECLSPEC_HIDDEN;
185 HRESULT IDirectSoundBufferImpl_Duplicate(
186     DirectSoundDevice *device,
187     IDirectSoundBufferImpl **ppdsb,
188     IDirectSoundBufferImpl *pdsb) DECLSPEC_HIDDEN;
189 void secondarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
190 const IDirectSound3DListenerVtbl ds3dlvt DECLSPEC_HIDDEN;
191 const IDirectSound3DBufferVtbl ds3dbvt DECLSPEC_HIDDEN;
192 const IKsPropertySetVtbl iksbvt DECLSPEC_HIDDEN;
193
194 HRESULT IKsPrivatePropertySetImpl_Create(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
195
196 /*******************************************************************************
197  */
198
199 /* dsound.c */
200
201 HRESULT DSOUND_Create(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
202 HRESULT DSOUND_Create8(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
203 HRESULT IDirectSoundImpl_Create(IUnknown *outer_unk, REFIID riid, void **ppv, BOOL has_ds8) DECLSPEC_HIDDEN;
204
205 /* primary.c */
206
207 HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device) DECLSPEC_HIDDEN;
208 HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device) DECLSPEC_HIDDEN;
209 HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device) DECLSPEC_HIDDEN;
210 HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device) DECLSPEC_HIDDEN;
211 HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos) DECLSPEC_HIDDEN;
212 LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
213 HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) DECLSPEC_HIDDEN;
214 HRESULT primarybuffer_create(DirectSoundDevice *device, IDirectSoundBufferImpl **ppdsb,
215     const DSBUFFERDESC *dsbd) DECLSPEC_HIDDEN;
216 void primarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
217 HRESULT primarybuffer_SetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
218 LONG capped_refcount_dec(LONG *ref) DECLSPEC_HIDDEN;
219
220 /* duplex.c */
221
222 HRESULT DSOUND_FullDuplexCreate(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
223
224 /* mixer.c */
225 void DSOUND_CheckEvent(const IDirectSoundBufferImpl *dsb, DWORD playpos, int len) DECLSPEC_HIDDEN;
226 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
227 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
228 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
229 DWORD DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl *dsb, DWORD secpos, DWORD secmixpos, float *overshot) DECLSPEC_HIDDEN;
230
231 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) DECLSPEC_HIDDEN;
232
233 /* sound3d.c */
234
235 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
236
237 /* capture.c */
238  
239 HRESULT DSOUND_CaptureCreate(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
240 HRESULT DSOUND_CaptureCreate8(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
241 HRESULT IDirectSoundCaptureImpl_Create(IUnknown *outer_unk, REFIID riid, void **ppv, BOOL has_dsc8) DECLSPEC_HIDDEN;
242
243 #define STATE_STOPPED   0
244 #define STATE_STARTING  1
245 #define STATE_PLAYING   2
246 #define STATE_CAPTURING 2
247 #define STATE_STOPPING  3
248
249 extern CRITICAL_SECTION DSOUND_renderers_lock DECLSPEC_HIDDEN;
250 extern CRITICAL_SECTION DSOUND_capturers_lock DECLSPEC_HIDDEN;
251 extern struct list DSOUND_capturers DECLSPEC_HIDDEN;
252 extern struct list DSOUND_renderers DECLSPEC_HIDDEN;
253
254 extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
255 extern GUID DSOUND_capture_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
256
257 extern WCHAR wine_vxd_drv[] DECLSPEC_HIDDEN;
258
259 void setup_dsound_options(void) DECLSPEC_HIDDEN;
260
261 HRESULT get_mmdevice(EDataFlow flow, const GUID *tgt, IMMDevice **device) DECLSPEC_HIDDEN;
262
263 BOOL DSOUND_check_supported(IAudioClient *client, DWORD rate,
264         DWORD depth, WORD channels) DECLSPEC_HIDDEN;
265 UINT DSOUND_create_timer(LPTIMECALLBACK cb, DWORD_PTR user) DECLSPEC_HIDDEN;
266 HRESULT enumerate_mmdevices(EDataFlow flow, GUID *guids,
267         LPDSENUMCALLBACKW cb, void *user) DECLSPEC_HIDDEN;