Skip to content

Commit b388518

Browse files
committed
[engine] Make XAudio2 default audio engine on Windows
DirectSound8 is obsolete and preserved for backward compatibility.
1 parent 454133f commit b388518

File tree

14 files changed

+1598
-1222
lines changed

14 files changed

+1598
-1222
lines changed

engine/audio/private/snd_dev_direct.cpp

Lines changed: 316 additions & 275 deletions
Large diffs are not rendered by default.

engine/audio/private/snd_dev_xaudio.cpp

Lines changed: 1028 additions & 786 deletions
Large diffs are not rendered by default.

engine/audio/private/snd_dev_xaudio.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class CXboxVoice
5555
};
5656

5757
CXboxVoice *Audio_GetXVoice( void );
58-
IXAudio2 *Audio_GetXAudio2( void );
5958

6059
#endif
6160

engine/audio/private/snd_dma.cpp

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "vaudio/ivaudio.h"
2222
#include "../../client.h"
2323
#include "../../cl_main.h"
24-
#include "utldict.h"
24+
#include "tier1/utldict.h"
2525
#include "mempool.h"
2626
#include "../../enginetrace.h" // for traceline
2727
#include "../../public/bspflags.h" // for traceline
@@ -37,25 +37,13 @@
3737
#include "../../pure_server.h"
3838
#include "filesystem/IQueuedLoader.h"
3939
#include "voice.h"
40-
#if defined( _X360 )
41-
#include "xbox/xbox_console.h"
42-
#include "xmp.h"
43-
#endif
4440

4541
#include "replay/iclientreplaycontext.h"
4642
#include "replay/ireplaymovierenderer.h"
4743

4844
#include "video/ivideoservices.h"
4945
extern IVideoServices *g_pVideo;
5046

51-
/*
52-
#include "gl_model_private.h"
53-
#include "world.h"
54-
#include "vphysics_interface.h"
55-
#include "client_class.h"
56-
#include "server_class.h"
57-
*/
58-
5947
// memdbgon must be the last include file in a .cpp file!!!
6048
#include "tier0/memdbgon.h"
6149

@@ -66,8 +54,23 @@ extern IVideoServices *g_pVideo;
6654
//
6755
//#define DEBUG_CHANNELS
6856

69-
#define SNDLVL_TO_DIST_MULT( sndlvl ) ( sndlvl ? ((powf( 10.0f, snd_refdb.GetFloat() / 20 ) / powf( 10.0f, (float)sndlvl / 20 )) / snd_refdist.GetFloat()) : 0 )
70-
#define DIST_MULT_TO_SNDLVL( dist_mult ) (soundlevel_t)(int)( (dist_mult) ? ( 20 * log10f( powf( 10.0f, snd_refdb.GetFloat() / 20 ) / ((dist_mult) * snd_refdist.GetFloat()) ) ) : 0 )
57+
extern ConVar snd_refdb;
58+
extern ConVar snd_refdist;
59+
60+
inline float SNDLVL_TO_DIST_MULT( soundlevel_t sndlvl )
61+
{
62+
return sndlvl != SNDLVL_NONE
63+
? powf( 10.0f, ( snd_refdb.GetFloat() - static_cast<float>( sndlvl ) ) / 20 ) / snd_refdist.GetFloat()
64+
: 0;
65+
}
66+
67+
inline soundlevel_t DIST_MULT_TO_SNDLVL( float dist_mult )
68+
{
69+
// dimhotepus: Rewrite and simplify to match SNDLVL_TO_DIST_MULT.
70+
return (soundlevel_t)(int)( dist_mult
71+
? snd_refdb.GetFloat() - log10f( dist_mult * snd_refdist.GetFloat() ) * 20
72+
: 0 );
73+
}
7174

7275
extern ConVar dsp_spatial;
7376
extern IPhysicsSurfaceProps *physprop;
@@ -447,7 +450,7 @@ typedef struct
447450

448451
static soundfade_t soundfade; // Client sound fading singleton object
449452

450-
// 0)headphones 2)stereo speakers 4)quad 5)5point1
453+
// 0)headphones 2)stereo speakers 4)quad 5)5point1 7)7point1
451454
// autodetected from windows settings
452455
ConVar snd_surround( "snd_surround_speakers", "-1", FCVAR_INTERNAL_USE );
453456
ConVar snd_legacy_surround( "snd_legacy_surround", "0", FCVAR_ARCHIVE );
@@ -497,7 +500,7 @@ class CResourcePreloadSound : public CResourcePreload
497500
{
498501
bool bSpew = ( g_pQueuedLoader->GetSpewDetail() & LOADER_DETAIL_PURGES ) != 0;
499502

500-
for ( int i = s_Sounds.FirstInorder(); i != s_Sounds.InvalidIndex(); i = s_Sounds.NextInorder( i ) )
503+
for ( auto i = s_Sounds.FirstInorder(); i != s_Sounds.InvalidIndex(); i = s_Sounds.NextInorder( i ) )
501504
{
502505
// the master sound table grows forever
503506
// remove sound sources from the master sound table that were not in the preload list
@@ -538,7 +541,7 @@ class CResourcePreloadSound : public CResourcePreload
538541
{
539542
bool bSpew = ( g_pQueuedLoader->GetSpewDetail() & LOADER_DETAIL_PURGES ) != 0;
540543

541-
for ( int i = s_Sounds.FirstInorder(); i != s_Sounds.InvalidIndex(); i = s_Sounds.NextInorder( i ) )
544+
for ( auto i = s_Sounds.FirstInorder(); i != s_Sounds.InvalidIndex(); i = s_Sounds.NextInorder( i ) )
542545
{
543546
// the master sound table grows forever
544547
// remove sound sources from the master sound table that were not in the preload list
@@ -1010,8 +1013,8 @@ void S_ReloadFilesInList( IFileList *pFilesToReload )
10101013

10111014
CUtlVector< CSfxTable * > processed;
10121015

1013-
int iLast = s_Sounds.LastInorder();
1014-
for ( int i = s_Sounds.FirstInorder(); i != iLast; i = s_Sounds.NextInorder( i ) )
1016+
auto iLast = s_Sounds.LastInorder();
1017+
for ( auto i = s_Sounds.FirstInorder(); i != iLast; i = s_Sounds.NextInorder( i ) )
10151018
{
10161019
FileNameHandle_t fnHandle = s_Sounds.Key( i );
10171020
char filename[MAX_PATH * 3];
@@ -1812,15 +1815,13 @@ void SND_GetDopplerPoints( channel_t *pChannel, QAngle &source_angles, Vector &v
18121815

18131816
pitch = DOPPLER_PITCH_MAX - dist * (DOPPLER_PITCH_MAX - DOPPLER_PITCH_MIN);
18141817

1815-
pChannel->basePitch = (int)(pitch * 100.0);
1818+
pChannel->basePitch = (int)(pitch * 100.0f);
18161819
}
18171820

18181821
// console variables used to construct gain curve - don't change these!
18191822

18201823
extern ConVar snd_foliage_db_loss;
18211824
extern ConVar snd_gain;
1822-
extern ConVar snd_refdb;
1823-
extern ConVar snd_refdist;
18241825
extern ConVar snd_gain_max;
18251826
extern ConVar snd_gain_min;
18261827

@@ -6411,7 +6412,7 @@ void S_Update_Thread()
64116412
float frameTime = THREADED_MIX_TIME * 0.001f;
64126413
double lastFrameTime = Plat_FloatTime();
64136414

6414-
while ( !g_bMixThreadExit )
6415+
while ( !g_bMixThreadExit.load(std::memory_order::memory_order_relaxed) )
64156416
{
64166417
double t0 = Plat_FloatTime();
64176418

@@ -6441,7 +6442,7 @@ void S_ShutdownMixThread()
64416442
{
64426443
if ( g_hMixThread )
64436444
{
6444-
g_bMixThreadExit = true;
6445+
g_bMixThreadExit.store(true, std::memory_order::memory_order_relaxed);
64456446
ThreadJoin( g_hMixThread );
64466447
ReleaseThreadHandle( g_hMixThread );
64476448
g_hMixThread = NULL;
@@ -6460,7 +6461,7 @@ void S_Update_( float mixAheadTime )
64606461
{
64616462
if ( !g_hMixThread )
64626463
{
6463-
g_bMixThreadExit = false;
6464+
g_bMixThreadExit.store(false, std::memory_order::memory_order_relaxed);
64646465
g_hMixThread = ThreadExecuteSolo( "SoundMixer", S_Update_Thread );
64656466
}
64666467
}

engine/audio/private/snd_wave_data.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ extern double realtime;
4242
#define TF_XBOX_WAV_MEMORY_CACHE ( 24 * 1024 * 1024 ) // Team Fortress uses a larger cache
4343

4444
// Dev builds will be missing soundcaches and hitch sometimes, we only care if its being properly launched from steam where sound caches should be complete.
45-
ConVar snd_async_spew_blocking( "snd_async_spew_blocking", "1", 0, "Spew message to console any time async sound loading blocks on file i/o. ( 0=Off, 1=With -steam only, 2=Always" );
45+
ConVar snd_async_spew_blocking( "snd_async_spew_blocking", "1", 0, "Spew message to console any time async sound loading blocks on file I/O. (0=Off, 1=With -steam only, 2=Always)" );
4646
ConVar snd_async_spew( "snd_async_spew", "0", 0, "Spew all async sound reads, including success" );
4747
ConVar snd_async_fullyasync( "snd_async_fullyasync", "0", 0, "All playback is fully async (sound doesn't play until data arrives)." );
48-
ConVar snd_async_stream_spew( "snd_async_stream_spew", "0", 0, "Spew streaming info ( 0=Off, 1=streams, 2=buffers" );
48+
ConVar snd_async_stream_spew( "snd_async_stream_spew", "0", 0, "Spew streaming info (0=Off, 1=streams, 2=buffers)" );
4949

5050
static bool SndAsyncSpewBlocking()
5151
{

0 commit comments

Comments
 (0)