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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Linux does not support better timing than 10ms */
|
|
|
|
#define DS_TIME_RES 10 /* Resolution of multimedia timer */
|
|
|
|
#define DS_TIME_DEL 10 /* Delay of multimedia timer callback, and duration of HEL fragment */
|
|
|
|
|
|
|
|
#define DS_HEL_FRAGS 48 /* HEL only: number of waveOut fragments in primary buffer
|
|
|
|
* (changing this won't help you) */
|
|
|
|
|
2003-03-06 23:46:34 +01:00
|
|
|
/* direct sound hardware acceleration levels */
|
|
|
|
#define DS_HW_ACCEL_FULL 0 /* default on Windows 98 */
|
|
|
|
#define DS_HW_ACCEL_STANDARD 1 /* default on Windows 2000 */
|
|
|
|
#define DS_HW_ACCEL_BASIC 2
|
|
|
|
#define DS_HW_ACCEL_EMULATION 3
|
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
extern int ds_emuldriver;
|
|
|
|
extern int ds_hel_margin;
|
|
|
|
extern int ds_hel_queue;
|
|
|
|
extern int ds_snd_queue_max;
|
|
|
|
extern int ds_snd_queue_min;
|
2003-03-06 23:46:34 +01:00
|
|
|
extern int ds_hw_accel;
|
2003-03-15 01:54:11 +01:00
|
|
|
extern int ds_default_playback;
|
|
|
|
extern int ds_default_capture;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Predeclare the interface implementation structures
|
|
|
|
*/
|
|
|
|
typedef struct IDirectSoundImpl IDirectSoundImpl;
|
|
|
|
typedef struct IDirectSoundBufferImpl IDirectSoundBufferImpl;
|
2003-02-15 01:01:17 +01:00
|
|
|
typedef struct IDirectSoundCaptureImpl IDirectSoundCaptureImpl;
|
|
|
|
typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl;
|
2003-03-04 03:12:34 +01:00
|
|
|
typedef struct IDirectSoundFullDuplexImpl IDirectSoundFullDuplexImpl;
|
2002-06-13 21:15:06 +02:00
|
|
|
typedef struct IDirectSoundNotifyImpl IDirectSoundNotifyImpl;
|
|
|
|
typedef struct IDirectSound3DListenerImpl IDirectSound3DListenerImpl;
|
|
|
|
typedef struct IDirectSound3DBufferImpl IDirectSound3DBufferImpl;
|
|
|
|
typedef struct IKsPropertySetImpl IKsPropertySetImpl;
|
|
|
|
typedef struct PrimaryBufferImpl PrimaryBufferImpl;
|
2003-08-07 00:57:24 +02:00
|
|
|
typedef struct IClassFactoryImpl IClassFactoryImpl;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirectSound implementation structure
|
|
|
|
*/
|
|
|
|
struct IDirectSoundImpl
|
|
|
|
{
|
|
|
|
/* IUnknown fields */
|
|
|
|
ICOM_VFIELD(IDirectSound8);
|
2003-06-28 00:22:15 +02:00
|
|
|
DWORD ref;
|
2002-06-13 21:15:06 +02:00
|
|
|
/* IDirectSoundImpl fields */
|
2003-03-15 01:54:11 +01:00
|
|
|
GUID guid;
|
2002-06-13 21:15:06 +02:00
|
|
|
PIDSDRIVER driver;
|
|
|
|
DSDRIVERDESC drvdesc;
|
|
|
|
DSDRIVERCAPS drvcaps;
|
|
|
|
DWORD priolevel;
|
|
|
|
WAVEFORMATEX wfx; /* current main waveformat */
|
|
|
|
HWAVEOUT hwo;
|
|
|
|
LPWAVEHDR pwave[DS_HEL_FRAGS];
|
|
|
|
UINT timerID, pwplay, pwwrite, pwqueue, prebuf, precount;
|
|
|
|
DWORD fraglen;
|
|
|
|
PIDSDRIVERBUFFER hwbuf;
|
|
|
|
LPBYTE buffer;
|
|
|
|
DWORD writelead, buflen, state, playpos, mixpos;
|
|
|
|
BOOL need_remix;
|
|
|
|
int nrofbuffers;
|
|
|
|
IDirectSoundBufferImpl** buffers;
|
2003-02-15 01:01:17 +01:00
|
|
|
RTL_RWLOCK lock;
|
|
|
|
CRITICAL_SECTION mixlock;
|
|
|
|
DSVOLUMEPAN volpan;
|
2003-06-28 00:22:15 +02:00
|
|
|
PrimaryBufferImpl* primary;
|
|
|
|
DSBUFFERDESC dsbd;
|
|
|
|
|
|
|
|
/* DirectSound3DListener fields */
|
|
|
|
IDirectSound3DListenerImpl* listener;
|
|
|
|
DS3DLISTENER ds3dl;
|
|
|
|
CRITICAL_SECTION ds3dl_lock;
|
|
|
|
BOOL ds3dl_need_recalc;
|
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
|
|
|
|
{
|
|
|
|
DWORD ref;
|
|
|
|
LPBYTE memory;
|
|
|
|
} BufferMemory;
|
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirectSoundBuffer implementation structure
|
|
|
|
*/
|
|
|
|
struct IDirectSoundBufferImpl
|
|
|
|
{
|
|
|
|
/* FIXME: document */
|
|
|
|
/* IUnknown fields */
|
|
|
|
ICOM_VFIELD(IDirectSoundBuffer8);
|
2003-06-28 00:22:15 +02:00
|
|
|
DWORD ref;
|
2002-06-13 21:15:06 +02:00
|
|
|
/* IDirectSoundBufferImpl fields */
|
2003-06-28 00:22:15 +02:00
|
|
|
IDirectSoundImpl* dsound;
|
|
|
|
IDirectSound3DBufferImpl* ds3db;
|
|
|
|
IKsPropertySetImpl* iks;
|
|
|
|
CRITICAL_SECTION lock;
|
|
|
|
PIDSDRIVERBUFFER hwbuf;
|
|
|
|
WAVEFORMATEX wfx;
|
|
|
|
BufferMemory* buffer;
|
|
|
|
DWORD playflags,state,leadin;
|
|
|
|
DWORD playpos,startpos,writelead,buflen;
|
|
|
|
DWORD nAvgBytesPerSec;
|
|
|
|
DWORD freq;
|
|
|
|
DSVOLUMEPAN volpan, cvolpan;
|
|
|
|
DSBUFFERDESC dsbd;
|
2002-06-13 21:15:06 +02:00
|
|
|
/* used for frequency conversion (PerfectPitch) */
|
2003-06-28 00:22:15 +02:00
|
|
|
ULONG freqAdjust, freqAcc;
|
2002-06-13 21:15:06 +02:00
|
|
|
/* used for intelligent (well, sort of) prebuffering */
|
2003-06-28 00:22:15 +02:00
|
|
|
DWORD probably_valid_to, last_playpos;
|
|
|
|
DWORD primary_mixpos, buf_mixpos;
|
|
|
|
BOOL need_remix;
|
2002-06-13 21:15:06 +02:00
|
|
|
/* IDirectSoundNotifyImpl fields */
|
2003-06-28 00:22:15 +02:00
|
|
|
IDirectSoundNotifyImpl* notify;
|
|
|
|
|
|
|
|
/* DirectSound3DBuffer fields */
|
|
|
|
DS3DBUFFER ds3db_ds3db;
|
|
|
|
LONG ds3db_lVolume;
|
|
|
|
BOOL ds3db_need_recalc;
|
2002-06-13 21:15:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT WINAPI SecondaryBuffer_Create(
|
|
|
|
IDirectSoundImpl *This,
|
|
|
|
IDirectSoundBufferImpl **pdsb,
|
|
|
|
LPDSBUFFERDESC dsbd);
|
|
|
|
|
|
|
|
struct PrimaryBufferImpl {
|
2003-06-28 00:22:15 +02:00
|
|
|
ICOM_VFIELD(IDirectSoundBuffer8);
|
|
|
|
DWORD ref;
|
|
|
|
IDirectSoundImpl* dsound;
|
2002-06-13 21:15:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT WINAPI PrimaryBuffer_Create(
|
|
|
|
IDirectSoundImpl *This,
|
|
|
|
PrimaryBufferImpl **pdsb,
|
|
|
|
LPDSBUFFERDESC dsbd);
|
|
|
|
|
2003-02-15 01:01:17 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirectSoundCapture implementation structure
|
|
|
|
*/
|
|
|
|
struct IDirectSoundCaptureImpl
|
|
|
|
{
|
|
|
|
/* IUnknown fields */
|
|
|
|
ICOM_VFIELD(IDirectSoundCapture);
|
|
|
|
DWORD ref;
|
|
|
|
|
|
|
|
/* IDirectSoundCaptureImpl fields */
|
2003-03-04 03:12:34 +01:00
|
|
|
GUID guid;
|
|
|
|
BOOL initialized;
|
2003-02-15 01:01:17 +01:00
|
|
|
|
2003-03-04 03:12:34 +01:00
|
|
|
/* DirectSound driver stuff */
|
|
|
|
PIDSCDRIVER driver;
|
|
|
|
DSDRIVERDESC drvdesc;
|
|
|
|
DSCDRIVERCAPS drvcaps;
|
|
|
|
PIDSCDRIVERBUFFER hwbuf;
|
2003-02-15 01:01:17 +01:00
|
|
|
|
2003-03-04 03:12:34 +01:00
|
|
|
/* wave driver info */
|
|
|
|
HWAVEIN hwi;
|
2003-02-15 01:01:17 +01:00
|
|
|
|
2003-03-04 03:12:34 +01:00
|
|
|
/* more stuff */
|
2003-02-15 01:01:17 +01:00
|
|
|
LPBYTE buffer;
|
|
|
|
DWORD buflen;
|
2003-03-04 03:12:34 +01:00
|
|
|
DWORD read_position;
|
2003-02-15 01:01:17 +01:00
|
|
|
|
2003-03-04 03:12:34 +01:00
|
|
|
/* FIXME: this should be a pointer because it can be bigger */
|
|
|
|
WAVEFORMATEX wfx;
|
2003-02-15 01:01:17 +01:00
|
|
|
|
2003-03-04 03:12:34 +01:00
|
|
|
IDirectSoundCaptureBufferImpl* capture_buffer;
|
|
|
|
DWORD state;
|
2003-02-15 01:01:17 +01:00
|
|
|
LPWAVEHDR pwave;
|
2003-03-04 03:12:34 +01:00
|
|
|
int nrofpwaves;
|
|
|
|
int index;
|
2003-02-15 01:01:17 +01:00
|
|
|
CRITICAL_SECTION lock;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirectSoundCaptureBuffer implementation structure
|
|
|
|
*/
|
|
|
|
struct IDirectSoundCaptureBufferImpl
|
|
|
|
{
|
2003-03-04 03:12:34 +01:00
|
|
|
/* IUnknown fields */
|
|
|
|
ICOM_VFIELD(IDirectSoundCaptureBuffer8);
|
2003-06-28 00:22:15 +02:00
|
|
|
DWORD ref;
|
2003-03-04 03:12:34 +01:00
|
|
|
|
|
|
|
/* IDirectSoundCaptureBufferImpl fields */
|
2003-06-28 00:22:15 +02:00
|
|
|
IDirectSoundCaptureImpl* dsound;
|
2003-03-04 03:12:34 +01:00
|
|
|
/* FIXME: don't need this */
|
2003-06-28 00:22:15 +02:00
|
|
|
LPDSCBUFFERDESC pdscbd;
|
|
|
|
DWORD flags;
|
2003-05-02 22:16:48 +02:00
|
|
|
/* IDirectSoundNotifyImpl fields */
|
2003-06-28 00:22:15 +02:00
|
|
|
IDirectSoundNotifyImpl* notify;
|
2003-03-04 03:12:34 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirectSoundFullDuplex implementation structure
|
|
|
|
*/
|
|
|
|
struct IDirectSoundFullDuplexImpl
|
|
|
|
{
|
|
|
|
/* IUnknown fields */
|
|
|
|
ICOM_VFIELD(IDirectSoundFullDuplex);
|
2003-06-28 00:22:15 +02:00
|
|
|
DWORD ref;
|
2003-03-04 03:12:34 +01:00
|
|
|
|
|
|
|
/* IDirectSoundFullDuplexImpl fields */
|
2003-06-28 00:22:15 +02:00
|
|
|
CRITICAL_SECTION lock;
|
2003-02-15 01:01:17 +01:00
|
|
|
};
|
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* IDirectSoundNotify implementation structure
|
|
|
|
*/
|
|
|
|
struct IDirectSoundNotifyImpl
|
|
|
|
{
|
|
|
|
/* IUnknown fields */
|
|
|
|
ICOM_VFIELD(IDirectSoundNotify);
|
2003-06-28 00:22:15 +02:00
|
|
|
DWORD ref;
|
2002-06-13 21:15:06 +02:00
|
|
|
/* IDirectSoundNotifyImpl fields */
|
2003-06-28 00:22:15 +02:00
|
|
|
LPDSBPOSITIONNOTIFY notifies;
|
|
|
|
int nrofnotifies;
|
2003-05-02 22:16:48 +02:00
|
|
|
|
2003-06-28 00:22:15 +02:00
|
|
|
PIDSDRIVERNOTIFY hwnotify;
|
2002-06-13 21:15:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirectSound3DListener implementation structure
|
|
|
|
*/
|
|
|
|
struct IDirectSound3DListenerImpl
|
|
|
|
{
|
|
|
|
/* IUnknown fields */
|
|
|
|
ICOM_VFIELD(IDirectSound3DListener);
|
2003-06-28 00:22:15 +02:00
|
|
|
DWORD ref;
|
2002-06-13 21:15:06 +02:00
|
|
|
/* IDirectSound3DListenerImpl fields */
|
2003-06-28 00:22:15 +02:00
|
|
|
IDirectSoundImpl* dsound;
|
2002-06-13 21:15:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT WINAPI IDirectSound3DListenerImpl_Create(
|
|
|
|
PrimaryBufferImpl *This,
|
|
|
|
IDirectSound3DListenerImpl **pdsl);
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IKsPropertySet implementation structure
|
|
|
|
*/
|
|
|
|
struct IKsPropertySetImpl
|
|
|
|
{
|
|
|
|
/* IUnknown fields */
|
|
|
|
ICOM_VFIELD(IKsPropertySet);
|
|
|
|
DWORD ref;
|
|
|
|
/* IKsPropertySetImpl fields */
|
|
|
|
IDirectSoundBufferImpl* dsb;
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT WINAPI IKsPropertySetImpl_Create(
|
|
|
|
IDirectSoundBufferImpl *This,
|
|
|
|
IKsPropertySetImpl **piks);
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirectSound3DBuffer implementation structure
|
|
|
|
*/
|
|
|
|
struct IDirectSound3DBufferImpl
|
|
|
|
{
|
|
|
|
/* IUnknown fields */
|
|
|
|
ICOM_VFIELD(IDirectSound3DBuffer);
|
2003-06-28 00:22:15 +02:00
|
|
|
DWORD ref;
|
2002-06-13 21:15:06 +02:00
|
|
|
/* IDirectSound3DBufferImpl fields */
|
2003-06-28 00:22:15 +02:00
|
|
|
IDirectSoundBufferImpl* dsb;
|
|
|
|
CRITICAL_SECTION lock;
|
2002-06-13 21:15:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT WINAPI IDirectSound3DBufferImpl_Create(
|
|
|
|
IDirectSoundBufferImpl *This,
|
|
|
|
IDirectSound3DBufferImpl **pds3db);
|
|
|
|
|
2003-08-07 00:57:24 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* DirectSound ClassFactory implementation structure
|
|
|
|
*/
|
|
|
|
struct IClassFactoryImpl
|
|
|
|
{
|
|
|
|
/* IUnknown fields */
|
|
|
|
ICOM_VFIELD(IClassFactory);
|
|
|
|
DWORD ref;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern IClassFactoryImpl DSOUND_CAPTURE_CF;
|
|
|
|
extern IClassFactoryImpl DSOUND_FULLDUPLEX_CF;
|
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
|
|
|
|
void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
|
|
|
|
|
|
|
|
/* primary.c */
|
|
|
|
|
|
|
|
HRESULT DSOUND_PrimaryCreate(IDirectSoundImpl *This);
|
|
|
|
HRESULT DSOUND_PrimaryDestroy(IDirectSoundImpl *This);
|
|
|
|
HRESULT DSOUND_PrimaryPlay(IDirectSoundImpl *This);
|
|
|
|
HRESULT DSOUND_PrimaryStop(IDirectSoundImpl *This);
|
|
|
|
HRESULT DSOUND_PrimaryGetPosition(IDirectSoundImpl *This, LPDWORD playpos, LPDWORD writepos);
|
|
|
|
|
|
|
|
/* buffer.c */
|
|
|
|
|
|
|
|
DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
|
|
|
|
DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix);
|
|
|
|
|
|
|
|
/* mixer.c */
|
|
|
|
|
|
|
|
void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len);
|
|
|
|
void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb);
|
|
|
|
void DSOUND_MixCancelAt(IDirectSoundBufferImpl *dsb, DWORD buf_writepos);
|
|
|
|
void DSOUND_WaveQueue(IDirectSoundImpl *dsound, DWORD mixq);
|
|
|
|
void DSOUND_PerformMix(void);
|
|
|
|
void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
|
|
|
|
void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
|
|
|
|
|
2003-06-28 00:22:15 +02:00
|
|
|
/* sound3d.c */
|
|
|
|
|
|
|
|
void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb);
|
|
|
|
|
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
|
|
|
|
|
|
|
#define DSOUND_FREQSHIFT (14)
|
|
|
|
|
|
|
|
extern IDirectSoundImpl* dsound;
|
2003-03-04 03:12:34 +01:00
|
|
|
extern IDirectSoundCaptureImpl* dsound_capture;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2003-02-15 01:01:17 +01:00
|
|
|
extern ICOM_VTABLE(IDirectSoundNotify) dsnvt;
|
|
|
|
extern HRESULT mmErr(UINT err);
|
2003-03-04 03:12:34 +01:00
|
|
|
extern void setup_dsound_options(void);
|