Skip to content

Commit 7ecbf95

Browse files
committed
pending: sound updates
* increase max channels to 256 to prevent us from hitting the cap in team fights * make more room for static channels over dynamic channels * dsound updates: * use DSBCAPS_TRUEPLAYPOSITION for accurate GetCurrentPosition * Pass NULL to GetCurrentPosition for write cursor, to skip querying it * limit dsound max distance, we only use it for local speaker spatialization * implement threaded sound a dedicated thread to doing all sound updates it gets notified when the main thread wants a sound update, and wakes up from sleep * backport 64 bit sound changes from CSGO * enable spatialization effects by default
1 parent b3275c9 commit 7ecbf95

File tree

7 files changed

+341
-77
lines changed

7 files changed

+341
-77
lines changed

src/engine/audio/private/snd_channels.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ struct channel_t
126126
//-----------------------------------------------------------------------------
127127
//-----------------------------------------------------------------------------
128128

129-
#define MAX_CHANNELS 128
130-
#define MAX_DYNAMIC_CHANNELS 64
129+
#define MAX_CHANNELS 256
130+
#define MAX_DYNAMIC_CHANNELS 32
131131

132132
//-----------------------------------------------------------------------------
133133
//-----------------------------------------------------------------------------

src/engine/audio/private/snd_dev_direct.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ int CAudioDirectSound::PaintBegin( float mixAheadTime, int soundtime, int lpaint
370370
DWORD dwStatus;
371371

372372
// If using surround, there are 4 or 5 different buffers being used and the pDSBuf is NULL.
373-
if ( IsUsingBufferPerSpeaker() )
373+
if ( IsUsingBufferPerSpeaker() )
374374
{
375375
if (pDSBufFL->GetStatus(&dwStatus) != DS_OK)
376376
Msg ("Couldn't get SURROUND FL sound buffer status\n");
@@ -674,6 +674,7 @@ bool CAudioDirectSound::SNDDMA_InitInterleaved( LPDIRECTSOUND lpDS, WAVEFORMATEX
674674
dsbdesc.dwFlags = 0;
675675
break;
676676
}
677+
dsbdesc.dwFlags |= DSBCAPS_TRUEPLAYPOSITION;
677678
if ( !snd_mute_losefocus.GetBool() )
678679
{
679680
dsbdesc.dwFlags |= DSBCAPS_GLOBALFOCUS;
@@ -688,7 +689,7 @@ bool CAudioDirectSound::SNDDMA_InitInterleaved( LPDIRECTSOUND lpDS, WAVEFORMATEX
688689
if ( !bSuccess )
689690
return false;
690691

691-
DWORD dwSize = 0, dwWrite;
692+
DWORD dwSize = 0;
692693
DWORD *pBuffer = 0;
693694
if ( !LockDSBuffer( pDSBuf, &pBuffer, &dwSize, "DS_INTERLEAVED", DSBLOCK_ENTIREBUFFER ) )
694695
return false;
@@ -707,7 +708,7 @@ bool CAudioDirectSound::SNDDMA_InitInterleaved( LPDIRECTSOUND lpDS, WAVEFORMATEX
707708
pDSBuf->Play(0, 0, DSBPLAY_LOOPING);
708709

709710
pDSBuf->Stop();
710-
pDSBuf->GetCurrentPosition(&m_outputBufferStartOffset, &dwWrite);
711+
pDSBuf->GetCurrentPosition(&m_outputBufferStartOffset, NULL);
711712

712713
pDSBuf->Play(0, 0, DSBPLAY_LOOPING);
713714

@@ -725,7 +726,7 @@ sndinitstat CAudioDirectSound::SNDDMA_InitDirect( void )
725726
{
726727
DSBUFFERDESC dsbuf;
727728
DSBCAPS dsbcaps;
728-
DWORD dwSize, dwWrite;
729+
DWORD dwSize;
729730
WAVEFORMATEX format;
730731
WAVEFORMATEX pformat;
731732
HRESULT hresult;
@@ -830,7 +831,7 @@ sndinitstat CAudioDirectSound::SNDDMA_InitDirect( void )
830831
// sound hardware format
831832
Q_memset( &dsbuf, 0, sizeof(dsbuf) );
832833
dsbuf.dwSize = sizeof(DSBUFFERDESC);
833-
dsbuf.dwFlags = DSBCAPS_PRIMARYBUFFER;
834+
dsbuf.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_TRUEPLAYPOSITION;
834835
if ( snd_legacy_surround.GetBool() || m_bSurround )
835836
{
836837
dsbuf.dwFlags |= DSBCAPS_CTRL3D;
@@ -900,7 +901,8 @@ sndinitstat CAudioDirectSound::SNDDMA_InitDirect( void )
900901
// create the secondary buffer we'll actually work with
901902
Q_memset( &dsbuf, 0, sizeof(dsbuf) );
902903
dsbuf.dwSize = sizeof(DSBUFFERDESC);
903-
dsbuf.dwFlags = DSBCAPS_LOCSOFTWARE; // NOTE: don't use CTRLFREQUENCY (slow)
904+
// NOTE: don't use CTRLFREQUENCY (slow)
905+
dsbuf.dwFlags = DSBCAPS_LOCSOFTWARE | DSBCAPS_TRUEPLAYPOSITION;
904906
dsbuf.dwBufferBytes = SECONDARY_BUFFER_SIZE;
905907
dsbuf.lpwfxFormat = &format;
906908
if ( !snd_mute_losefocus.GetBool() )
@@ -992,7 +994,7 @@ sndinitstat CAudioDirectSound::SNDDMA_InitDirect( void )
992994

993995
pDSBuf->Stop();
994996

995-
pDSBuf->GetCurrentPosition(&m_outputBufferStartOffset, &dwWrite);
997+
pDSBuf->GetCurrentPosition(&m_outputBufferStartOffset, NULL);
996998

997999
pDSBuf->Play(0, 0, DSBPLAY_LOOPING);
9981000
}
@@ -1288,7 +1290,7 @@ void DS3D_SetBufferParams( LPDIRECTSOUND3DBUFFER pDSBuf3D, D3DVECTOR *pbpos, D3D
12881290
bparm.vConeOrientation = bdir;
12891291
bparm.lConeOutsideVolume = DSBVOLUME_MIN;
12901292
bparm.flMinDistance = 100.0; // no rolloff (until > 2.0 meter distance)
1291-
bparm.flMaxDistance = DS3D_DEFAULTMAXDISTANCE;
1293+
bparm.flMaxDistance = 1000.0;
12921294
bparm.dwMode = DS3DMODE_NORMAL;
12931295

12941296
hr = pDSBuf3D->SetAllParameters( &bparm, DS3D_DEFERRED );
@@ -1300,7 +1302,7 @@ bool CAudioDirectSound::SNDDMA_InitSurround(LPDIRECTSOUND lpDS, WAVEFORMATEX* lp
13001302
{
13011303
DSBUFFERDESC dsbuf;
13021304
WAVEFORMATEX wvex;
1303-
DWORD dwSize, dwWrite;
1305+
DWORD dwSize;
13041306
int reps;
13051307
HRESULT hresult;
13061308
void *lpData = NULL;
@@ -1316,8 +1318,9 @@ bool CAudioDirectSound::SNDDMA_InitSurround(LPDIRECTSOUND lpDS, WAVEFORMATEX* lp
13161318

13171319
memset (&dsbuf, 0, sizeof(dsbuf));
13181320
dsbuf.dwSize = sizeof(DSBUFFERDESC);
1319-
// NOTE: LOCHARDWARE causes SB AWE64 to crash in it's DSOUND driver
1320-
dsbuf.dwFlags = DSBCAPS_CTRL3D; // don't use CTRLFREQUENCY (slow)
1321+
// NOTE: LOCHARDWARE causes SB AWE64 to crash in it's DSOUND driver
1322+
// don't use CTRLFREQUENCY (slow)
1323+
dsbuf.dwFlags = DSBCAPS_CTRL3D | DSBCAPS_TRUEPLAYPOSITION;
13211324
if ( !snd_mute_losefocus.GetBool() )
13221325
{
13231326
dsbuf.dwFlags |= DSBCAPS_GLOBALFOCUS;
@@ -1623,7 +1626,7 @@ bool CAudioDirectSound::SNDDMA_InitSurround(LPDIRECTSOUND lpDS, WAVEFORMATEX* lp
16231626

16241627
// get hardware playback position, store it, syncronize all buffers to FL
16251628

1626-
pDSBufFL->GetCurrentPosition(&m_outputBufferStartOffset, &dwWrite);
1629+
pDSBufFL->GetCurrentPosition(&m_outputBufferStartOffset, NULL);
16271630
pDSBufFR->SetCurrentPosition(m_outputBufferStartOffset);
16281631
pDSBufRL->SetCurrentPosition(m_outputBufferStartOffset);
16291632
pDSBufRR->SetCurrentPosition(m_outputBufferStartOffset);

0 commit comments

Comments
 (0)