2005-06-13 06:06:15 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2010-11-11 13:01:23 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
#include "quakedef.h"
|
|
|
|
#include "winquake.h"
|
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
#ifdef AVAIL_DSOUND
|
|
|
|
|
|
|
|
//#define DIRECTSOUND_VERSION 0x800 //either < 0x800 (eax-only) or 0x800 (microsoft's fx stuff).
|
2007-05-25 22:16:29 +00:00
|
|
|
#include <dsound.h>
|
2016-12-07 18:45:25 +00:00
|
|
|
|
|
|
|
#if !defined(IDirectSoundFXI3DL2Reverb_SetAllParameters) && DIRECTSOUND_VERSION>=0x800
|
|
|
|
//mingw defines version as 0x900, but doesn't provide all the extra interfaces (only the core stuff).
|
|
|
|
//which makes it kinda pointless, so lets provide the crap that its missing.
|
|
|
|
typedef struct {
|
|
|
|
LONG lRoom;
|
|
|
|
LONG lRoomHF;
|
|
|
|
FLOAT flRoomRolloffFactor;
|
|
|
|
FLOAT flDecayTime;
|
|
|
|
FLOAT flDecayHFRatio;
|
|
|
|
LONG lReflections;
|
|
|
|
FLOAT flReflectionsDelay;
|
|
|
|
LONG lReverb;
|
|
|
|
FLOAT flReverbDelay;
|
|
|
|
FLOAT flDiffusion;
|
|
|
|
FLOAT flDensity;
|
|
|
|
FLOAT flHFReference;
|
|
|
|
} DSFXI3DL2Reverb;
|
|
|
|
|
|
|
|
typedef struct IDirectSoundFXI3DL2Reverb
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
STDMETHOD(QueryInterface)(struct IDirectSoundFXI3DL2Reverb *this_, REFIID riid, LPVOID * ppvObj);
|
|
|
|
STDMETHOD_(ULONG,AddRef)(struct IDirectSoundFXI3DL2Reverb *this_);
|
|
|
|
STDMETHOD_(ULONG,Release)(struct IDirectSoundFXI3DL2Reverb *this_);
|
|
|
|
STDMETHOD(SetAllParameters)(struct IDirectSoundFXI3DL2Reverb *this_, const DSFXI3DL2Reverb *pcDsFxI3DL2Reverb);
|
|
|
|
//INCOMPLETE
|
|
|
|
} *lpVtbl;
|
|
|
|
} IDirectSoundFXI3DL2Reverb;
|
|
|
|
#define IDirectSoundFXI3DL2Reverb8 IDirectSoundFXI3DL2Reverb
|
|
|
|
#define IID_IDirectSoundFXI3DL2Reverb8 IID_IDirectSoundFXI3DL2Reverb
|
|
|
|
|
|
|
|
#define IDirectSoundFXI3DL2Reverb_Release(a) (a)->lpVtbl->Release(a)
|
|
|
|
#define IDirectSoundFXI3DL2Reverb_SetAllParameters(a,b) (a)->lpVtbl->SetAllParameters(a,b)
|
2011-01-04 02:56:16 +00:00
|
|
|
#endif
|
2010-12-24 05:42:04 +00:00
|
|
|
|
2010-12-23 08:53:23 +00:00
|
|
|
#if _MSC_VER <= 1200
|
2016-12-07 18:45:25 +00:00
|
|
|
#define FORCE_DEFINE_GUID DEFINE_GUID
|
2010-12-23 08:53:23 +00:00
|
|
|
#else
|
2016-12-07 18:45:25 +00:00
|
|
|
#ifndef DECLSPEC_SELECTANY
|
|
|
|
#define DECLSPEC_SELECTANY
|
|
|
|
#endif
|
|
|
|
#define FORCE_DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
|
|
|
|
EXTERN_C const GUID DECLSPEC_SELECTANY name \
|
|
|
|
= { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
|
2010-11-11 13:01:23 +00:00
|
|
|
#endif
|
2009-11-04 21:16:50 +00:00
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
#if DIRECTSOUND_VERSION >= 0x0800
|
|
|
|
FORCE_DEFINE_GUID(IID_IDirectSoundBuffer8, 0x6825a449, 0x7524, 0x4d82, 0x92, 0x0f, 0x50, 0xe3, 0x6a, 0xb3, 0xab, 0x1e);
|
|
|
|
FORCE_DEFINE_GUID(IID_IDirectSound8, 0xC50A7E93, 0xF395, 0x4834, 0x9E, 0xF6, 0x7F, 0xA9, 0x9D, 0xE5, 0x09, 0x66);
|
|
|
|
FORCE_DEFINE_GUID(IID_IDirectSoundFXI3DL2Reverb, 0x4b166a6a, 0x0d66, 0x43f3, 0x80, 0xe3, 0xee, 0x62, 0x80, 0xde, 0xe1, 0xa4);
|
|
|
|
FORCE_DEFINE_GUID(GUID_DSFX_STANDARD_I3DL2REVERB, 0xef985e71, 0xd5c7, 0x42d4, 0xba, 0x4d, 0x2d, 0x07, 0x3e, 0x2e, 0x96, 0xf4);
|
|
|
|
HRESULT (WINAPI *pDirectSoundCreate8)(GUID FAR *lpGUID, LPDIRECTSOUND8 FAR *lplpDS, IUnknown FAR *pUnkOuter);
|
|
|
|
#endif
|
2005-06-13 06:06:15 +00:00
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
FORCE_DEFINE_GUID(IID_IDirectSound, 0x279AFA83, 0x4981, 0x11CE, 0xA5, 0x21, 0x00, 0x20, 0xAF, 0x0B, 0xE5, 0x60);
|
|
|
|
FORCE_DEFINE_GUID(IID_IKsPropertySet, 0x31efac30, 0x515c, 0x11d0, 0xa9, 0xaa, 0x00, 0xaa, 0x00, 0x61, 0xbe, 0x93);
|
2005-06-13 06:06:15 +00:00
|
|
|
HRESULT (WINAPI *pDirectSoundCreate)(GUID FAR *lpGUID, LPDIRECTSOUND FAR *lplpDS, IUnknown FAR *pUnkOuter);
|
2013-09-06 22:57:44 +00:00
|
|
|
HRESULT (WINAPI *pDirectSoundEnumerate)(LPDSENUMCALLBACKA lpCallback, LPVOID lpContext);
|
2011-04-30 17:21:10 +00:00
|
|
|
#if defined(VOICECHAT)
|
2005-06-13 06:06:15 +00:00
|
|
|
HRESULT (WINAPI *pDirectSoundCaptureCreate)(GUID FAR *lpGUID, LPDIRECTSOUNDCAPTURE FAR *lplpDS, IUnknown FAR *pUnkOuter);
|
2013-09-06 22:57:44 +00:00
|
|
|
HRESULT (WINAPI *pDirectSoundCaptureEnumerate)(LPDSENUMCALLBACK lpDSEnumCallback, LPVOID lpContext);
|
2006-10-05 21:59:43 +00:00
|
|
|
#endif
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
// 64K is > 1 second at 16-bit, 22050 Hz
|
|
|
|
#define WAV_BUFFERS 64
|
|
|
|
#define WAV_MASK 0x3F
|
|
|
|
#define WAV_BUFFER_SIZE 0x0400
|
|
|
|
#define SECONDARY_BUFFER_SIZE 0x10000
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
LPDIRECTSOUND pDS;
|
|
|
|
LPDIRECTSOUNDBUFFER pDSBuf;
|
|
|
|
LPDIRECTSOUNDBUFFER pDSPBuf;
|
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
#if DIRECTSOUND_VERSION >= 0x0800
|
|
|
|
//dsound8 interfaces, for reverb effects
|
|
|
|
LPDIRECTSOUND8 pDS8;
|
|
|
|
LPDIRECTSOUNDBUFFER8 pDSBuf8;
|
|
|
|
IDirectSoundFXI3DL2Reverb8 *pReverb;
|
|
|
|
#endif
|
|
|
|
|
2005-06-13 06:06:15 +00:00
|
|
|
DWORD gSndBufSize;
|
|
|
|
DWORD mmstarttime;
|
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
int curreverb;
|
|
|
|
int curreverbmodcount; //so it updates if the effect itself is updated
|
|
|
|
|
2005-06-13 06:06:15 +00:00
|
|
|
#ifdef _IKsPropertySet_
|
|
|
|
LPKSPROPERTYSET EaxKsPropertiesSet;
|
|
|
|
#endif
|
|
|
|
} dshandle_t;
|
|
|
|
|
|
|
|
HINSTANCE hInstDS;
|
|
|
|
|
|
|
|
static void DSOUND_Restore(soundcardinfo_t *sc)
|
|
|
|
{
|
|
|
|
DWORD dwStatus;
|
|
|
|
dshandle_t *dh = sc->handle;
|
2016-12-07 18:45:25 +00:00
|
|
|
if (IDirectSoundBuffer_GetStatus (dh->pDSBuf, &dwStatus) != ERROR_SUCCESS)
|
2005-06-13 06:06:15 +00:00
|
|
|
Con_Printf ("Couldn't get sound buffer status\n");
|
|
|
|
|
|
|
|
if (dwStatus & DSBSTATUS_BUFFERLOST)
|
2016-12-07 18:45:25 +00:00
|
|
|
IDirectSoundBuffer_Restore (dh->pDSBuf);
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
if (!(dwStatus & DSBSTATUS_PLAYING))
|
2016-12-07 18:45:25 +00:00
|
|
|
IDirectSoundBuffer_Play(dh->pDSBuf, 0, 0, DSBPLAY_LOOPING);
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
|
2013-07-26 17:19:06 +00:00
|
|
|
static DWORD dsound_locksize;
|
2012-04-09 19:12:12 +00:00
|
|
|
static void *DSOUND_Lock(soundcardinfo_t *sc, unsigned int *sampidx)
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
void *ret;
|
|
|
|
int reps;
|
|
|
|
DWORD dwSize2=0;
|
|
|
|
DWORD *pbuf2;
|
|
|
|
HRESULT hresult;
|
|
|
|
|
|
|
|
dshandle_t *dh = sc->handle;
|
2013-07-26 17:19:06 +00:00
|
|
|
dsound_locksize=0;
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
reps = 0;
|
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
while ((hresult = IDirectSoundBuffer_Lock(dh->pDSBuf, 0, dh->gSndBufSize, (void**)&ret, &dsound_locksize,
|
2005-06-13 06:06:15 +00:00
|
|
|
(void**)&pbuf2, &dwSize2, 0)) != DS_OK)
|
|
|
|
{
|
|
|
|
if (hresult != DSERR_BUFFERLOST)
|
|
|
|
{
|
|
|
|
Con_Printf ("S_TransferStereo16: DS::Lock Sound Buffer Failed\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (++reps > 10000)
|
|
|
|
{
|
|
|
|
Con_Printf ("S_TransferStereo16: DS: couldn't restore buffer\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DSOUND_Restore(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
//called when the mixer is done with it.
|
|
|
|
static void DSOUND_Unlock(soundcardinfo_t *sc, void *buffer)
|
|
|
|
{
|
|
|
|
dshandle_t *dh = sc->handle;
|
2016-12-07 18:45:25 +00:00
|
|
|
IDirectSoundBuffer_Unlock(dh->pDSBuf, buffer, dsound_locksize, NULL, 0);
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
FreeSound
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
//per device
|
2013-04-07 08:59:05 +00:00
|
|
|
static void DSOUND_Shutdown_Internal (soundcardinfo_t *sc)
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
dshandle_t *dh = sc->handle;
|
|
|
|
if (!dh)
|
|
|
|
return;
|
2012-02-27 12:23:15 +00:00
|
|
|
|
2005-06-13 06:06:15 +00:00
|
|
|
sc->handle = NULL;
|
2006-10-05 21:59:43 +00:00
|
|
|
#ifdef _IKsPropertySet_
|
2005-06-13 06:06:15 +00:00
|
|
|
if (dh->EaxKsPropertiesSet)
|
|
|
|
IKsPropertySet_Release(dh->EaxKsPropertiesSet);
|
2016-12-07 18:45:25 +00:00
|
|
|
dh->EaxKsPropertiesSet = NULL;
|
2006-10-05 21:59:43 +00:00
|
|
|
#endif
|
2016-12-07 18:45:25 +00:00
|
|
|
|
|
|
|
#if DIRECTSOUND_VERSION >= 0x0800
|
|
|
|
if (dh->pReverb)
|
|
|
|
IDirectSoundFXI3DL2Reverb_Release(dh->pReverb);
|
|
|
|
dh->pReverb = NULL;
|
|
|
|
if (dh->pDSBuf8)
|
|
|
|
IDirectSoundBuffer8_Release(dh->pDSBuf8);
|
|
|
|
dh->pDSBuf8 = NULL;
|
|
|
|
#endif
|
|
|
|
|
2005-06-13 06:06:15 +00:00
|
|
|
if (dh->pDSBuf)
|
|
|
|
{
|
2016-12-07 18:45:25 +00:00
|
|
|
IDirectSoundBuffer_Stop(dh->pDSBuf);
|
|
|
|
IDirectSoundBuffer_Release(dh->pDSBuf);
|
|
|
|
if (dh->pDSBuf == dh->pDSPBuf)
|
|
|
|
dh->pDSPBuf = NULL;
|
|
|
|
dh->pDSBuf = NULL;
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
if (dh->pDSPBuf)
|
|
|
|
IDirectSoundBuffer_Release(dh->pDSPBuf);
|
|
|
|
dh->pDSPBuf = NULL;
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
if (dh->pDS)
|
|
|
|
{
|
2016-12-07 18:45:25 +00:00
|
|
|
IDirectSound_SetCooperativeLevel (dh->pDS, mainwindow, DSSCL_NORMAL);
|
|
|
|
IDirectSound_Release(dh->pDS);
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dh->pDS = NULL;
|
|
|
|
|
|
|
|
Z_Free(dh);
|
|
|
|
}
|
|
|
|
|
2013-04-07 08:59:05 +00:00
|
|
|
static void DSOUND_Shutdown (soundcardinfo_t *sc)
|
|
|
|
{
|
|
|
|
#ifdef MULTITHREAD
|
|
|
|
if (sc->thread)
|
|
|
|
{
|
|
|
|
//thread does the actual closing.
|
|
|
|
sc->selfpainting = false;
|
|
|
|
Sys_WaitOnThread(sc->thread);
|
|
|
|
sc->thread = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
DSOUND_Shutdown_Internal(sc);
|
|
|
|
}
|
|
|
|
|
2005-06-13 06:06:15 +00:00
|
|
|
/*
|
|
|
|
Direct Sound.
|
|
|
|
These following defs should be moved to winquake.h somewhere.
|
|
|
|
|
|
|
|
We tell DS to use a different wave format. We do this to gain extra channels. >2
|
|
|
|
We still use the old stuff too, when we can for compatability.
|
|
|
|
|
|
|
|
EAX 2 is also supported.
|
|
|
|
This is a global state. Once applied, it's applied for other programs too.
|
|
|
|
We have to do a few special things to try to ensure support in all it's different versions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* new formatTag:*/
|
2010-10-02 02:25:39 +00:00
|
|
|
#ifndef WAVE_FORMAT_EXTENSIBLE
|
2005-06-13 06:06:15 +00:00
|
|
|
# define WAVE_FORMAT_EXTENSIBLE (0xfffe)
|
2010-10-02 02:25:39 +00:00
|
|
|
#endif
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
/* Speaker Positions:*/
|
|
|
|
# define SPEAKER_FRONT_LEFT 0x1
|
|
|
|
# define SPEAKER_FRONT_RIGHT 0x2
|
|
|
|
# define SPEAKER_FRONT_CENTER 0x4
|
|
|
|
# define SPEAKER_LOW_FREQUENCY 0x8
|
|
|
|
# define SPEAKER_BACK_LEFT 0x10
|
|
|
|
# define SPEAKER_BACK_RIGHT 0x20
|
|
|
|
# define SPEAKER_FRONT_LEFT_OF_CENTER 0x40
|
|
|
|
# define SPEAKER_FRONT_RIGHT_OF_CENTER 0x80
|
|
|
|
# define SPEAKER_BACK_CENTER 0x100
|
|
|
|
# define SPEAKER_SIDE_LEFT 0x200
|
|
|
|
# define SPEAKER_SIDE_RIGHT 0x400
|
|
|
|
# define SPEAKER_TOP_CENTER 0x800
|
|
|
|
# define SPEAKER_TOP_FRONT_LEFT 0x1000
|
|
|
|
# define SPEAKER_TOP_FRONT_CENTER 0x2000
|
|
|
|
# define SPEAKER_TOP_FRONT_RIGHT 0x4000
|
|
|
|
# define SPEAKER_TOP_BACK_LEFT 0x8000
|
|
|
|
# define SPEAKER_TOP_BACK_CENTER 0x10000
|
|
|
|
# define SPEAKER_TOP_BACK_RIGHT 0x20000
|
|
|
|
|
|
|
|
/* Bit mask locations reserved for future use*/
|
2016-12-07 18:45:25 +00:00
|
|
|
#ifndef SPEAKER_RESERVED
|
2005-06-13 06:06:15 +00:00
|
|
|
# define SPEAKER_RESERVED 0x7FFC0000
|
2016-12-07 18:45:25 +00:00
|
|
|
#endif
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
/* Used to specify that any possible permutation of speaker configurations*/
|
|
|
|
# define SPEAKER_ALL 0x80000000
|
|
|
|
|
|
|
|
/* DirectSound Speaker Config*/
|
|
|
|
# define KSAUDIO_SPEAKER_MONO (SPEAKER_FRONT_CENTER)
|
|
|
|
# define KSAUDIO_SPEAKER_STEREO (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT)
|
|
|
|
# define KSAUDIO_SPEAKER_QUAD (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | \
|
|
|
|
SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT)
|
|
|
|
# define KSAUDIO_SPEAKER_SURROUND (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | \
|
|
|
|
SPEAKER_FRONT_CENTER | SPEAKER_BACK_CENTER)
|
|
|
|
# define KSAUDIO_SPEAKER_5POINT1 (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | \
|
|
|
|
SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | \
|
|
|
|
SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT)
|
|
|
|
# define KSAUDIO_SPEAKER_7POINT1 (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | \
|
|
|
|
SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | \
|
|
|
|
SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | \
|
|
|
|
SPEAKER_FRONT_LEFT_OF_CENTER | SPEAKER_FRONT_RIGHT_OF_CENTER)
|
|
|
|
|
|
|
|
typedef struct {
|
2010-11-11 13:01:23 +00:00
|
|
|
WAVEFORMATEX Format;
|
2005-06-13 06:06:15 +00:00
|
|
|
union {
|
|
|
|
WORD wValidBitsPerSample; /* bits of precision */
|
|
|
|
WORD wSamplesPerBlock; /* valid if wBitsPerSample==0 */
|
|
|
|
WORD wReserved; /* If neither applies, set to */
|
|
|
|
/* zero. */
|
|
|
|
} Samples;
|
|
|
|
DWORD dwChannelMask; /* which channels are */
|
|
|
|
/* present in stream */
|
|
|
|
GUID SubFormat;
|
|
|
|
} QWAVEFORMATEX;
|
|
|
|
|
2012-07-05 19:42:36 +00:00
|
|
|
const static GUID QKSDATAFORMAT_SUBTYPE_PCM = {0x00000001,0x0000,0x0010,
|
2005-06-13 06:06:15 +00:00
|
|
|
{0x80,
|
|
|
|
0x00,
|
|
|
|
0x00,
|
|
|
|
0xaa,
|
|
|
|
0x00,
|
|
|
|
0x38,
|
|
|
|
0x9b,
|
|
|
|
0x71}};
|
|
|
|
|
|
|
|
#ifdef _IKsPropertySet_
|
|
|
|
const static GUID CLSID_EAXDIRECTSOUND = {0x4ff53b81, 0x1ce0, 0x11d3,
|
|
|
|
{0xaa, 0xb8, 0x0, 0xa0, 0xc9, 0x59, 0x49, 0xd5}};
|
2010-11-11 13:01:23 +00:00
|
|
|
const static GUID DSPROPSETID_EAX20_LISTENERPROPERTIES = {0x306a6a8, 0xb224, 0x11d2,
|
2005-06-13 06:06:15 +00:00
|
|
|
{0x99, 0xe5, 0x0, 0x0, 0xe8, 0xd8, 0xc7, 0x22}};
|
|
|
|
|
|
|
|
typedef struct _EAXLISTENERPROPERTIES
|
|
|
|
{
|
|
|
|
long lRoom; // room effect level at low frequencies
|
|
|
|
long lRoomHF; // room effect high-frequency level re. low frequency level
|
|
|
|
float flRoomRolloffFactor; // like DS3D flRolloffFactor but for room effect
|
|
|
|
float flDecayTime; // reverberation decay time at low frequencies
|
|
|
|
float flDecayHFRatio; // high-frequency to low-frequency decay time ratio
|
|
|
|
long lReflections; // early reflections level relative to room effect
|
|
|
|
float flReflectionsDelay; // initial reflection delay time
|
|
|
|
long lReverb; // late reverberation level relative to room effect
|
|
|
|
float flReverbDelay; // late reverberation delay time relative to initial reflection
|
|
|
|
unsigned long dwEnvironment; // sets all listener properties
|
|
|
|
float flEnvironmentSize; // environment size in meters
|
|
|
|
float flEnvironmentDiffusion; // environment diffusion
|
|
|
|
float flAirAbsorptionHF; // change in level per meter at 5 kHz
|
|
|
|
unsigned long dwFlags; // modifies the behavior of properties
|
|
|
|
} EAXLISTENERPROPERTIES, *LPEAXLISTENERPROPERTIES;
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
EAX_ENVIRONMENT_GENERIC,
|
|
|
|
EAX_ENVIRONMENT_PADDEDCELL,
|
|
|
|
EAX_ENVIRONMENT_ROOM,
|
|
|
|
EAX_ENVIRONMENT_BATHROOM,
|
|
|
|
EAX_ENVIRONMENT_LIVINGROOM,
|
|
|
|
EAX_ENVIRONMENT_STONEROOM,
|
|
|
|
EAX_ENVIRONMENT_AUDITORIUM,
|
|
|
|
EAX_ENVIRONMENT_CONCERTHALL,
|
|
|
|
EAX_ENVIRONMENT_CAVE,
|
|
|
|
EAX_ENVIRONMENT_ARENA,
|
|
|
|
EAX_ENVIRONMENT_HANGAR,
|
|
|
|
EAX_ENVIRONMENT_CARPETEDHALLWAY,
|
|
|
|
EAX_ENVIRONMENT_HALLWAY,
|
|
|
|
EAX_ENVIRONMENT_STONECORRIDOR,
|
|
|
|
EAX_ENVIRONMENT_ALLEY,
|
|
|
|
EAX_ENVIRONMENT_FOREST,
|
|
|
|
EAX_ENVIRONMENT_CITY,
|
|
|
|
EAX_ENVIRONMENT_MOUNTAINS,
|
|
|
|
EAX_ENVIRONMENT_QUARRY,
|
|
|
|
EAX_ENVIRONMENT_PLAIN,
|
|
|
|
EAX_ENVIRONMENT_PARKINGLOT,
|
|
|
|
EAX_ENVIRONMENT_SEWERPIPE,
|
|
|
|
EAX_ENVIRONMENT_UNDERWATER,
|
|
|
|
EAX_ENVIRONMENT_DRUGGED,
|
|
|
|
EAX_ENVIRONMENT_DIZZY,
|
|
|
|
EAX_ENVIRONMENT_PSYCHOTIC,
|
|
|
|
|
|
|
|
EAX_ENVIRONMENT_COUNT
|
|
|
|
};
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
DSPROPERTY_EAXLISTENER_NONE,
|
|
|
|
DSPROPERTY_EAXLISTENER_ALLPARAMETERS,
|
|
|
|
DSPROPERTY_EAXLISTENER_ROOM,
|
|
|
|
DSPROPERTY_EAXLISTENER_ROOMHF,
|
|
|
|
DSPROPERTY_EAXLISTENER_ROOMROLLOFFFACTOR,
|
|
|
|
DSPROPERTY_EAXLISTENER_DECAYTIME,
|
|
|
|
DSPROPERTY_EAXLISTENER_DECAYHFRATIO,
|
|
|
|
DSPROPERTY_EAXLISTENER_REFLECTIONS,
|
|
|
|
DSPROPERTY_EAXLISTENER_REFLECTIONSDELAY,
|
|
|
|
DSPROPERTY_EAXLISTENER_REVERB,
|
|
|
|
DSPROPERTY_EAXLISTENER_REVERBDELAY,
|
|
|
|
DSPROPERTY_EAXLISTENER_ENVIRONMENT,
|
|
|
|
DSPROPERTY_EAXLISTENER_ENVIRONMENTSIZE,
|
|
|
|
DSPROPERTY_EAXLISTENER_ENVIRONMENTDIFFUSION,
|
|
|
|
DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF,
|
|
|
|
DSPROPERTY_EAXLISTENER_FLAGS
|
|
|
|
} DSPROPERTY_EAX_LISTENERPROPERTY;
|
|
|
|
|
|
|
|
const static GUID DSPROPSETID_EAX20_BUFFERPROPERTIES ={
|
2010-11-11 13:01:23 +00:00
|
|
|
0x306a6a7,
|
|
|
|
0xb224,
|
|
|
|
0x11d2,
|
2005-06-13 06:06:15 +00:00
|
|
|
{0x99, 0xe5, 0x0, 0x0, 0xe8, 0xd8, 0xc7, 0x22}};
|
|
|
|
|
|
|
|
const static GUID CLSID_EAXDirectSound ={
|
2010-11-11 13:01:23 +00:00
|
|
|
0x4ff53b81,
|
|
|
|
0x1ce0,
|
2005-06-13 06:06:15 +00:00
|
|
|
0x11d3,
|
|
|
|
{0xaa, 0xb8, 0x0, 0xa0, 0xc9, 0x59, 0x49, 0xd5}};
|
|
|
|
|
|
|
|
typedef struct _EAXBUFFERPROPERTIES
|
|
|
|
{
|
|
|
|
long lDirect; // direct path level
|
|
|
|
long lDirectHF; // direct path level at high frequencies
|
|
|
|
long lRoom; // room effect level
|
|
|
|
long lRoomHF; // room effect level at high frequencies
|
|
|
|
float flRoomRolloffFactor; // like DS3D flRolloffFactor but for room effect
|
2010-11-11 13:01:23 +00:00
|
|
|
long lObstruction; // main obstruction control (attenuation at high frequencies)
|
2005-06-13 06:06:15 +00:00
|
|
|
float flObstructionLFRatio; // obstruction low-frequency level re. main control
|
|
|
|
long lOcclusion; // main occlusion control (attenuation at high frequencies)
|
|
|
|
float flOcclusionLFRatio; // occlusion low-frequency level re. main control
|
|
|
|
float flOcclusionRoomRatio; // occlusion room effect level re. main control
|
|
|
|
long lOutsideVolumeHF; // outside sound cone level at high frequencies
|
|
|
|
float flAirAbsorptionFactor; // multiplies DSPROPERTY_EAXLISTENER_AIRABSORPTIONHF
|
|
|
|
unsigned long dwFlags; // modifies the behavior of properties
|
|
|
|
} EAXBUFFERPROPERTIES, *LPEAXBUFFERPROPERTIES;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
DSPROPERTY_EAXBUFFER_NONE,
|
|
|
|
DSPROPERTY_EAXBUFFER_ALLPARAMETERS,
|
|
|
|
DSPROPERTY_EAXBUFFER_DIRECT,
|
|
|
|
DSPROPERTY_EAXBUFFER_DIRECTHF,
|
|
|
|
DSPROPERTY_EAXBUFFER_ROOM,
|
2010-11-11 13:01:23 +00:00
|
|
|
DSPROPERTY_EAXBUFFER_ROOMHF,
|
2005-06-13 06:06:15 +00:00
|
|
|
DSPROPERTY_EAXBUFFER_ROOMROLLOFFFACTOR,
|
|
|
|
DSPROPERTY_EAXBUFFER_OBSTRUCTION,
|
|
|
|
DSPROPERTY_EAXBUFFER_OBSTRUCTIONLFRATIO,
|
2010-11-11 13:01:23 +00:00
|
|
|
DSPROPERTY_EAXBUFFER_OCCLUSION,
|
2005-06-13 06:06:15 +00:00
|
|
|
DSPROPERTY_EAXBUFFER_OCCLUSIONLFRATIO,
|
|
|
|
DSPROPERTY_EAXBUFFER_OCCLUSIONROOMRATIO,
|
|
|
|
DSPROPERTY_EAXBUFFER_OUTSIDEVOLUMEHF,
|
|
|
|
DSPROPERTY_EAXBUFFER_AIRABSORPTIONFACTOR,
|
|
|
|
DSPROPERTY_EAXBUFFER_FLAGS
|
2010-11-11 13:01:23 +00:00
|
|
|
} DSPROPERTY_EAX_BUFFERPROPERTY;
|
2005-06-13 06:06:15 +00:00
|
|
|
#endif
|
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
static long GainToMillibels(float gain)
|
|
|
|
{
|
|
|
|
return 100*20*(0.43429*log(gain));
|
|
|
|
}
|
|
|
|
static void DSOUND_SetReverb(soundcardinfo_t *sc, size_t reverbidx)
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
dshandle_t *dh = sc->handle;
|
2016-12-07 18:45:25 +00:00
|
|
|
struct reverbproperties_s *prop;
|
|
|
|
if (reverbidx >= numreverbproperties)
|
|
|
|
return; //invalid
|
|
|
|
if (dh->curreverb == reverbidx && dh->curreverbmodcount == reverbproperties[reverbidx].modificationcount)
|
|
|
|
return; //nothing changed.
|
|
|
|
dh->curreverb = reverbidx;
|
|
|
|
dh->curreverbmodcount = reverbproperties[reverbidx].modificationcount;
|
|
|
|
|
|
|
|
prop = &reverbproperties[dh->curreverb].props;
|
2005-06-13 06:06:15 +00:00
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
#ifdef _IKsPropertySet_
|
2005-06-13 06:06:15 +00:00
|
|
|
//attempt at eax support.
|
|
|
|
//EAX is a global thing. Get it going in a game and your media player will be doing it too.
|
|
|
|
|
|
|
|
if (dh->EaxKsPropertiesSet) //only on ds cards.
|
|
|
|
{
|
|
|
|
EAXLISTENERPROPERTIES ListenerProperties = {0};
|
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
ListenerProperties.flEnvironmentSize = prop->flEchoTime;
|
|
|
|
ListenerProperties.flEnvironmentDiffusion = prop->flDiffusion;
|
|
|
|
ListenerProperties.lRoom = GainToMillibels(prop->flGain);
|
|
|
|
ListenerProperties.lRoomHF = GainToMillibels(prop->flGainHF);
|
|
|
|
ListenerProperties.flRoomRolloffFactor = prop->flRoomRolloffFactor;
|
|
|
|
ListenerProperties.flAirAbsorptionHF = prop->flAirAbsorptionGainHF;
|
|
|
|
ListenerProperties.lReflections = GainToMillibels(prop->flReflectionsGain);
|
|
|
|
ListenerProperties.flReflectionsDelay = prop->flReflectionsDelay;
|
|
|
|
ListenerProperties.lReverb = GainToMillibels(prop->flLateReverbGain);
|
|
|
|
ListenerProperties.flReverbDelay = prop->flLateReverbDelay;
|
|
|
|
ListenerProperties.flDecayTime = prop->flDecayTime;
|
|
|
|
ListenerProperties.flDecayHFRatio = prop->flDecayHFRatio;
|
|
|
|
ListenerProperties.dwFlags = 0x3f;
|
|
|
|
ListenerProperties.dwEnvironment = reverbidx?EAX_ENVIRONMENT_UNDERWATER:0;
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
if (FAILED(IKsPropertySet_Set(dh->EaxKsPropertiesSet, &DSPROPSETID_EAX20_LISTENERPROPERTIES,
|
|
|
|
DSPROPERTY_EAXLISTENER_ALLPARAMETERS, 0, 0, &ListenerProperties,
|
|
|
|
sizeof(ListenerProperties))))
|
|
|
|
Con_SafePrintf ("EAX set failed\n");
|
|
|
|
}
|
|
|
|
#endif
|
2016-12-07 18:45:25 +00:00
|
|
|
|
|
|
|
#if DIRECTSOUND_VERSION >= 0x0800
|
|
|
|
if (dh->pReverb)
|
|
|
|
{
|
|
|
|
DSFXI3DL2Reverb reverb;
|
|
|
|
reverb.lRoom = bound(-10000, GainToMillibels(prop->flGain), 0); // [-10000, 0] default: -1000 mB
|
|
|
|
reverb.lRoomHF = bound(-10000, GainToMillibels(prop->flGainHF), 0); // [-10000, 0] default: 0 mB
|
|
|
|
reverb.flRoomRolloffFactor = bound(0.0, prop->flRoomRolloffFactor, 10.0); // [0.0, 10.0] default: 0.0
|
|
|
|
reverb.flDecayTime = bound(0.1, prop->flDecayTime, 20.0); // [0.1, 20.0] default: 1.49s
|
|
|
|
reverb.flDecayHFRatio = bound(0.1, prop->flDecayHFRatio, 2.0); // [0.1, 2.0] default: 0.83
|
|
|
|
reverb.lReflections = bound(-10000, GainToMillibels(prop->flReflectionsGain), 1000); // [-10000, 1000] default: -2602 mB
|
|
|
|
reverb.flReflectionsDelay = bound(0.0, prop->flReflectionsDelay, 0.3); // [0.0, 0.3] default: 0.007 s
|
|
|
|
reverb.lReverb = bound(-10000, GainToMillibels(prop->flLateReverbGain), 2000); // [-10000, 2000] default: 200 mB
|
|
|
|
reverb.flReverbDelay = bound(0.0, prop->flLateReverbDelay, 0.1); // [0.0, 0.1] default: 0.011 s
|
|
|
|
reverb.flDiffusion = bound(0.0, prop->flDiffusion*100, 100.0); // [0.0, 100.0] default: 100.0 %
|
|
|
|
reverb.flDensity = bound(0.0, prop->flDensity*100, 100.0); // [0.0, 100.0] default: 100.0 %
|
|
|
|
reverb.flHFReference = bound(20.0, prop->flHFReference, 20000.0); // [20.0, 20000.0] default: 5000.0 Hz
|
|
|
|
|
|
|
|
IDirectSoundFXI3DL2Reverb_SetAllParameters(dh->pReverb, &reverb);
|
|
|
|
}
|
|
|
|
#endif
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
SNDDMA_GetDMAPos
|
|
|
|
|
|
|
|
return the current sample position (in mono samples read)
|
|
|
|
inside the recirculating dma buffer, so the mixing code will know
|
|
|
|
how many sample are required to fill it up.
|
|
|
|
===============
|
|
|
|
*/
|
2011-05-19 13:34:07 +00:00
|
|
|
static unsigned int DSOUND_GetDMAPos(soundcardinfo_t *sc)
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
DWORD mmtime;
|
|
|
|
int s;
|
|
|
|
DWORD dwWrite;
|
|
|
|
|
|
|
|
dshandle_t *dh = sc->handle;
|
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
IDirectSoundBuffer_GetCurrentPosition(dh->pDSBuf, &mmtime, &dwWrite);
|
2005-06-13 06:06:15 +00:00
|
|
|
s = mmtime - dh->mmstarttime;
|
|
|
|
|
|
|
|
|
|
|
|
s >>= (sc->sn.samplebits/8) - 1;
|
|
|
|
|
2006-04-09 01:53:26 +00:00
|
|
|
s %= (sc->sn.samples);
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
SNDDMA_Submit
|
|
|
|
|
|
|
|
Send sound to device if buffer isn't really the dma buffer
|
|
|
|
===============
|
|
|
|
*/
|
2011-02-02 00:41:01 +00:00
|
|
|
static void DSOUND_Submit(soundcardinfo_t *sc, int start, int end)
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-07-26 17:19:06 +00:00
|
|
|
static qboolean DSOUND_InitOutputLibrary(void)
|
|
|
|
{
|
|
|
|
if (!hInstDS)
|
|
|
|
hInstDS = LoadLibrary("dsound.dll");
|
2013-09-06 22:57:44 +00:00
|
|
|
if (!hInstDS)
|
|
|
|
{
|
|
|
|
Con_SafePrintf ("Couldn't load dsound.dll\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!pDirectSoundCreate)
|
2013-07-26 17:19:06 +00:00
|
|
|
pDirectSoundCreate = (void *)GetProcAddress(hInstDS,"DirectSoundCreate");
|
2016-12-07 18:45:25 +00:00
|
|
|
#if DIRECTSOUND_VERSION >= 0x0800
|
|
|
|
if (!pDirectSoundCreate8)
|
|
|
|
pDirectSoundCreate8 = (void *)GetProcAddress(hInstDS,"DirectSoundCreate8"); //xp+
|
|
|
|
if (!pDirectSoundCreate8)
|
|
|
|
#endif
|
2013-09-06 22:57:44 +00:00
|
|
|
{
|
2016-12-07 18:45:25 +00:00
|
|
|
if (!pDirectSoundCreate)
|
|
|
|
{
|
|
|
|
Con_SafePrintf ("Couldn't get DS proc addr\n");
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-26 17:19:06 +00:00
|
|
|
}
|
2013-09-06 22:57:44 +00:00
|
|
|
if (!pDirectSoundEnumerate)
|
|
|
|
pDirectSoundEnumerate = (void *)GetProcAddress(hInstDS,"DirectSoundEnumerateA");
|
2013-07-26 17:19:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
2005-06-13 06:06:15 +00:00
|
|
|
/*
|
|
|
|
==================
|
|
|
|
SNDDMA_InitDirect
|
|
|
|
|
|
|
|
Direct-Sound support
|
|
|
|
==================
|
|
|
|
*/
|
2013-07-26 17:19:06 +00:00
|
|
|
static int DSOUND_InitCard_Internal (soundcardinfo_t *sc, char *cardname)
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
2013-06-24 09:04:00 +00:00
|
|
|
extern cvar_t snd_inactive;
|
|
|
|
extern cvar_t snd_eax;
|
2016-12-07 18:45:25 +00:00
|
|
|
int usereverb; //2=eax, 1=ds8
|
2005-06-13 06:06:15 +00:00
|
|
|
DSBUFFERDESC dsbuf;
|
|
|
|
DSBCAPS dsbcaps;
|
|
|
|
DWORD dwSize, dwWrite;
|
|
|
|
DSCAPS dscaps;
|
2010-11-11 13:01:23 +00:00
|
|
|
QWAVEFORMATEX format, pformat;
|
2005-06-13 06:06:15 +00:00
|
|
|
HRESULT hresult;
|
|
|
|
int reps;
|
|
|
|
qboolean primary_format_set;
|
|
|
|
dshandle_t *dh;
|
|
|
|
char *buffer;
|
2013-07-26 17:19:06 +00:00
|
|
|
GUID guid, *dsguid;
|
|
|
|
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
memset (&format, 0, sizeof(format));
|
|
|
|
|
2013-07-26 17:19:06 +00:00
|
|
|
if (*sc->name)
|
|
|
|
{
|
|
|
|
wchar_t mssuck[128];
|
|
|
|
mbstowcs(mssuck, sc->name, sizeof(mssuck)/sizeof(mssuck[0])-1);
|
|
|
|
CLSIDFromString(mssuck, &guid);
|
|
|
|
dsguid = &guid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memset(&guid, 0, sizeof(GUID));
|
|
|
|
dsguid = NULL;
|
|
|
|
}
|
|
|
|
|
2011-07-06 01:40:40 +00:00
|
|
|
if (sc->sn.numchannels >= 8) // 7.1 surround
|
|
|
|
{
|
|
|
|
format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
|
|
|
|
format.Format.cbSize = 22;
|
2012-07-05 19:42:36 +00:00
|
|
|
memcpy(&format.SubFormat, &QKSDATAFORMAT_SUBTYPE_PCM, sizeof(GUID));
|
2011-07-06 01:40:40 +00:00
|
|
|
|
|
|
|
format.dwChannelMask = KSAUDIO_SPEAKER_7POINT1;
|
|
|
|
sc->sn.numchannels = 8;
|
|
|
|
}
|
|
|
|
else if (sc->sn.numchannels >= 6) //5.1 surround
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
|
|
|
|
format.Format.cbSize = 22;
|
2012-07-05 19:42:36 +00:00
|
|
|
memcpy(&format.SubFormat, &QKSDATAFORMAT_SUBTYPE_PCM, sizeof(GUID));
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
format.dwChannelMask = KSAUDIO_SPEAKER_5POINT1;
|
|
|
|
sc->sn.numchannels = 6;
|
|
|
|
}
|
2006-05-10 05:18:08 +00:00
|
|
|
else if (sc->sn.numchannels >= 4) //4 speaker quad
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
|
|
|
|
format.Format.cbSize = 22;
|
2012-07-05 19:42:36 +00:00
|
|
|
memcpy(&format.SubFormat, &QKSDATAFORMAT_SUBTYPE_PCM, sizeof(GUID));
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
format.dwChannelMask = KSAUDIO_SPEAKER_QUAD;
|
|
|
|
sc->sn.numchannels = 4;
|
|
|
|
}
|
2006-05-10 05:18:08 +00:00
|
|
|
else if (sc->sn.numchannels >= 2) //stereo
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
format.Format.wFormatTag = WAVE_FORMAT_PCM;
|
|
|
|
format.Format.cbSize = 0;
|
|
|
|
sc->sn.numchannels = 2;
|
|
|
|
}
|
|
|
|
else //mono time
|
|
|
|
{
|
|
|
|
format.Format.wFormatTag = WAVE_FORMAT_PCM;
|
|
|
|
format.Format.cbSize = 0;
|
|
|
|
sc->sn.numchannels = 1;
|
|
|
|
}
|
2010-11-11 13:01:23 +00:00
|
|
|
|
2005-06-13 06:06:15 +00:00
|
|
|
format.Format.nChannels = sc->sn.numchannels;
|
2016-12-07 18:45:25 +00:00
|
|
|
format.Format.wBitsPerSample = sc->sn.samplebits;
|
|
|
|
format.Format.nSamplesPerSec = sc->sn.speed;
|
|
|
|
format.Format.nBlockAlign = format.Format.nChannels * format.Format.wBitsPerSample / 8;
|
|
|
|
format.Format.nAvgBytesPerSec = format.Format.nSamplesPerSec * format.Format.nBlockAlign;
|
2005-06-13 06:06:15 +00:00
|
|
|
|
2013-07-26 17:19:06 +00:00
|
|
|
if (!DSOUND_InitOutputLibrary())
|
|
|
|
return false;
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
sc->handle = Z_Malloc(sizeof(dshandle_t));
|
|
|
|
dh = sc->handle;
|
2016-12-07 18:45:25 +00:00
|
|
|
|
|
|
|
usereverb = !!snd_eax.ival;
|
2005-06-13 06:06:15 +00:00
|
|
|
//EAX attempt
|
2010-12-23 08:53:23 +00:00
|
|
|
#if _MSC_VER > 1200
|
2006-10-05 21:59:43 +00:00
|
|
|
#ifdef _IKsPropertySet_
|
2005-06-13 06:06:15 +00:00
|
|
|
dh->pDS = NULL;
|
2016-12-07 18:45:25 +00:00
|
|
|
if (usereverb)
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
CoInitialize(NULL);
|
|
|
|
if (FAILED(CoCreateInstance( &CLSID_EAXDirectSound, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectSound, (void **)&dh->pDS )))
|
|
|
|
dh->pDS=NULL;
|
|
|
|
else
|
2013-07-26 17:19:06 +00:00
|
|
|
{
|
|
|
|
IDirectSound_Initialize(dh->pDS, dsguid);
|
2016-12-07 18:45:25 +00:00
|
|
|
usereverb = 2;
|
2013-07-26 17:19:06 +00:00
|
|
|
}
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!dh->pDS)
|
2006-10-05 21:59:43 +00:00
|
|
|
#endif
|
2005-06-13 06:06:15 +00:00
|
|
|
#endif
|
|
|
|
{
|
2016-12-07 18:45:25 +00:00
|
|
|
for(;;)
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
2016-12-07 18:45:25 +00:00
|
|
|
dh->pDS = NULL;
|
|
|
|
#if DIRECTSOUND_VERSION >= 0x0800
|
|
|
|
dh->pDS8 = NULL;
|
|
|
|
if (pDirectSoundCreate8)
|
|
|
|
{
|
|
|
|
hresult = pDirectSoundCreate8(dsguid, &dh->pDS8, NULL);
|
|
|
|
dh->pDS = (void*)dh->pDS8; //evil cast
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
hresult = pDirectSoundCreate(dsguid, &dh->pDS, NULL);
|
|
|
|
if (hresult == DS_OK)
|
|
|
|
break;
|
|
|
|
|
2005-06-13 06:06:15 +00:00
|
|
|
if (hresult != DSERR_ALLOCATED)
|
|
|
|
{
|
|
|
|
Con_SafePrintf (": create failed\n");
|
2013-07-26 17:19:06 +00:00
|
|
|
return false;
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if (MessageBox (NULL,
|
|
|
|
// "The sound hardware is in use by another app.\n\n"
|
|
|
|
// "Select Retry to try to start sound again or Cancel to run Quake with no sound.",
|
|
|
|
// "Sound not available",
|
|
|
|
// MB_RETRYCANCEL | MB_SETFOREGROUND | MB_ICONEXCLAMATION) != IDRETRY)
|
|
|
|
// {
|
|
|
|
Con_SafePrintf (": failure\n"
|
|
|
|
" hardware already in use\n"
|
|
|
|
" Close the other app then use snd_restart\n");
|
2013-07-26 17:19:06 +00:00
|
|
|
return false;
|
2005-06-13 06:06:15 +00:00
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-09 09:25:28 +00:00
|
|
|
#ifdef FTE_SDL
|
2013-07-26 17:19:06 +00:00
|
|
|
#define mainwindow GetDesktopWindow()
|
|
|
|
#endif
|
2016-12-07 18:45:25 +00:00
|
|
|
if (DS_OK != IDirectSound_SetCooperativeLevel (dh->pDS, mainwindow, DSSCL_EXCLUSIVE))
|
2013-07-26 17:19:06 +00:00
|
|
|
{
|
|
|
|
Con_SafePrintf ("Set coop level failed\n");
|
|
|
|
DSOUND_Shutdown_Internal (sc);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-06-13 06:06:15 +00:00
|
|
|
dscaps.dwSize = sizeof(dscaps);
|
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
if (DS_OK != IDirectSound_GetCaps (dh->pDS, &dscaps))
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
Con_SafePrintf ("Couldn't get DS caps\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dscaps.dwFlags & DSCAPS_EMULDRIVER)
|
|
|
|
{
|
|
|
|
Con_SafePrintf ("No DirectSound driver installed\n");
|
2013-04-07 08:59:05 +00:00
|
|
|
DSOUND_Shutdown_Internal (sc);
|
2013-07-26 17:19:06 +00:00
|
|
|
return false;
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// get access to the primary buffer, if possible, so we can set the
|
|
|
|
// sound hardware format
|
|
|
|
memset (&dsbuf, 0, sizeof(dsbuf));
|
|
|
|
dsbuf.dwSize = sizeof(DSBUFFERDESC);
|
|
|
|
dsbuf.dwFlags = DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME;
|
|
|
|
dsbuf.dwBufferBytes = 0;
|
|
|
|
dsbuf.lpwfxFormat = NULL;
|
|
|
|
|
2006-10-05 21:59:43 +00:00
|
|
|
#ifdef DSBCAPS_GLOBALFOCUS
|
2014-02-09 09:25:28 +00:00
|
|
|
#ifndef FTE_SDL
|
2013-03-12 23:09:25 +00:00
|
|
|
if (snd_inactive.ival || sys_parentwindow
|
2012-01-03 23:44:01 +00:00
|
|
|
) /*always inactive if we have a parent window, because we can't tell properly otherwise*/
|
2013-04-09 00:18:38 +00:00
|
|
|
#endif
|
2005-06-21 01:39:36 +00:00
|
|
|
{
|
|
|
|
dsbuf.dwFlags |= DSBCAPS_GLOBALFOCUS;
|
|
|
|
sc->inactive_sound = true;
|
|
|
|
}
|
2006-10-05 21:59:43 +00:00
|
|
|
#endif
|
2005-06-21 01:39:36 +00:00
|
|
|
|
2005-06-13 06:06:15 +00:00
|
|
|
memset(&dsbcaps, 0, sizeof(dsbcaps));
|
|
|
|
dsbcaps.dwSize = sizeof(dsbcaps);
|
|
|
|
primary_format_set = false;
|
|
|
|
|
|
|
|
if (!COM_CheckParm ("-snoforceformat"))
|
|
|
|
{
|
2016-12-07 18:45:25 +00:00
|
|
|
if (DS_OK == IDirectSound_CreateSoundBuffer(dh->pDS, &dsbuf, &dh->pDSPBuf, NULL))
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
pformat = format;
|
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
if (DS_OK != IDirectSoundBuffer_SetFormat (dh->pDSPBuf, (WAVEFORMATEX *)&pformat))
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
// if (snd_firsttime)
|
|
|
|
// Con_SafePrintf ("Set primary sound buffer format: no\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
// {
|
|
|
|
// if (snd_firsttime)
|
|
|
|
// Con_SafePrintf ("Set primary sound buffer format: yes\n");
|
|
|
|
|
|
|
|
primary_format_set = true;
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!primary_format_set || !COM_CheckParm ("-primarysound"))
|
|
|
|
{
|
|
|
|
// create the secondary buffer we'll actually work with
|
|
|
|
memset (&dsbuf, 0, sizeof(dsbuf));
|
|
|
|
dsbuf.dwSize = sizeof(DSBUFFERDESC);
|
2006-02-01 22:36:12 +00:00
|
|
|
dsbuf.dwFlags = DSBCAPS_CTRLFREQUENCY|DSBCAPS_LOCSOFTWARE; //dmw 29 may, 2003 removed locsoftware
|
2016-12-07 18:45:25 +00:00
|
|
|
|
|
|
|
#if DIRECTSOUND_VERSION >= 0x0800
|
|
|
|
if (usereverb == 1)
|
|
|
|
dsbuf.dwFlags |= DSBCAPS_CTRLFX;
|
|
|
|
#endif
|
|
|
|
|
2006-10-05 21:59:43 +00:00
|
|
|
#ifdef DSBCAPS_GLOBALFOCUS
|
2009-11-04 21:16:50 +00:00
|
|
|
if (snd_inactive.ival)
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
dsbuf.dwFlags |= DSBCAPS_GLOBALFOCUS;
|
|
|
|
sc->inactive_sound = true;
|
|
|
|
}
|
2006-10-05 21:59:43 +00:00
|
|
|
#endif
|
2006-05-10 05:18:08 +00:00
|
|
|
dsbuf.dwBufferBytes = sc->sn.samples / format.Format.nChannels;
|
|
|
|
if (!dsbuf.dwBufferBytes)
|
|
|
|
{
|
|
|
|
dsbuf.dwBufferBytes = SECONDARY_BUFFER_SIZE;
|
|
|
|
// the fast rates will need a much bigger buffer
|
|
|
|
if (format.Format.nSamplesPerSec > 48000)
|
|
|
|
dsbuf.dwBufferBytes *= 4;
|
|
|
|
}
|
2005-06-13 06:06:15 +00:00
|
|
|
dsbuf.lpwfxFormat = (WAVEFORMATEX *)&format;
|
|
|
|
|
|
|
|
memset(&dsbcaps, 0, sizeof(dsbcaps));
|
|
|
|
dsbcaps.dwSize = sizeof(dsbcaps);
|
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
if (DS_OK != IDirectSound_CreateSoundBuffer(dh->pDS, &dsbuf, &dh->pDSBuf, NULL))
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
Con_SafePrintf ("DS:CreateSoundBuffer Failed");
|
2013-04-07 08:59:05 +00:00
|
|
|
DSOUND_Shutdown_Internal (sc);
|
2013-07-26 17:19:06 +00:00
|
|
|
return false;
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sc->sn.numchannels = format.Format.nChannels;
|
|
|
|
sc->sn.samplebits = format.Format.wBitsPerSample;
|
|
|
|
sc->sn.speed = format.Format.nSamplesPerSec;
|
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
if (DS_OK != IDirectSoundBuffer_GetCaps (dh->pDSBuf, &dsbcaps))
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
Con_SafePrintf ("DS:GetCaps failed\n");
|
2013-04-07 08:59:05 +00:00
|
|
|
DSOUND_Shutdown_Internal (sc);
|
2013-07-26 17:19:06 +00:00
|
|
|
return false;
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if (snd_firsttime)
|
|
|
|
// Con_SafePrintf ("Using secondary sound buffer\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-07 18:45:25 +00:00
|
|
|
if (DS_OK != IDirectSound_SetCooperativeLevel (dh->pDS, mainwindow, DSSCL_WRITEPRIMARY))
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
Con_SafePrintf ("Set coop level failed\n");
|
2013-04-07 08:59:05 +00:00
|
|
|
DSOUND_Shutdown_Internal (sc);
|
2013-07-26 17:19:06 +00:00
|
|
|
return false;
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
if (DS_OK != IDirectSoundBuffer_GetCaps (dh->pDSPBuf, &dsbcaps))
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
Con_Printf ("DS:GetCaps failed\n");
|
2013-04-07 08:59:05 +00:00
|
|
|
DSOUND_Shutdown_Internal (sc);
|
2013-07-26 17:19:06 +00:00
|
|
|
return false;
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dh->pDSBuf = dh->pDSPBuf;
|
|
|
|
// Con_SafePrintf ("Using primary sound buffer\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
dh->gSndBufSize = dsbcaps.dwBufferBytes;
|
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
#if DIRECTSOUND_VERSION >= 0x0800
|
|
|
|
if (usereverb == 1)
|
|
|
|
{
|
|
|
|
if (SUCCEEDED(IDirectSoundBuffer_QueryInterface(dh->pDSBuf, &IID_IDirectSoundBuffer8, (void*)&dh->pDSBuf8)))
|
|
|
|
{
|
|
|
|
DSEFFECTDESC effects[1];
|
|
|
|
DWORD results[1];
|
|
|
|
memset(effects, 0, sizeof(effects));
|
|
|
|
effects[0].dwSize = sizeof(effects[0]);
|
|
|
|
effects[0].dwFlags = 0;
|
|
|
|
effects[0].guidDSFXClass = GUID_DSFX_STANDARD_I3DL2REVERB;
|
|
|
|
if (SUCCEEDED(IDirectSoundBuffer8_SetFX(dh->pDSBuf8, 1, effects, results)))
|
|
|
|
if (SUCCEEDED(IDirectSoundBuffer8_GetObjectInPath(dh->pDSBuf8, &GUID_DSFX_STANDARD_I3DL2REVERB, 0, &IID_IDirectSoundFXI3DL2Reverb8, (void*)&dh->pReverb)))
|
|
|
|
usereverb = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-06-13 06:06:15 +00:00
|
|
|
#if 1
|
|
|
|
// Make sure mixer is active
|
2016-12-07 18:45:25 +00:00
|
|
|
IDirectSoundBuffer_Play(dh->pDSBuf, 0, 0, DSBPLAY_LOOPING);
|
2005-06-13 06:06:15 +00:00
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
Con_DPrintf(" %d channel(s)\n"
|
|
|
|
" %d bits/sample\n"
|
|
|
|
" %d bytes/sec\n",
|
|
|
|
sc->sn.numchannels, sc->sn.samplebits, sc->sn.speed);
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// initialize the buffer
|
|
|
|
reps = 0;
|
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
while ((hresult = IDirectSoundBuffer_Lock(dh->pDSBuf, 0, dh->gSndBufSize, (void**)&buffer, &dwSize, NULL, NULL, 0)) != DS_OK)
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
if (hresult != DSERR_BUFFERLOST)
|
|
|
|
{
|
|
|
|
Con_SafePrintf ("SNDDMA_InitDirect: DS::Lock Sound Buffer Failed\n");
|
2013-04-07 08:59:05 +00:00
|
|
|
DSOUND_Shutdown_Internal (sc);
|
2013-07-26 17:19:06 +00:00
|
|
|
return false;
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (++reps > 10000)
|
|
|
|
{
|
|
|
|
Con_SafePrintf ("SNDDMA_InitDirect: DS: couldn't restore buffer\n");
|
2013-04-07 08:59:05 +00:00
|
|
|
DSOUND_Shutdown_Internal (sc);
|
2013-07-26 17:19:06 +00:00
|
|
|
return false;
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(buffer, 0, dwSize);
|
|
|
|
// lpData[4] = lpData[5] = 0x7f; // force a pop for debugging
|
|
|
|
|
|
|
|
// Sleep(500);
|
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
IDirectSoundBuffer_Unlock(dh->pDSBuf, buffer, dwSize, NULL, 0);
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
IDirectSoundBuffer_Stop(dh->pDSBuf);
|
2005-06-13 06:06:15 +00:00
|
|
|
#endif
|
2016-12-07 18:45:25 +00:00
|
|
|
IDirectSoundBuffer_GetCurrentPosition(dh->pDSBuf, &dh->mmstarttime, &dwWrite);
|
|
|
|
IDirectSoundBuffer_Play(dh->pDSBuf, 0, 0, DSBPLAY_LOOPING);
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
sc->sn.samples = dh->gSndBufSize/(sc->sn.samplebits/8);
|
|
|
|
sc->sn.samplepos = 0;
|
|
|
|
sc->sn.buffer = NULL;
|
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
dh->curreverb = ~0;
|
|
|
|
dh->curreverbmodcount = ~0;
|
|
|
|
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
sc->Lock = DSOUND_Lock;
|
|
|
|
sc->Unlock = DSOUND_Unlock;
|
2016-07-12 00:40:13 +00:00
|
|
|
sc->SetEnvironmentReverb = DSOUND_SetReverb;
|
2005-06-13 06:06:15 +00:00
|
|
|
sc->Submit = DSOUND_Submit;
|
|
|
|
sc->Shutdown = DSOUND_Shutdown;
|
|
|
|
sc->GetDMAPos = DSOUND_GetDMAPos;
|
|
|
|
sc->Restore = DSOUND_Restore;
|
|
|
|
|
2010-12-23 08:53:23 +00:00
|
|
|
#if _MSC_VER > 1200
|
2005-06-13 06:06:15 +00:00
|
|
|
#ifdef _IKsPropertySet_
|
|
|
|
//attempt at eax support
|
2016-12-07 18:45:25 +00:00
|
|
|
if (usereverb == 2)
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
DWORD support;
|
|
|
|
|
|
|
|
if (SUCCEEDED(IDirectSoundBuffer_QueryInterface(dh->pDSBuf, &IID_IKsPropertySet, (void*)&dh->EaxKsPropertiesSet)))
|
|
|
|
{
|
|
|
|
r = IKsPropertySet_QuerySupport(dh->EaxKsPropertiesSet, &DSPROPSETID_EAX20_LISTENERPROPERTIES, DSPROPERTY_EAXLISTENER_ALLPARAMETERS, &support);
|
|
|
|
if(!SUCCEEDED(r) || (support&(KSPROPERTY_SUPPORT_GET|KSPROPERTY_SUPPORT_SET))
|
|
|
|
!= (KSPROPERTY_SUPPORT_GET|KSPROPERTY_SUPPORT_SET))
|
|
|
|
{
|
|
|
|
IKsPropertySet_Release(dh->EaxKsPropertiesSet);
|
|
|
|
dh->EaxKsPropertiesSet = NULL;
|
|
|
|
Con_SafePrintf ("EAX 2 not supported\n");
|
2016-12-07 18:45:25 +00:00
|
|
|
//otherwise successful. It can be used for normal sound anyway.
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
2016-12-07 18:45:25 +00:00
|
|
|
else
|
|
|
|
usereverb = 0; //worked. EAX is fully inited.
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-07 18:45:25 +00:00
|
|
|
Con_DPrintf ("Couldn't get extended properties\n");
|
2005-06-13 06:06:15 +00:00
|
|
|
dh->EaxKsPropertiesSet = NULL;
|
|
|
|
}
|
|
|
|
}
|
2010-12-23 08:53:23 +00:00
|
|
|
#endif
|
2005-06-13 06:06:15 +00:00
|
|
|
#endif
|
2012-02-27 12:23:15 +00:00
|
|
|
|
2016-12-07 18:45:25 +00:00
|
|
|
if (usereverb)
|
|
|
|
Con_SafePrintf ("Couldn't enable environmental reverb effects\n");
|
|
|
|
|
2013-07-26 17:19:06 +00:00
|
|
|
return true;
|
2013-04-07 08:59:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-27 12:23:15 +00:00
|
|
|
#ifdef MULTITHREAD
|
2013-04-07 08:59:05 +00:00
|
|
|
static int DSOUND_Thread(void *arg)
|
|
|
|
{
|
|
|
|
soundcardinfo_t *sc = arg;
|
|
|
|
void *cond = sc->handle;
|
|
|
|
sc->handle = NULL;
|
|
|
|
|
|
|
|
//once creating the thread, the main thread will wait for us to signal that we have inited the dsound device.
|
2013-07-26 17:19:06 +00:00
|
|
|
if (!DSOUND_InitCard_Internal(sc, sc->name))
|
2013-04-07 08:59:05 +00:00
|
|
|
sc->selfpainting = false;
|
|
|
|
|
|
|
|
//wake up the main thread.
|
|
|
|
Sys_ConditionSignal(cond);
|
|
|
|
|
|
|
|
while(sc->selfpainting)
|
|
|
|
{
|
|
|
|
S_MixerThread(sc);
|
|
|
|
/* Quote:
|
|
|
|
On NT (Win2K and XP) the cursors in SW buffers (and HW buffers on some devices) move in 10ms increments, so calling GetCurrentPosition() every 10ms is ideal.
|
|
|
|
Calling it more often than every 5ms will cause some perf degradation.
|
|
|
|
*/
|
|
|
|
Sleep(9);
|
|
|
|
}
|
|
|
|
|
|
|
|
//we created the device, we need to kill it.
|
|
|
|
DSOUND_Shutdown_Internal(sc);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-27 12:23:15 +00:00
|
|
|
#endif
|
|
|
|
|
2013-07-26 17:19:06 +00:00
|
|
|
static qboolean QDECL DSOUND_InitCard (soundcardinfo_t *sc, const char *device)
|
2013-04-07 08:59:05 +00:00
|
|
|
{
|
|
|
|
if (COM_CheckParm("-wavonly"))
|
2013-07-26 17:19:06 +00:00
|
|
|
return false;
|
2013-04-07 08:59:05 +00:00
|
|
|
|
2013-07-26 17:19:06 +00:00
|
|
|
Q_strncpyz(sc->name, device?device:"", sizeof(sc->name));
|
2013-05-13 13:43:18 +00:00
|
|
|
|
2013-04-07 08:59:05 +00:00
|
|
|
#ifdef MULTITHREAD
|
|
|
|
if (snd_mixerthread.ival)
|
|
|
|
{
|
|
|
|
void *cond;
|
|
|
|
sc->selfpainting = true;
|
|
|
|
sc->handle = cond = Sys_CreateConditional();
|
2013-04-13 15:29:50 +00:00
|
|
|
Sys_LockConditional(cond);
|
2013-04-07 08:59:05 +00:00
|
|
|
sc->thread = Sys_CreateThread("dsoundmixer", DSOUND_Thread, sc, THREADP_HIGHEST, 0);
|
|
|
|
if (!sc->thread)
|
|
|
|
{
|
|
|
|
Con_SafePrintf ("Unable to create sound mixing thread\n");
|
2013-07-26 17:19:06 +00:00
|
|
|
return false;
|
2013-04-07 08:59:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//wait for the thread to finish (along with all its error con printfs etc
|
2014-03-30 08:55:06 +00:00
|
|
|
if (!Sys_ConditionWait(cond))
|
|
|
|
Con_SafePrintf ("Looks like the sound thread isn't starting up\n");
|
2013-04-13 15:29:50 +00:00
|
|
|
Sys_UnlockConditional(cond);
|
2013-04-07 08:59:05 +00:00
|
|
|
Sys_DestroyConditional(cond);
|
|
|
|
|
|
|
|
if (!sc->selfpainting)
|
|
|
|
{
|
|
|
|
Sys_WaitOnThread(sc->thread);
|
|
|
|
sc->thread = NULL;
|
2013-07-26 17:19:06 +00:00
|
|
|
return false;
|
2013-04-07 08:59:05 +00:00
|
|
|
}
|
2013-07-26 17:19:06 +00:00
|
|
|
return true;
|
2013-04-07 08:59:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2013-07-26 17:19:06 +00:00
|
|
|
return DSOUND_InitCard_Internal(sc, sc->name);
|
|
|
|
}
|
|
|
|
|
2016-07-12 00:40:13 +00:00
|
|
|
#define SDRVNAME "DSound"
|
2013-07-26 17:19:06 +00:00
|
|
|
static BOOL (CALLBACK DSound_EnumCallback)(GUID FAR *guid, LPCSTR str1, LPCSTR str2, LPVOID parm)
|
|
|
|
{
|
|
|
|
char guidbuf[128];
|
|
|
|
wchar_t mssuck[128];
|
|
|
|
void (QDECL *callback) (const char *drivername, const char *devicecode, const char *readablename) = parm;
|
|
|
|
if (guid == NULL) //we don't care about the (dupe) default device
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
StringFromGUID2(guid, mssuck, sizeof(mssuck)/sizeof(mssuck[0]));
|
|
|
|
wcstombs(guidbuf, mssuck, sizeof(guidbuf));
|
2016-07-12 00:40:13 +00:00
|
|
|
callback(SDRVNAME, guidbuf, va("DS: %s", str1));
|
2013-07-26 17:19:06 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
static qboolean QDECL DSOUND_Enumerate(void (QDECL *cb) (const char *drivername, const char *devicecode, const char *readablename))
|
|
|
|
{
|
|
|
|
if (!DSOUND_InitOutputLibrary())
|
|
|
|
return false;
|
|
|
|
if (pDirectSoundEnumerate)
|
|
|
|
{
|
|
|
|
pDirectSoundEnumerate(&DSound_EnumCallback, cb);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
2013-04-07 08:59:05 +00:00
|
|
|
|
2013-07-26 17:19:06 +00:00
|
|
|
sounddriver_t DSOUND_Output =
|
|
|
|
{
|
|
|
|
SDRVNAME,
|
|
|
|
DSOUND_InitCard,
|
|
|
|
DSOUND_Enumerate
|
|
|
|
};
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-04-30 17:21:10 +00:00
|
|
|
#if defined(VOICECHAT) && defined(AVAIL_DSOUND)
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
|
2010-11-20 22:01:16 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
LPDIRECTSOUNDCAPTURE DSCapture;
|
|
|
|
LPDIRECTSOUNDCAPTUREBUFFER DSCaptureBuffer;
|
|
|
|
long lastreadpos;
|
|
|
|
} dsndcapture_t;
|
2013-09-06 22:57:44 +00:00
|
|
|
static const long bufferbytes = 1024*1024;
|
2005-06-13 06:06:15 +00:00
|
|
|
|
2013-09-06 22:57:44 +00:00
|
|
|
static const long inputwidth = 2;
|
2005-06-13 06:06:15 +00:00
|
|
|
|
2013-09-06 22:57:44 +00:00
|
|
|
static BOOL CALLBACK dsound_capture_enumerate_ds(LPGUID lpGuid, LPCSTR lpcstrDescription, LPCSTR lpcstrModule, LPVOID lpContext)
|
|
|
|
{
|
|
|
|
char guidbuf[128];
|
|
|
|
wchar_t mssuck[128];
|
|
|
|
void (QDECL *callback) (const char *drivername, const char *devicecode, const char *readablename) = lpContext;
|
|
|
|
|
|
|
|
if (lpGuid == NULL) //we don't care about the (dupe) default device
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
StringFromGUID2(lpGuid, mssuck, sizeof(mssuck)/sizeof(mssuck[0]));
|
|
|
|
wcstombs(guidbuf, mssuck, sizeof(guidbuf));
|
|
|
|
callback(SDRVNAME, guidbuf, lpcstrDescription);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static qboolean QDECL DSOUND_Capture_Enumerate (void (QDECL *callback) (const char *drivername, const char *devicecode, const char *readablename))
|
|
|
|
{
|
|
|
|
if (!pDirectSoundCaptureEnumerate)
|
|
|
|
{
|
|
|
|
/*make sure its loaded*/
|
|
|
|
if (!hInstDS)
|
|
|
|
hInstDS = LoadLibrary("dsound.dll");
|
|
|
|
if (hInstDS)
|
|
|
|
pDirectSoundCaptureEnumerate = (void *)GetProcAddress(hInstDS,"DirectSoundCaptureEnumerateA");
|
|
|
|
|
|
|
|
if (!pDirectSoundCaptureEnumerate)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FAILED(pDirectSoundCaptureEnumerate(dsound_capture_enumerate_ds, callback)))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-26 02:50:24 +00:00
|
|
|
static void *QDECL DSOUND_Capture_Init (int rate, const char *device)
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
2010-11-20 22:01:16 +00:00
|
|
|
dsndcapture_t *result;
|
2005-06-13 06:06:15 +00:00
|
|
|
DSCBUFFERDESC bufdesc;
|
|
|
|
|
2010-11-20 22:01:16 +00:00
|
|
|
WAVEFORMATEX wfxFormat;
|
2013-09-06 22:57:44 +00:00
|
|
|
GUID *dsguid, guid;
|
2010-11-20 22:01:16 +00:00
|
|
|
|
2005-06-13 06:06:15 +00:00
|
|
|
wfxFormat.wFormatTag = WAVE_FORMAT_PCM;
|
|
|
|
wfxFormat.nChannels = 1;
|
2010-11-20 22:01:16 +00:00
|
|
|
wfxFormat.nSamplesPerSec = rate;
|
2005-06-13 06:06:15 +00:00
|
|
|
wfxFormat.wBitsPerSample = 8*inputwidth;
|
|
|
|
wfxFormat.nBlockAlign = wfxFormat.nChannels * (wfxFormat.wBitsPerSample / 8);
|
|
|
|
wfxFormat.nAvgBytesPerSec = wfxFormat.nSamplesPerSec * wfxFormat.nBlockAlign;
|
|
|
|
wfxFormat.cbSize = 0;
|
|
|
|
|
|
|
|
bufdesc.dwSize = sizeof(bufdesc);
|
|
|
|
bufdesc.dwBufferBytes = bufferbytes;
|
|
|
|
bufdesc.dwFlags = 0;
|
|
|
|
bufdesc.dwReserved = 0;
|
|
|
|
bufdesc.lpwfxFormat = &wfxFormat;
|
|
|
|
|
2013-09-06 22:57:44 +00:00
|
|
|
if (device && *device)
|
|
|
|
{
|
|
|
|
wchar_t mssuck[128];
|
|
|
|
mbstowcs(mssuck, device, sizeof(mssuck)/sizeof(mssuck[0])-1);
|
|
|
|
CLSIDFromString(mssuck, &guid);
|
|
|
|
dsguid = &guid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memset(&guid, 0, sizeof(GUID));
|
|
|
|
dsguid = NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-20 22:01:16 +00:00
|
|
|
/*probably already inited*/
|
2005-06-13 06:06:15 +00:00
|
|
|
if (!hInstDS)
|
|
|
|
{
|
|
|
|
hInstDS = LoadLibrary("dsound.dll");
|
2010-11-11 13:01:23 +00:00
|
|
|
|
2005-06-13 06:06:15 +00:00
|
|
|
if (hInstDS == NULL)
|
|
|
|
{
|
|
|
|
Con_SafePrintf ("Couldn't load dsound.dll\n");
|
2010-11-20 22:01:16 +00:00
|
|
|
return NULL;
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-20 22:01:16 +00:00
|
|
|
/*global pointer, used only in this function*/
|
2005-06-13 06:06:15 +00:00
|
|
|
if (!pDirectSoundCaptureCreate)
|
|
|
|
{
|
|
|
|
pDirectSoundCaptureCreate = (void *)GetProcAddress(hInstDS,"DirectSoundCaptureCreate");
|
|
|
|
|
2006-09-18 22:51:33 +00:00
|
|
|
if (!pDirectSoundCaptureCreate)
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
|
|
|
Con_SafePrintf ("Couldn't get DS proc addr\n");
|
2010-11-20 22:01:16 +00:00
|
|
|
return NULL;
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-20 22:01:16 +00:00
|
|
|
result = Z_Malloc(sizeof(*result));
|
2013-09-06 22:57:44 +00:00
|
|
|
if (!FAILED(pDirectSoundCaptureCreate(dsguid, &result->DSCapture, NULL)))
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
2010-11-20 22:01:16 +00:00
|
|
|
if (!FAILED(IDirectSoundCapture_CreateCaptureBuffer(result->DSCapture, &bufdesc, &result->DSCaptureBuffer, NULL)))
|
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
IDirectSoundCapture_Release(result->DSCapture);
|
2005-06-13 06:06:15 +00:00
|
|
|
Con_SafePrintf ("Couldn't create a capture buffer\n");
|
|
|
|
}
|
2010-11-20 22:01:16 +00:00
|
|
|
Z_Free(result);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-09-06 22:57:44 +00:00
|
|
|
static void QDECL DSOUND_Capture_Start(void *ctx)
|
2010-11-20 22:01:16 +00:00
|
|
|
{
|
|
|
|
DWORD capturePos;
|
|
|
|
dsndcapture_t *c = ctx;
|
|
|
|
IDirectSoundCaptureBuffer_Start(c->DSCaptureBuffer, DSBPLAY_LOOPING);
|
|
|
|
|
|
|
|
c->lastreadpos = 0;
|
|
|
|
IDirectSoundCaptureBuffer_GetCurrentPosition(c->DSCaptureBuffer, &capturePos, &c->lastreadpos);
|
|
|
|
}
|
2005-06-13 06:06:15 +00:00
|
|
|
|
2013-09-06 22:57:44 +00:00
|
|
|
static void QDECL DSOUND_Capture_Stop(void *ctx)
|
2010-11-20 22:01:16 +00:00
|
|
|
{
|
|
|
|
dsndcapture_t *c = ctx;
|
|
|
|
IDirectSoundCaptureBuffer_Stop(c->DSCaptureBuffer);
|
|
|
|
}
|
2005-06-13 06:06:15 +00:00
|
|
|
|
2013-09-06 22:57:44 +00:00
|
|
|
static void QDECL DSOUND_Capture_Shutdown(void *ctx)
|
2010-11-20 22:01:16 +00:00
|
|
|
{
|
|
|
|
dsndcapture_t *c = ctx;
|
|
|
|
if (c->DSCaptureBuffer)
|
|
|
|
{
|
|
|
|
IDirectSoundCaptureBuffer_Stop(c->DSCaptureBuffer);
|
|
|
|
IDirectSoundCaptureBuffer_Release(c->DSCaptureBuffer);
|
|
|
|
}
|
|
|
|
if (c->DSCapture)
|
|
|
|
{
|
|
|
|
IDirectSoundCapture_Release(c->DSCapture);
|
|
|
|
}
|
|
|
|
Z_Free(ctx);
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
|
2010-11-15 02:40:31 +00:00
|
|
|
/*minsamples is a hint*/
|
2013-09-06 22:57:44 +00:00
|
|
|
static unsigned int QDECL DSOUND_Capture_Update(void *ctx, unsigned char *buffer, unsigned int minbytes, unsigned int maxbytes)
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
2010-11-20 22:01:16 +00:00
|
|
|
dsndcapture_t *c = ctx;
|
2005-06-13 06:06:15 +00:00
|
|
|
HRESULT hr;
|
|
|
|
LPBYTE lpbuf1 = NULL;
|
|
|
|
LPBYTE lpbuf2 = NULL;
|
|
|
|
DWORD dwsize1 = 0;
|
|
|
|
DWORD dwsize2 = 0;
|
|
|
|
|
|
|
|
DWORD capturePos;
|
|
|
|
DWORD readPos;
|
|
|
|
long filled;
|
|
|
|
|
|
|
|
// Query to see how much data is in buffer.
|
2010-11-20 22:01:16 +00:00
|
|
|
hr = IDirectSoundCaptureBuffer_GetCurrentPosition(c->DSCaptureBuffer, &capturePos, &readPos);
|
|
|
|
if (hr != DS_OK)
|
2005-06-13 06:06:15 +00:00
|
|
|
{
|
2010-11-15 02:40:31 +00:00
|
|
|
return 0;
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
2010-11-20 22:01:16 +00:00
|
|
|
filled = readPos - c->lastreadpos;
|
|
|
|
if (filled < 0)
|
|
|
|
filled += bufferbytes; // unwrap offset
|
2005-06-13 06:06:15 +00:00
|
|
|
|
2010-11-15 02:40:31 +00:00
|
|
|
if (filled > maxbytes) //figure out how much we need to empty it by, and if that's enough to be worthwhile.
|
|
|
|
filled = maxbytes;
|
|
|
|
else if (filled < minbytes)
|
|
|
|
return 0;
|
2005-06-13 06:06:15 +00:00
|
|
|
|
2010-11-15 02:40:31 +00:00
|
|
|
// filled /= inputwidth;
|
|
|
|
// filled *= inputwidth;
|
2005-06-13 06:06:15 +00:00
|
|
|
|
|
|
|
// Lock free space in the DS
|
2010-11-20 22:01:16 +00:00
|
|
|
hr = IDirectSoundCaptureBuffer_Lock(c->DSCaptureBuffer, c->lastreadpos, filled, (void **) &lpbuf1, &dwsize1, (void **) &lpbuf2, &dwsize2, 0);
|
2005-06-13 06:06:15 +00:00
|
|
|
if (hr == DS_OK)
|
|
|
|
{
|
|
|
|
// Copy from DS to the buffer
|
2010-11-15 02:40:31 +00:00
|
|
|
memcpy(buffer, lpbuf1, dwsize1);
|
2005-06-13 06:06:15 +00:00
|
|
|
if(lpbuf2 != NULL)
|
|
|
|
{
|
2010-11-15 02:40:31 +00:00
|
|
|
memcpy(buffer+dwsize1, lpbuf2, dwsize2);
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
// Update our buffer offset and unlock sound buffer
|
2010-11-20 22:01:16 +00:00
|
|
|
c->lastreadpos = (c->lastreadpos + dwsize1 + dwsize2) % bufferbytes;
|
|
|
|
IDirectSoundCaptureBuffer_Unlock(c->DSCaptureBuffer, lpbuf1, dwsize1, lpbuf2, dwsize2);
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-15 02:40:31 +00:00
|
|
|
return 0;
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
2010-11-15 02:40:31 +00:00
|
|
|
return filled;
|
2005-06-13 06:06:15 +00:00
|
|
|
}
|
2010-11-20 22:01:16 +00:00
|
|
|
snd_capture_driver_t DSOUND_Capture =
|
|
|
|
{
|
2013-09-06 22:57:44 +00:00
|
|
|
1,
|
|
|
|
SDRVNAME,
|
|
|
|
DSOUND_Capture_Enumerate,
|
2010-11-20 22:01:16 +00:00
|
|
|
DSOUND_Capture_Init,
|
|
|
|
DSOUND_Capture_Start,
|
|
|
|
DSOUND_Capture_Update,
|
|
|
|
DSOUND_Capture_Stop,
|
|
|
|
DSOUND_Capture_Shutdown
|
|
|
|
};
|
2005-06-13 06:06:15 +00:00
|
|
|
#endif
|