dsound: fix format handling on invalid format to never fail
[wine/multimedia.git] / dlls / dsound / dsound_private.h
bloba99351f4a9624ed19591223aae99f69587896bad
1 /* DirectSound
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998 Rob Riggs
5 * Copyright 2000-2001 TransGaming Technologies, Inc.
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.
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.
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
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 */
26 #include "wingdi.h"
27 #include "mmdeviceapi.h"
28 #include "audioclient.h"
29 #include "mediaobj.h"
30 #include "mmsystem.h"
31 #include "uuids.h"
33 #include "wine/list.h"
35 #define DS_MAX_CHANNELS 6
37 extern int ds_hel_buflen DECLSPEC_HIDDEN;
39 /*****************************************************************************
40 * Predeclare the interface implementation structures
42 typedef struct IDirectSoundBufferImpl IDirectSoundBufferImpl;
43 typedef struct DirectSoundDevice DirectSoundDevice;
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;
54 typedef struct _DSVOLUMEPAN
56 DWORD dwTotalAmpFactor[DS_MAX_CHANNELS];
57 LONG lVolume;
58 LONG lPan;
59 } DSVOLUMEPAN,*PDSVOLUMEPAN;
61 typedef struct DSFilter {
62 GUID guid;
63 IMediaObject* obj;
64 IMediaObjectInPlace* inplace;
65 } DSFilter;
67 /*****************************************************************************
68 * IDirectSoundDevice implementation structure
70 struct DirectSoundDevice
72 LONG ref;
74 GUID guid;
75 DSCAPS drvcaps;
76 DWORD priolevel, sleeptime;
77 PWAVEFORMATEX pwfx, primary_pwfx;
78 LPBYTE buffer;
79 DWORD writelead, buflen, aclen, fraglen, state, playpos, pad;
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 speaker_angles[DS_MAX_CHANNELS];
87 int speaker_num[DS_MAX_CHANNELS];
88 int num_speakers;
89 int lfe_channel;
90 float *tmp_buffer;
91 DWORD tmp_buffer_len, mix_buffer_len;
93 DSVOLUMEPAN volpan;
95 normfunc normfunction;
97 /* DirectSound3DListener fields */
98 DS3DLISTENER ds3dl;
99 BOOL ds3dl_need_recalc;
101 IMMDevice *mmdevice;
102 IAudioClient *client;
103 IAudioStreamVolume *volume;
104 IAudioRenderClient *render;
106 HANDLE sleepev, thread;
107 HANDLE thread_finished;
108 struct list entry;
111 /* reference counted buffer memory for duplicated buffer memory */
112 typedef struct BufferMemory
114 LONG ref;
115 LONG lockedbytes;
116 LPBYTE memory;
117 struct list buffers;
118 } BufferMemory;
120 HRESULT DirectSoundDevice_AddBuffer(
121 DirectSoundDevice * device,
122 IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
123 void DirectSoundDevice_RemoveBuffer(DirectSoundDevice * device, IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
125 /*****************************************************************************
126 * IDirectSoundBuffer implementation structure
128 struct IDirectSoundBufferImpl
130 IDirectSoundBuffer8 IDirectSoundBuffer8_iface;
131 IDirectSoundNotify IDirectSoundNotify_iface;
132 IDirectSound3DListener IDirectSound3DListener_iface; /* only primary buffer */
133 IDirectSound3DBuffer IDirectSound3DBuffer_iface; /* only secondary buffer */
134 IKsPropertySet IKsPropertySet_iface;
135 LONG numIfaces; /* "in use interfaces" refcount */
136 LONG ref, refn, ref3D, refiks;
137 /* IDirectSoundBufferImpl fields */
138 DirectSoundDevice* device;
139 RTL_RWLOCK lock;
140 PWAVEFORMATEX pwfx;
141 BufferMemory* buffer;
142 DWORD playflags,state,leadin;
143 DWORD writelead,buflen;
144 DWORD nAvgBytesPerSec;
145 DWORD freq;
146 DSVOLUMEPAN volpan;
147 DSBUFFERDESC dsbd;
148 /* used for frequency conversion (PerfectPitch) */
149 ULONG freqneeded;
150 DWORD firstep;
151 float firgain;
152 LONG64 freqAdjustNum,freqAdjustDen;
153 LONG64 freqAccNum;
154 /* used for mixing */
155 DWORD sec_mixpos;
157 /* IDirectSoundNotify fields */
158 LPDSBPOSITIONNOTIFY notifies;
159 int nrofnotifies;
160 /* DirectSound3DBuffer fields */
161 DS3DBUFFER ds3db_ds3db;
162 LONG ds3db_lVolume;
163 BOOL ds3db_need_recalc;
164 /* Used for bit depth conversion */
165 int mix_channels;
166 bitsgetfunc get, get_aux;
167 bitsputfunc put, put_aux;
168 int num_filters;
169 DSFilter* filters;
171 struct list entry;
174 float get_mono(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel) DECLSPEC_HIDDEN;
175 void put_mono2stereo(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) DECLSPEC_HIDDEN;
176 void put_mono2quad(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) DECLSPEC_HIDDEN;
177 void put_stereo2quad(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) DECLSPEC_HIDDEN;
178 void put_mono2surround51(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) DECLSPEC_HIDDEN;
179 void put_stereo2surround51(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) DECLSPEC_HIDDEN;
181 HRESULT secondarybuffer_create(DirectSoundDevice *device, const DSBUFFERDESC *dsbd,
182 IDirectSoundBuffer **buffer) 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;
192 HRESULT IKsPrivatePropertySetImpl_Create(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
194 /*******************************************************************************
197 /* dsound.c */
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 void DSOUND_ParseSpeakerConfig(DirectSoundDevice *device) DECLSPEC_HIDDEN;
204 /* primary.c */
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 LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
210 HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) DECLSPEC_HIDDEN;
211 HRESULT primarybuffer_create(DirectSoundDevice *device, IDirectSoundBufferImpl **ppdsb,
212 const DSBUFFERDESC *dsbd) DECLSPEC_HIDDEN;
213 void primarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
214 HRESULT primarybuffer_SetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
215 LONG capped_refcount_dec(LONG *ref) DECLSPEC_HIDDEN;
217 /* duplex.c */
219 HRESULT DSOUND_FullDuplexCreate(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
221 /* mixer.c */
222 void DSOUND_CheckEvent(const IDirectSoundBufferImpl *dsb, DWORD playpos, int len) DECLSPEC_HIDDEN;
223 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
224 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
225 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
226 DWORD DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl *dsb, DWORD secpos, DWORD secmixpos, float *overshot) DECLSPEC_HIDDEN;
228 DWORD CALLBACK DSOUND_mixthread(void *ptr) DECLSPEC_HIDDEN;
230 /* sound3d.c */
232 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
234 /* capture.c */
236 HRESULT DSOUND_CaptureCreate(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
237 HRESULT DSOUND_CaptureCreate8(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
238 HRESULT IDirectSoundCaptureImpl_Create(IUnknown *outer_unk, REFIID riid, void **ppv, BOOL has_dsc8) DECLSPEC_HIDDEN;
240 #define STATE_STOPPED 0
241 #define STATE_STARTING 1
242 #define STATE_PLAYING 2
243 #define STATE_CAPTURING 2
244 #define STATE_STOPPING 3
246 extern CRITICAL_SECTION DSOUND_renderers_lock DECLSPEC_HIDDEN;
247 extern CRITICAL_SECTION DSOUND_capturers_lock DECLSPEC_HIDDEN;
248 extern struct list DSOUND_capturers DECLSPEC_HIDDEN;
249 extern struct list DSOUND_renderers DECLSPEC_HIDDEN;
251 extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
252 extern GUID DSOUND_capture_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
254 extern WCHAR wine_vxd_drv[] DECLSPEC_HIDDEN;
256 void setup_dsound_options(void) DECLSPEC_HIDDEN;
258 HRESULT get_mmdevice(EDataFlow flow, const GUID *tgt, IMMDevice **device) DECLSPEC_HIDDEN;
260 BOOL DSOUND_check_supported(IAudioClient *client, DWORD rate,
261 DWORD depth, WORD channels) DECLSPEC_HIDDEN;
262 HRESULT enumerate_mmdevices(EDataFlow flow, GUID *guids,
263 LPDSENUMCALLBACKW cb, void *user) DECLSPEC_HIDDEN;