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