diff --git a/src/RageSound.cpp b/src/RageSound.cpp index 3836980000..9a22c74517 100644 --- a/src/RageSound.cpp +++ b/src/RageSound.cpp @@ -147,7 +147,7 @@ public: int SetPosition( int iFrame ) { return 1; } int Read( float *pBuf, int iFrames ) { return RageSoundReader::END_OF_FILE; } RageSoundReader *Copy() const { return new RageSoundReader_Silence; } - int GetSampleRate() const { return 44100; } // Hardcoded to 44100 + int GetSampleRate() const { return kFallbackSampleRate; } unsigned GetNumChannels() const { return 1; } int GetNextSourceFrame() const { return 0; } float GetStreamToSourceRatio() const { return 1.0f; } diff --git a/src/RageSound.h b/src/RageSound.h index 852d897d47..43e9fbbff4 100644 --- a/src/RageSound.h +++ b/src/RageSound.h @@ -9,6 +9,8 @@ #include +constexpr int kFallbackSampleRate = 44100; + class RageSoundReader; struct lua_State; diff --git a/src/RageSoundManager.cpp b/src/RageSoundManager.cpp index af373c5a6b..527ac8d2cd 100644 --- a/src/RageSoundManager.cpp +++ b/src/RageSoundManager.cpp @@ -133,7 +133,7 @@ float RageSoundManager::GetPlayLatency() const int RageSoundManager::GetDriverSampleRate() const { if( m_pDriver == nullptr ) - return 44100; // Fallback if no driver is loaded + return kFallbackSampleRate; return m_pDriver->GetSampleRate(); // Returns the *actual* operating rate of the loaded driver } diff --git a/src/arch/Sound/ALSA9Helpers.cpp b/src/arch/Sound/ALSA9Helpers.cpp index 9fc6fc7c1e..9f084e1860 100644 --- a/src/arch/Sound/ALSA9Helpers.cpp +++ b/src/arch/Sound/ALSA9Helpers.cpp @@ -1,4 +1,5 @@ #include "global.h" +#include "RageSound.h" #include "RageLog.h" #include "RageUtil.h" #include "ALSA9Helpers.h" @@ -229,7 +230,7 @@ RString Alsa9Buf::Init( int channels_, preferred_writeahead = iWriteahead; preferred_chunksize = iChunkSize; if( iSampleRate == 0 ) - samplerate = 44100; + samplerate = kFallbackSampleRate; else samplerate = iSampleRate; diff --git a/src/arch/Sound/DSoundHelpers.cpp b/src/arch/Sound/DSoundHelpers.cpp index 1152d3a40c..d8eb131f13 100644 --- a/src/arch/Sound/DSoundHelpers.cpp +++ b/src/arch/Sound/DSoundHelpers.cpp @@ -65,7 +65,7 @@ void DSound::SetPrimaryBufferMode() int preferredSampleRate = PREFSMAN->m_iSoundPreferredSampleRate; if (preferredSampleRate == 0) { - preferredSampleRate = 44100; // Default to 44100 Hz if preference is 0 + preferredSampleRate = kFallbackSampleRate; } waveformat.nSamplesPerSec = preferredSampleRate; waveformat.nBlockAlign = 4; @@ -202,7 +202,7 @@ RString DSoundBuf::Init( DSound &ds, DSoundBuf::hw hardware, bool bNeedCtrlFrequency = false; if( m_iSampleRate == DYNAMIC_SAMPLERATE ) // DYNAMIC_SAMPLERATE is usually 0 or some special value { - m_iSampleRate = 44100; // If dynamic, default to 44100 for now + m_iSampleRate = kFallbackSampleRate; bNeedCtrlFrequency = true; } diff --git a/src/arch/Sound/RageSoundDriver.h b/src/arch/Sound/RageSoundDriver.h index 22309b5948..75616341bc 100644 --- a/src/arch/Sound/RageSoundDriver.h +++ b/src/arch/Sound/RageSoundDriver.h @@ -6,13 +6,14 @@ #include "RageThreads.h" #include "RageTimer.h" #include "RageUtil_CircularBuffer.h" +#include "RageSound.h" #include class RageSoundBase; class RageTimer; class RageSoundMixBuffer; -static const int samples_per_block = 512; +static const int samples_per_block = 512; // This should probably be kSamplesPerBlock or similar if it's truly const and static class RageSoundDriver: public RageDriver { @@ -66,7 +67,7 @@ public: * hearing it. (This isn't necessarily the same as the buffer latency.) */ virtual float GetPlayLatency() const { return 0.0f; } - virtual int GetSampleRate() const { return 44100; } + virtual int GetSampleRate() const { return kFallbackSampleRate; } protected: /* Start the decoding. This should be called once the hardware is set up and diff --git a/src/arch/Sound/RageSoundDriver_DSound_Software.cpp b/src/arch/Sound/RageSoundDriver_DSound_Software.cpp index 01440276e9..58bc1bc009 100644 --- a/src/arch/Sound/RageSoundDriver_DSound_Software.cpp +++ b/src/arch/Sound/RageSoundDriver_DSound_Software.cpp @@ -97,7 +97,7 @@ RString RageSoundDriver_DSound_Software::Init() m_pPCM = new DSoundBuf; m_iSampleRate = PREFSMAN->m_iSoundPreferredSampleRate; if( m_iSampleRate == 0 ) - m_iSampleRate = 44100; + m_iSampleRate = kFallbackSampleRate; // This m_iSampleRate (driver's) is then passed as the iSampleRate parameter to DSoundBuf::Init() sError = m_pPCM->Init( ds, DSoundBuf::HW_DONT_CARE, channels, m_iSampleRate, 16, g_iMaxWriteahead ); if( sError != "" ) diff --git a/src/arch/Sound/RageSoundDriver_Null.cpp b/src/arch/Sound/RageSoundDriver_Null.cpp index f8a7124a58..067b1d9e85 100644 --- a/src/arch/Sound/RageSoundDriver_Null.cpp +++ b/src/arch/Sound/RageSoundDriver_Null.cpp @@ -32,7 +32,7 @@ RageSoundDriver_Null::RageSoundDriver_Null() { m_iSampleRate = PREFSMAN->m_iSoundPreferredSampleRate; if( m_iSampleRate == 0 ) - m_iSampleRate = 44100; + m_iSampleRate = kFallbackSampleRate; m_iLastCursorPos = GetPosition(); StartDecodeThread(); } diff --git a/src/arch/Sound/RageSoundDriver_OSS.cpp b/src/arch/Sound/RageSoundDriver_OSS.cpp index 655fc7fad0..029f341508 100644 --- a/src/arch/Sound/RageSoundDriver_OSS.cpp +++ b/src/arch/Sound/RageSoundDriver_OSS.cpp @@ -196,7 +196,7 @@ RString RageSoundDriver_OSS::Init() // Determine the target sample rate based on preference int targetSampleRate = PREFSMAN->m_iSoundPreferredSampleRate; if (targetSampleRate == 0) { - targetSampleRate = 44100; // Default to 44100 if preference is 0 + targetSampleRate = kFallbackSampleRate; } samplerate = targetSampleRate; // Attempt to set this rate diff --git a/src/arch/Sound/RageSoundDriver_PulseAudio.cpp b/src/arch/Sound/RageSoundDriver_PulseAudio.cpp index 8a58d37c23..12bef491f0 100644 --- a/src/arch/Sound/RageSoundDriver_PulseAudio.cpp +++ b/src/arch/Sound/RageSoundDriver_PulseAudio.cpp @@ -29,7 +29,7 @@ m_PulseMainLoop(nullptr), m_PulseCtx(nullptr), m_PulseStream(nullptr) { m_ss.rate = PREFSMAN->m_iSoundPreferredSampleRate; if( m_ss.rate == 0 ) - m_ss.rate = 44100; + m_ss.rate = kFallbackSampleRate; } RageSoundDriver_PulseAudio::~RageSoundDriver_PulseAudio() diff --git a/src/arch/Sound/RageSoundDriver_WaveOut.cpp b/src/arch/Sound/RageSoundDriver_WaveOut.cpp index c40f7b7626..b05b553f85 100644 --- a/src/arch/Sound/RageSoundDriver_WaveOut.cpp +++ b/src/arch/Sound/RageSoundDriver_WaveOut.cpp @@ -125,7 +125,7 @@ RString RageSoundDriver_WaveOut::Init() b_InitSuccess = false; m_iSampleRate = PREFSMAN->m_iSoundPreferredSampleRate; if( m_iSampleRate == 0 ) - m_iSampleRate = 44100; + m_iSampleRate = kFallbackSampleRate; WAVEFORMATEX fmt; fmt.wFormatTag = WAVE_FORMAT_PCM;