Skip to content

Commit

Permalink
[engine] Make XAudio2 default audio engine on Windows
Browse files Browse the repository at this point in the history
DirectSound8 is obsolete and preserved for backward compatibility.
  • Loading branch information
dimhotepus committed Dec 7, 2024
1 parent 454133f commit b388518
Show file tree
Hide file tree
Showing 14 changed files with 1,598 additions and 1,222 deletions.
591 changes: 316 additions & 275 deletions engine/audio/private/snd_dev_direct.cpp

Large diffs are not rendered by default.

1,814 changes: 1,028 additions & 786 deletions engine/audio/private/snd_dev_xaudio.cpp

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion engine/audio/private/snd_dev_xaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class CXboxVoice
};

CXboxVoice *Audio_GetXVoice( void );
IXAudio2 *Audio_GetXAudio2( void );

#endif

Expand Down
53 changes: 27 additions & 26 deletions engine/audio/private/snd_dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "vaudio/ivaudio.h"
#include "../../client.h"
#include "../../cl_main.h"
#include "utldict.h"
#include "tier1/utldict.h"
#include "mempool.h"
#include "../../enginetrace.h" // for traceline
#include "../../public/bspflags.h" // for traceline
Expand All @@ -37,25 +37,13 @@
#include "../../pure_server.h"
#include "filesystem/IQueuedLoader.h"
#include "voice.h"
#if defined( _X360 )
#include "xbox/xbox_console.h"
#include "xmp.h"
#endif

#include "replay/iclientreplaycontext.h"
#include "replay/ireplaymovierenderer.h"

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

/*
#include "gl_model_private.h"
#include "world.h"
#include "vphysics_interface.h"
#include "client_class.h"
#include "server_class.h"
*/

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

Expand All @@ -66,8 +54,23 @@ extern IVideoServices *g_pVideo;
//
//#define DEBUG_CHANNELS

#define SNDLVL_TO_DIST_MULT( sndlvl ) ( sndlvl ? ((powf( 10.0f, snd_refdb.GetFloat() / 20 ) / powf( 10.0f, (float)sndlvl / 20 )) / snd_refdist.GetFloat()) : 0 )
#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 )
extern ConVar snd_refdb;
extern ConVar snd_refdist;

inline float SNDLVL_TO_DIST_MULT( soundlevel_t sndlvl )
{
return sndlvl != SNDLVL_NONE
? powf( 10.0f, ( snd_refdb.GetFloat() - static_cast<float>( sndlvl ) ) / 20 ) / snd_refdist.GetFloat()
: 0;
}

inline soundlevel_t DIST_MULT_TO_SNDLVL( float dist_mult )
{
// dimhotepus: Rewrite and simplify to match SNDLVL_TO_DIST_MULT.
return (soundlevel_t)(int)( dist_mult
? snd_refdb.GetFloat() - log10f( dist_mult * snd_refdist.GetFloat() ) * 20
: 0 );
}

extern ConVar dsp_spatial;
extern IPhysicsSurfaceProps *physprop;
Expand Down Expand Up @@ -447,7 +450,7 @@ typedef struct

static soundfade_t soundfade; // Client sound fading singleton object

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

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

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

CUtlVector< CSfxTable * > processed;

int iLast = s_Sounds.LastInorder();
for ( int i = s_Sounds.FirstInorder(); i != iLast; i = s_Sounds.NextInorder( i ) )
auto iLast = s_Sounds.LastInorder();
for ( auto i = s_Sounds.FirstInorder(); i != iLast; i = s_Sounds.NextInorder( i ) )
{
FileNameHandle_t fnHandle = s_Sounds.Key( i );
char filename[MAX_PATH * 3];
Expand Down Expand Up @@ -1812,15 +1815,13 @@ void SND_GetDopplerPoints( channel_t *pChannel, QAngle &source_angles, Vector &v

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

pChannel->basePitch = (int)(pitch * 100.0);
pChannel->basePitch = (int)(pitch * 100.0f);
}

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

extern ConVar snd_foliage_db_loss;
extern ConVar snd_gain;
extern ConVar snd_refdb;
extern ConVar snd_refdist;
extern ConVar snd_gain_max;
extern ConVar snd_gain_min;

Expand Down Expand Up @@ -6411,7 +6412,7 @@ void S_Update_Thread()
float frameTime = THREADED_MIX_TIME * 0.001f;
double lastFrameTime = Plat_FloatTime();

while ( !g_bMixThreadExit )
while ( !g_bMixThreadExit.load(std::memory_order::memory_order_relaxed) )
{
double t0 = Plat_FloatTime();

Expand Down Expand Up @@ -6441,7 +6442,7 @@ void S_ShutdownMixThread()
{
if ( g_hMixThread )
{
g_bMixThreadExit = true;
g_bMixThreadExit.store(true, std::memory_order::memory_order_relaxed);
ThreadJoin( g_hMixThread );
ReleaseThreadHandle( g_hMixThread );
g_hMixThread = NULL;
Expand All @@ -6460,7 +6461,7 @@ void S_Update_( float mixAheadTime )
{
if ( !g_hMixThread )
{
g_bMixThreadExit = false;
g_bMixThreadExit.store(false, std::memory_order::memory_order_relaxed);
g_hMixThread = ThreadExecuteSolo( "SoundMixer", S_Update_Thread );
}
}
Expand Down
4 changes: 2 additions & 2 deletions engine/audio/private/snd_wave_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ extern double realtime;
#define TF_XBOX_WAV_MEMORY_CACHE ( 24 * 1024 * 1024 ) // Team Fortress uses a larger cache

// 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.
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" );
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)" );
ConVar snd_async_spew( "snd_async_spew", "0", 0, "Spew all async sound reads, including success" );
ConVar snd_async_fullyasync( "snd_async_fullyasync", "0", 0, "All playback is fully async (sound doesn't play until data arrives)." );
ConVar snd_async_stream_spew( "snd_async_stream_spew", "0", 0, "Spew streaming info ( 0=Off, 1=streams, 2=buffers" );
ConVar snd_async_stream_spew( "snd_async_stream_spew", "0", 0, "Spew streaming info (0=Off, 1=streams, 2=buffers)" );

static bool SndAsyncSpewBlocking()
{
Expand Down
Loading

0 comments on commit b388518

Please sign in to comment.