2002-06-13 21:15:06 +02:00
|
|
|
/* DirectSound
|
|
|
|
*
|
|
|
|
* Copyright 1998 Marcus Meissner
|
|
|
|
* Copyright 1998 Rob Riggs
|
|
|
|
* Copyright 2000-2001 TransGaming Technologies, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-06-13 21:15:06 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Linux does not support better timing than 10ms */
|
2007-06-13 17:05:49 +02:00
|
|
|
#define DS_TIME_RES 2 /* Resolution of multimedia timer */
|
2002-06-13 21:15:06 +02:00
|
|
|
#define DS_TIME_DEL 10 /* Delay of multimedia timer callback, and duration of HEL fragment */
|
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "mmdeviceapi.h"
|
|
|
|
#include "audioclient.h"
|
|
|
|
#include "mmsystem.h"
|
|
|
|
|
2007-07-29 23:47:01 +02:00
|
|
|
#include "wine/list.h"
|
|
|
|
|
2014-12-27 22:32:24 +01:00
|
|
|
#define DS_MAX_CHANNELS 2
|
|
|
|
|
2011-04-21 11:25:41 +02:00
|
|
|
extern int ds_hel_buflen DECLSPEC_HIDDEN;
|
|
|
|
extern int ds_snd_queue_max DECLSPEC_HIDDEN;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Predeclare the interface implementation structures
|
|
|
|
*/
|
2004-07-04 02:13:44 +02:00
|
|
|
typedef struct IDirectSoundBufferImpl IDirectSoundBufferImpl;
|
2005-05-31 11:31:37 +02:00
|
|
|
typedef struct DirectSoundDevice DirectSoundDevice;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2007-11-07 20:31:53 +01:00
|
|
|
/* dsound_convert.h */
|
2011-11-07 17:25:49 +01:00
|
|
|
typedef float (*bitsgetfunc)(const IDirectSoundBufferImpl *, DWORD, DWORD);
|
|
|
|
typedef void (*bitsputfunc)(const IDirectSoundBufferImpl *, DWORD, DWORD, float);
|
|
|
|
extern const bitsgetfunc getbpp[5] DECLSPEC_HIDDEN;
|
2012-05-15 15:29:34 +02:00
|
|
|
void putieee32(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) DECLSPEC_HIDDEN;
|
|
|
|
void mixieee32(float *src, float *dst, unsigned samples) DECLSPEC_HIDDEN;
|
2007-11-07 20:32:09 +01:00
|
|
|
typedef void (*normfunc)(const void *, void *, unsigned);
|
2012-05-14 22:19:46 +02:00
|
|
|
extern const normfunc normfunctions[5] DECLSPEC_HIDDEN;
|
2007-11-07 20:31:53 +01:00
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
typedef struct _DSVOLUMEPAN
|
|
|
|
{
|
2014-12-27 22:32:24 +01:00
|
|
|
DWORD dwTotalAmpFactor[DS_MAX_CHANNELS];
|
2011-09-24 16:02:52 +02:00
|
|
|
LONG lVolume;
|
|
|
|
LONG lPan;
|
|
|
|
} DSVOLUMEPAN,*PDSVOLUMEPAN;
|
|
|
|
|
2006-01-14 17:06:52 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirectSoundDevice implementation structure
|
|
|
|
*/
|
2005-05-31 11:31:37 +02:00
|
|
|
struct DirectSoundDevice
|
|
|
|
{
|
2005-07-12 21:21:36 +02:00
|
|
|
LONG ref;
|
2005-05-31 11:31:37 +02:00
|
|
|
|
2003-03-15 01:54:11 +01:00
|
|
|
GUID guid;
|
2011-09-27 22:19:04 +02:00
|
|
|
DSCAPS drvcaps;
|
2012-12-19 10:30:04 +01:00
|
|
|
DWORD priolevel, sleeptime;
|
2012-11-16 20:35:51 +01:00
|
|
|
PWAVEFORMATEX pwfx, primary_pwfx;
|
2012-12-19 10:30:04 +01:00
|
|
|
UINT playing_offs_bytes, in_mmdev_bytes, prebuf;
|
2002-06-13 21:15:06 +02:00
|
|
|
DWORD fraglen;
|
|
|
|
LPBYTE buffer;
|
|
|
|
DWORD writelead, buflen, state, playpos, mixpos;
|
|
|
|
int nrofbuffers;
|
|
|
|
IDirectSoundBufferImpl** buffers;
|
2004-09-07 21:32:21 +02:00
|
|
|
RTL_RWLOCK buffer_list_lock;
|
2003-02-15 01:01:17 +01:00
|
|
|
CRITICAL_SECTION mixlock;
|
2011-08-31 01:11:29 +02:00
|
|
|
IDirectSoundBufferImpl *primary;
|
2003-09-02 01:58:43 +02:00
|
|
|
DWORD speaker_config;
|
2012-05-15 15:29:34 +02:00
|
|
|
float *mix_buffer, *tmp_buffer;
|
2007-11-07 20:32:22 +01:00
|
|
|
DWORD tmp_buffer_len, mix_buffer_len;
|
|
|
|
|
2008-09-28 20:47:28 +02:00
|
|
|
DSVOLUMEPAN volpan;
|
|
|
|
|
2007-11-07 20:32:22 +01:00
|
|
|
normfunc normfunction;
|
2003-06-28 00:22:15 +02:00
|
|
|
|
|
|
|
/* DirectSound3DListener fields */
|
|
|
|
DS3DLISTENER ds3dl;
|
|
|
|
BOOL ds3dl_need_recalc;
|
2011-09-27 15:51:07 +02:00
|
|
|
|
|
|
|
IMMDevice *mmdevice;
|
|
|
|
IAudioClient *client;
|
|
|
|
IAudioClock *clock;
|
|
|
|
IAudioStreamVolume *volume;
|
|
|
|
IAudioRenderClient *render;
|
|
|
|
|
2012-12-19 10:30:04 +01:00
|
|
|
HANDLE sleepev, thread;
|
2011-09-27 15:51:07 +02:00
|
|
|
struct list entry;
|
2002-06-13 21:15:06 +02:00
|
|
|
};
|
|
|
|
|
2003-06-28 00:22:15 +02:00
|
|
|
/* reference counted buffer memory for duplicated buffer memory */
|
|
|
|
typedef struct BufferMemory
|
|
|
|
{
|
2005-07-12 21:21:36 +02:00
|
|
|
LONG ref;
|
2003-06-28 00:22:15 +02:00
|
|
|
LPBYTE memory;
|
2007-07-29 23:47:01 +02:00
|
|
|
struct list buffers;
|
2003-06-28 00:22:15 +02:00
|
|
|
} BufferMemory;
|
|
|
|
|
2011-04-21 11:25:41 +02:00
|
|
|
ULONG DirectSoundDevice_Release(DirectSoundDevice * device) DECLSPEC_HIDDEN;
|
2006-01-17 16:10:15 +01:00
|
|
|
HRESULT DirectSoundDevice_Initialize(
|
|
|
|
DirectSoundDevice ** ppDevice,
|
2011-04-21 11:25:41 +02:00
|
|
|
LPCGUID lpcGUID) DECLSPEC_HIDDEN;
|
2006-01-14 17:06:52 +01:00
|
|
|
HRESULT DirectSoundDevice_AddBuffer(
|
2006-01-17 16:10:15 +01:00
|
|
|
DirectSoundDevice * device,
|
2011-04-21 11:25:41 +02:00
|
|
|
IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
|
2012-09-25 23:25:45 +02:00
|
|
|
void DirectSoundDevice_RemoveBuffer(DirectSoundDevice * device, IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
|
2006-01-17 16:10:15 +01:00
|
|
|
HRESULT DirectSoundDevice_CreateSoundBuffer(
|
|
|
|
DirectSoundDevice * device,
|
|
|
|
LPCDSBUFFERDESC dsbd,
|
|
|
|
LPLPDIRECTSOUNDBUFFER ppdsb,
|
|
|
|
LPUNKNOWN lpunk,
|
2011-04-21 11:25:41 +02:00
|
|
|
BOOL from8) DECLSPEC_HIDDEN;
|
2006-01-17 16:10:15 +01:00
|
|
|
HRESULT DirectSoundDevice_DuplicateSoundBuffer(
|
|
|
|
DirectSoundDevice * device,
|
|
|
|
LPDIRECTSOUNDBUFFER psb,
|
2011-04-21 11:25:41 +02:00
|
|
|
LPLPDIRECTSOUNDBUFFER ppdsb) DECLSPEC_HIDDEN;
|
2004-07-04 02:13:44 +02:00
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirectSoundBuffer implementation structure
|
|
|
|
*/
|
|
|
|
struct IDirectSoundBufferImpl
|
|
|
|
{
|
2011-08-24 02:30:37 +02:00
|
|
|
IDirectSoundBuffer8 IDirectSoundBuffer8_iface;
|
2012-01-20 00:28:16 +01:00
|
|
|
IDirectSoundNotify IDirectSoundNotify_iface;
|
2012-01-16 00:13:31 +01:00
|
|
|
IDirectSound3DListener IDirectSound3DListener_iface; /* only primary buffer */
|
2012-01-19 01:18:30 +01:00
|
|
|
IDirectSound3DBuffer IDirectSound3DBuffer_iface; /* only secondary buffer */
|
2012-01-17 01:53:10 +01:00
|
|
|
IKsPropertySet IKsPropertySet_iface;
|
2011-08-25 23:42:44 +02:00
|
|
|
LONG numIfaces; /* "in use interfaces" refcount */
|
2012-01-20 00:28:16 +01:00
|
|
|
LONG ref, refn, ref3D, refiks;
|
2002-06-13 21:15:06 +02:00
|
|
|
/* IDirectSoundBufferImpl fields */
|
2006-01-06 12:35:20 +01:00
|
|
|
DirectSoundDevice* device;
|
2007-07-29 21:01:43 +02:00
|
|
|
RTL_RWLOCK lock;
|
2004-08-18 02:30:37 +02:00
|
|
|
PWAVEFORMATEX pwfx;
|
2003-06-28 00:22:15 +02:00
|
|
|
BufferMemory* buffer;
|
|
|
|
DWORD playflags,state,leadin;
|
2007-07-29 23:47:01 +02:00
|
|
|
DWORD writelead,buflen;
|
2003-06-28 00:22:15 +02:00
|
|
|
DWORD nAvgBytesPerSec;
|
2012-05-01 22:01:32 +02:00
|
|
|
DWORD freq;
|
2007-06-13 17:05:49 +02:00
|
|
|
DSVOLUMEPAN volpan;
|
2003-06-28 00:22:15 +02:00
|
|
|
DSBUFFERDESC dsbd;
|
2002-06-13 21:15:06 +02:00
|
|
|
/* used for frequency conversion (PerfectPitch) */
|
2012-05-01 22:01:06 +02:00
|
|
|
ULONG freqneeded;
|
2012-05-06 20:06:13 +02:00
|
|
|
DWORD firstep;
|
2014-12-27 23:41:07 +01:00
|
|
|
float firgain;
|
|
|
|
LONG64 freqAdjustNum,freqAdjustDen;
|
|
|
|
LONG64 freqAccNum;
|
2007-07-29 23:47:01 +02:00
|
|
|
/* used for mixing */
|
2012-05-14 22:19:50 +02:00
|
|
|
DWORD sec_mixpos;
|
2012-05-01 22:01:32 +02:00
|
|
|
|
2012-01-20 00:28:16 +01:00
|
|
|
/* IDirectSoundNotify fields */
|
2003-09-02 01:58:43 +02:00
|
|
|
LPDSBPOSITIONNOTIFY notifies;
|
|
|
|
int nrofnotifies;
|
2003-06-28 00:22:15 +02:00
|
|
|
/* DirectSound3DBuffer fields */
|
|
|
|
DS3DBUFFER ds3db_ds3db;
|
|
|
|
LONG ds3db_lVolume;
|
|
|
|
BOOL ds3db_need_recalc;
|
2011-11-07 17:25:49 +01:00
|
|
|
/* Used for bit depth conversion */
|
2011-12-12 21:07:49 +01:00
|
|
|
int mix_channels;
|
|
|
|
bitsgetfunc get, get_aux;
|
|
|
|
bitsputfunc put, put_aux;
|
2011-11-07 17:25:49 +01:00
|
|
|
|
2007-07-29 23:47:01 +02:00
|
|
|
struct list entry;
|
2002-06-13 21:15:06 +02:00
|
|
|
};
|
|
|
|
|
2011-12-12 21:07:49 +01:00
|
|
|
float get_mono(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel) DECLSPEC_HIDDEN;
|
|
|
|
void put_mono2stereo(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) DECLSPEC_HIDDEN;
|
|
|
|
|
2006-01-03 17:32:50 +01:00
|
|
|
HRESULT IDirectSoundBufferImpl_Create(
|
2006-01-06 12:35:20 +01:00
|
|
|
DirectSoundDevice *device,
|
|
|
|
IDirectSoundBufferImpl **ppdsb,
|
2011-04-21 11:25:41 +02:00
|
|
|
LPCDSBUFFERDESC dsbd) DECLSPEC_HIDDEN;
|
2006-01-14 17:06:52 +01:00
|
|
|
HRESULT IDirectSoundBufferImpl_Duplicate(
|
|
|
|
DirectSoundDevice *device,
|
|
|
|
IDirectSoundBufferImpl **ppdsb,
|
2011-04-21 11:25:41 +02:00
|
|
|
IDirectSoundBufferImpl *pdsb) DECLSPEC_HIDDEN;
|
2011-08-25 23:42:44 +02:00
|
|
|
void secondarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
|
2012-01-16 00:13:31 +01:00
|
|
|
const IDirectSound3DListenerVtbl ds3dlvt DECLSPEC_HIDDEN;
|
2012-01-19 01:18:30 +01:00
|
|
|
const IDirectSound3DBufferVtbl ds3dbvt DECLSPEC_HIDDEN;
|
2012-01-17 01:53:10 +01:00
|
|
|
const IKsPropertySetVtbl iksbvt DECLSPEC_HIDDEN;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2012-08-24 01:47:14 +02:00
|
|
|
HRESULT IKsPrivatePropertySetImpl_Create(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2006-01-16 20:39:52 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
*/
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2004-09-07 21:32:21 +02:00
|
|
|
/* dsound.c */
|
|
|
|
|
2012-07-19 02:00:27 +02:00
|
|
|
HRESULT DSOUND_Create(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT DSOUND_Create8(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
|
2012-08-16 01:45:29 +02:00
|
|
|
HRESULT IDirectSoundImpl_Create(IUnknown *outer_unk, REFIID riid, void **ppv, BOOL has_ds8) DECLSPEC_HIDDEN;
|
2004-09-07 21:32:21 +02:00
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
/* primary.c */
|
|
|
|
|
2011-04-21 11:25:41 +02:00
|
|
|
HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos) DECLSPEC_HIDDEN;
|
|
|
|
LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) DECLSPEC_HIDDEN;
|
2012-11-16 20:35:51 +01:00
|
|
|
HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device) DECLSPEC_HIDDEN;
|
2011-08-31 01:11:29 +02:00
|
|
|
HRESULT primarybuffer_create(DirectSoundDevice *device, IDirectSoundBufferImpl **ppdsb,
|
|
|
|
const DSBUFFERDESC *dsbd) DECLSPEC_HIDDEN;
|
2011-08-31 01:13:33 +02:00
|
|
|
void primarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
|
2011-08-31 01:17:04 +02:00
|
|
|
HRESULT primarybuffer_SetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
|
2012-05-09 15:48:56 +02:00
|
|
|
LONG capped_refcount_dec(LONG *ref) DECLSPEC_HIDDEN;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2006-08-18 07:13:31 +02:00
|
|
|
/* duplex.c */
|
2012-08-16 01:27:12 +02:00
|
|
|
|
|
|
|
HRESULT DSOUND_FullDuplexCreate(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
|
2006-08-18 07:13:31 +02:00
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
/* mixer.c */
|
2011-04-21 11:25:41 +02:00
|
|
|
void DSOUND_CheckEvent(const IDirectSoundBufferImpl *dsb, DWORD playpos, int len) DECLSPEC_HIDDEN;
|
|
|
|
void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
|
|
|
|
void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
|
|
|
|
void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
|
2012-05-01 22:01:06 +02:00
|
|
|
DWORD DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl *dsb, DWORD secpos, DWORD secmixpos, float *overshot) DECLSPEC_HIDDEN;
|
2007-07-29 23:47:01 +02:00
|
|
|
|
2012-12-19 10:30:04 +01:00
|
|
|
DWORD CALLBACK DSOUND_mixthread(void *ptr) DECLSPEC_HIDDEN;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2003-06-28 00:22:15 +02:00
|
|
|
/* sound3d.c */
|
|
|
|
|
2011-04-21 11:25:41 +02:00
|
|
|
void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
|
2003-06-28 00:22:15 +02:00
|
|
|
|
2006-01-16 20:39:14 +01:00
|
|
|
/* capture.c */
|
2006-08-18 07:13:31 +02:00
|
|
|
|
2012-08-16 01:20:01 +02:00
|
|
|
HRESULT DSOUND_CaptureCreate(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
|
|
|
|
HRESULT DSOUND_CaptureCreate8(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
|
2012-08-16 01:49:10 +02:00
|
|
|
HRESULT IDirectSoundCaptureImpl_Create(IUnknown *outer_unk, REFIID riid, void **ppv, BOOL has_dsc8) DECLSPEC_HIDDEN;
|
2006-01-16 20:39:14 +01:00
|
|
|
|
2003-02-15 01:01:17 +01:00
|
|
|
#define STATE_STOPPED 0
|
|
|
|
#define STATE_STARTING 1
|
|
|
|
#define STATE_PLAYING 2
|
|
|
|
#define STATE_CAPTURING 2
|
|
|
|
#define STATE_STOPPING 3
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
extern CRITICAL_SECTION DSOUND_renderers_lock DECLSPEC_HIDDEN;
|
2011-09-27 15:51:22 +02:00
|
|
|
extern CRITICAL_SECTION DSOUND_capturers_lock DECLSPEC_HIDDEN;
|
|
|
|
extern struct list DSOUND_capturers DECLSPEC_HIDDEN;
|
2011-09-27 15:51:07 +02:00
|
|
|
extern struct list DSOUND_renderers DECLSPEC_HIDDEN;
|
2010-01-05 22:20:52 +01:00
|
|
|
|
2011-09-27 15:51:07 +02:00
|
|
|
extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
|
2011-04-21 11:25:41 +02:00
|
|
|
extern GUID DSOUND_capture_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
|
2004-08-20 22:01:31 +02:00
|
|
|
|
2011-09-27 15:51:33 +02:00
|
|
|
extern WCHAR wine_vxd_drv[] DECLSPEC_HIDDEN;
|
|
|
|
|
2011-04-21 11:25:41 +02:00
|
|
|
void setup_dsound_options(void) DECLSPEC_HIDDEN;
|
2011-09-27 15:51:07 +02:00
|
|
|
|
|
|
|
HRESULT get_mmdevice(EDataFlow flow, const GUID *tgt, IMMDevice **device) DECLSPEC_HIDDEN;
|
2011-09-27 15:51:22 +02:00
|
|
|
|
|
|
|
BOOL DSOUND_check_supported(IAudioClient *client, DWORD rate,
|
|
|
|
DWORD depth, WORD channels) DECLSPEC_HIDDEN;
|
2011-09-27 15:51:33 +02:00
|
|
|
HRESULT enumerate_mmdevices(EDataFlow flow, GUID *guids,
|
|
|
|
LPDSENUMCALLBACKW cb, void *user) DECLSPEC_HIDDEN;
|