Centralize fallback sample rate with kFallbackSampleRate
Replaces hardcoded 44100Hz values (used as fallbacks or for the "Default" sample rate preference) with a new constant `constexpr int kFallbackSampleRate = 44100;` defined in RageSound.h. This constant is now used in: - RageSoundReader_Silence - RageSoundManager (for unloaded driver scenarios) - All sound drivers' initialization logic for the "Default (0)" preference (DSound, WaveOut, AU, PulseAudio, OSS, WDMKS, Null) - DSound primary buffer setup.
This commit is contained in:
+1
-1
@@ -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; }
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
constexpr int kFallbackSampleRate = 44100;
|
||||
|
||||
class RageSoundReader;
|
||||
struct lua_State;
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,14 @@
|
||||
#include "RageThreads.h"
|
||||
#include "RageTimer.h"
|
||||
#include "RageUtil_CircularBuffer.h"
|
||||
#include "RageSound.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
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
|
||||
|
||||
@@ -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 != "" )
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user