From 4e26e1ac6f20bd515d5f5d517c98877dc0160679 Mon Sep 17 00:00:00 2001 From: dhewg Date: Wed, 14 Dec 2011 16:48:20 +0100 Subject: [PATCH] Don't use idAudioHardware to get the speaker count Use the CVar s_numberOfSpeakers for that, its already stored in there. Add the same (!= 2 && !=6) check as in the audio backends since the mixer is limited to these 2 values. --- neo/sound/snd_system.cpp | 21 +++++++++++++++------ neo/sound/snd_world.cpp | 10 +++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/neo/sound/snd_system.cpp b/neo/sound/snd_system.cpp index a4fd7f55..a36753e7 100644 --- a/neo/sound/snd_system.cpp +++ b/neo/sound/snd_system.cpp @@ -476,6 +476,13 @@ idSoundSystemLocal::InitHW =============== */ bool idSoundSystemLocal::InitHW() { + int numSpeakers = s_numberOfSpeakers.GetInteger(); + + if (numSpeakers != 2 && numSpeakers != 6) { + common->Warning("invalid value for s_numberOfSpeakers. Use either 2 or 6"); + numSpeakers = 2; + s_numberOfSpeakers.SetInteger(numSpeakers); + } if ( s_noSound.GetBool() ) { return false; @@ -498,10 +505,12 @@ bool idSoundSystemLocal::InitHW() { if ( snd_audio_hw->GetNumberOfSpeakers() == 0 ) { return false; } - // put the real number in there - s_numberOfSpeakers.SetInteger( snd_audio_hw->GetNumberOfSpeakers() ); + numSpeakers = snd_audio_hw->GetNumberOfSpeakers(); } + // put the real number in there + s_numberOfSpeakers.SetInteger(numSpeakers); + isInitialized = true; shutdown = false; @@ -590,7 +599,7 @@ int idSoundSystemLocal::AsyncMix( int soundTime, float *mixBuffer ) { } inTime = Sys_Milliseconds(); - numSpeakers = snd_audio_hw->GetNumberOfSpeakers(); + numSpeakers = s_numberOfSpeakers.GetInteger(); // let the active sound world mix all the channels in unless muted or avi demo recording if ( !muted && currentSoundWorld && !currentSoundWorld->fpa[0] ) { @@ -654,7 +663,7 @@ int idSoundSystemLocal::AsyncUpdate( int inTime ) { soundStats.runs++; soundStats.activeSounds = 0; - int numSpeakers = snd_audio_hw->GetNumberOfSpeakers(); + int numSpeakers = s_numberOfSpeakers.GetInteger(); nextWriteBlock++; nextWriteBlock %= ROOM_SLICES_IN_BUFFER; @@ -755,7 +764,7 @@ int idSoundSystemLocal::AsyncUpdateWrite( int inTime ) { } int sampleTime = dwCurrentBlock * MIXBUFFER_SAMPLES; - int numSpeakers = snd_audio_hw->GetNumberOfSpeakers(); + int numSpeakers = s_numberOfSpeakers.GetInteger(); if ( useOpenAL ) { // enable audio hardware caching @@ -837,7 +846,7 @@ cinData_t idSoundSystemLocal::ImageForTime( const int milliseconds, const bool w float *accum = finalMixBuffer; // unfortunately, these are already clamped int time = Sys_Milliseconds(); - int numSpeakers = snd_audio_hw->GetNumberOfSpeakers(); + int numSpeakers = s_numberOfSpeakers.GetInteger(); if ( !waveform ) { for( j = 0; j < numSpeakers; j++ ) { diff --git a/neo/sound/snd_world.cpp b/neo/sound/snd_world.cpp index 66f50d2c..d56a6e64 100644 --- a/neo/sound/snd_world.cpp +++ b/neo/sound/snd_world.cpp @@ -550,7 +550,7 @@ void idSoundWorldLocal::AVIOpen( const char *path, const char *name ) { lastAVI44kHz = game44kHz - game44kHz % MIXBUFFER_SAMPLES; - if ( soundSystemLocal.snd_audio_hw->GetNumberOfSpeakers() == 6 ) { + if ( idSoundSystemLocal::s_numberOfSpeakers.GetInteger() == 6 ) { fpa[0] = fileSystem->OpenFileWrite( aviDemoPath + "channel_51_left.raw" ); fpa[1] = fileSystem->OpenFileWrite( aviDemoPath + "channel_51_right.raw" ); fpa[2] = fileSystem->OpenFileWrite( aviDemoPath + "channel_51_center.raw" ); @@ -581,11 +581,7 @@ void idSoundWorldLocal::AVIUpdate() { return; } - if ( !soundSystemLocal.snd_audio_hw ) { - numSpeakers = 2; - } else { - numSpeakers = soundSystemLocal.snd_audio_hw->GetNumberOfSpeakers(); - } + numSpeakers = idSoundSystemLocal::s_numberOfSpeakers.GetInteger(); float mix[MIXBUFFER_SAMPLES*6+16]; float *mix_p = (float *)((( intptr_t)mix + 15 ) & ~15); // SIMD align @@ -639,7 +635,7 @@ void idSoundWorldLocal::AVIClose( void ) { fpa[i] = NULL; } } - if ( soundSystemLocal.snd_audio_hw->GetNumberOfSpeakers() == 2 ) { + if ( idSoundSystemLocal::s_numberOfSpeakers.GetInteger() == 2 ) { // convert it to a wave file idFile *rL, *lL, *wO; idStr name;