Address review feedback and improve code style

- Moved end-of-line comments to preceding lines for better readability and to avoid potential line length issues across various files modified in previous commits.
- In the RageSoundReader_Chain constructor: Removed redundant initialization of m_iPreferredSampleRate. Replaced hardcoded 44100 with kFallbackSampleRate. Removed an unnecessary comment.
- Added braces consistently to single-statement if/else blocks across all recently modified sound system files. This enhances code clarity and maintainability by explicitly defining block scopes.
This commit is contained in:
Patrik Nilsson
2025-06-01 13:36:25 +02:00
committed by teejusb
parent 72c7316671
commit 7d398919a0
11 changed files with 28 additions and 8 deletions
+2 -1
View File
@@ -135,7 +135,8 @@ int RageSoundManager::GetDriverSampleRate() const
if( m_pDriver == nullptr ) if( m_pDriver == nullptr )
return kFallbackSampleRate; return kFallbackSampleRate;
return m_pDriver->GetSampleRate(); // Returns the *actual* operating rate of the loaded driver // Returns the *actual* operating rate of the loaded driver
return m_pDriver->GetSampleRate();
} }
/* If the given path is loaded, return a copy; otherwise return nullptr. /* If the given path is loaded, return a copy; otherwise return nullptr.
+5 -1
View File
@@ -1,4 +1,5 @@
#include "global.h" #include "global.h"
#include "PrefsManager.h"
#include "RageSoundReader_Chain.h" #include "RageSoundReader_Chain.h"
#include "RageSoundReader_FileReader.h" #include "RageSoundReader_FileReader.h"
#include "RageSoundReader_Resample_Good.h" #include "RageSoundReader_Resample_Good.h"
@@ -6,6 +7,7 @@
#include "RageSoundReader_Pan.h" #include "RageSoundReader_Pan.h"
#include "RageLog.h" #include "RageLog.h"
#include "RageUtil.h" #include "RageUtil.h"
#include "RageSound.h"
#include "RageSoundMixBuffer.h" #include "RageSoundMixBuffer.h"
#include "RageSoundUtil.h" #include "RageSoundUtil.h"
@@ -25,7 +27,9 @@ RageSoundReader_Chain::RageSoundReader_Chain()
{ {
m_iPreferredSampleRate = PREFSMAN->m_iSoundPreferredSampleRate; m_iPreferredSampleRate = PREFSMAN->m_iSoundPreferredSampleRate;
if (m_iPreferredSampleRate == 0) if (m_iPreferredSampleRate == 0)
m_iPreferredSampleRate = 44100; // Default if system default (0) is chosen {
m_iPreferredSampleRate = kFallbackSampleRate;
}
m_iActualSampleRate = -1; m_iActualSampleRate = -1;
m_iChannels = 0; m_iChannels = 0;
+4
View File
@@ -230,9 +230,13 @@ RString Alsa9Buf::Init( int channels_,
preferred_writeahead = iWriteahead; preferred_writeahead = iWriteahead;
preferred_chunksize = iChunkSize; preferred_chunksize = iChunkSize;
if( iSampleRate == 0 ) if( iSampleRate == 0 )
{
samplerate = kFallbackSampleRate; samplerate = kFallbackSampleRate;
}
else else
{
samplerate = iSampleRate; samplerate = iSampleRate;
}
GetSoundCardDebugInfo(); GetSoundCardDebugInfo();
+2 -1
View File
@@ -200,7 +200,8 @@ RString DSoundBuf::Init( DSound &ds, DSoundBuf::hw hardware,
waveformat.wFormatTag = WAVE_FORMAT_PCM; waveformat.wFormatTag = WAVE_FORMAT_PCM;
bool bNeedCtrlFrequency = false; bool bNeedCtrlFrequency = false;
if( m_iSampleRate == DYNAMIC_SAMPLERATE ) // DYNAMIC_SAMPLERATE is usually 0 or some special value // DYNAMIC_SAMPLERATE is usually 0 or some special value
if( m_iSampleRate == DYNAMIC_SAMPLERATE )
{ {
m_iSampleRate = kFallbackSampleRate; m_iSampleRate = kFallbackSampleRate;
bNeedCtrlFrequency = true; bNeedCtrlFrequency = true;
+1 -1
View File
@@ -13,7 +13,7 @@
class RageSoundBase; class RageSoundBase;
class RageTimer; class RageTimer;
class RageSoundMixBuffer; class RageSoundMixBuffer;
static const int samples_per_block = 512; // This should probably be kSamplesPerBlock or similar if it's truly const and static static const int samples_per_block = 512;
class RageSoundDriver: public RageDriver class RageSoundDriver: public RageDriver
{ {
+3 -1
View File
@@ -151,7 +151,9 @@ RString RageSoundDriver_AU::Init()
streamFormat.mBitsPerChannel = kBitsPerChannel; streamFormat.mBitsPerChannel = kBitsPerChannel;
if( streamFormat.mSampleRate <= 0.0 ) if( streamFormat.mSampleRate <= 0.0 )
streamFormat.mSampleRate = 44100.0; {
streamFormat.mSampleRate = kFallbackSampleRate;
}
m_iSampleRate = int( streamFormat.mSampleRate ); m_iSampleRate = int( streamFormat.mSampleRate );
m_TimeScale = streamFormat.mSampleRate / AudioGetHostClockFrequency(); m_TimeScale = streamFormat.mSampleRate / AudioGetHostClockFrequency();
@@ -97,7 +97,9 @@ RString RageSoundDriver_DSound_Software::Init()
m_pPCM = new DSoundBuf; m_pPCM = new DSoundBuf;
m_iSampleRate = PREFSMAN->m_iSoundPreferredSampleRate; m_iSampleRate = PREFSMAN->m_iSoundPreferredSampleRate;
if( m_iSampleRate == 0 ) if( m_iSampleRate == 0 )
{
m_iSampleRate = kFallbackSampleRate; m_iSampleRate = kFallbackSampleRate;
}
// This m_iSampleRate (driver's) is then passed as the iSampleRate parameter to DSoundBuf::Init() // 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 ); sError = m_pPCM->Init( ds, DSoundBuf::HW_DONT_CARE, channels, m_iSampleRate, 16, g_iMaxWriteahead );
if( sError != "" ) if( sError != "" )
+3 -2
View File
@@ -31,8 +31,9 @@ int64_t RageSoundDriver_Null::GetPosition() const
RageSoundDriver_Null::RageSoundDriver_Null() RageSoundDriver_Null::RageSoundDriver_Null()
{ {
m_iSampleRate = PREFSMAN->m_iSoundPreferredSampleRate; m_iSampleRate = PREFSMAN->m_iSoundPreferredSampleRate;
if( m_iSampleRate == 0 ) {
m_iSampleRate = kFallbackSampleRate; m_iSampleRate = kFallbackSampleRate;
}
m_iLastCursorPos = GetPosition(); m_iLastCursorPos = GetPosition();
StartDecodeThread(); StartDecodeThread();
} }
+2 -1
View File
@@ -195,7 +195,8 @@ RString RageSoundDriver_OSS::Init()
// Determine the target sample rate based on preference // Determine the target sample rate based on preference
int targetSampleRate = PREFSMAN->m_iSoundPreferredSampleRate; int targetSampleRate = PREFSMAN->m_iSoundPreferredSampleRate;
if (targetSampleRate == 0) { if (targetSampleRate == 0)
{
targetSampleRate = kFallbackSampleRate; targetSampleRate = kFallbackSampleRate;
} }
@@ -29,7 +29,9 @@ m_PulseMainLoop(nullptr), m_PulseCtx(nullptr), m_PulseStream(nullptr)
{ {
m_ss.rate = PREFSMAN->m_iSoundPreferredSampleRate; m_ss.rate = PREFSMAN->m_iSoundPreferredSampleRate;
if( m_ss.rate == 0 ) if( m_ss.rate == 0 )
{
m_ss.rate = kFallbackSampleRate; m_ss.rate = kFallbackSampleRate;
}
} }
RageSoundDriver_PulseAudio::~RageSoundDriver_PulseAudio() RageSoundDriver_PulseAudio::~RageSoundDriver_PulseAudio()
@@ -125,7 +125,9 @@ RString RageSoundDriver_WaveOut::Init()
b_InitSuccess = false; b_InitSuccess = false;
m_iSampleRate = PREFSMAN->m_iSoundPreferredSampleRate; m_iSampleRate = PREFSMAN->m_iSoundPreferredSampleRate;
if( m_iSampleRate == 0 ) if( m_iSampleRate == 0 )
{
m_iSampleRate = kFallbackSampleRate; m_iSampleRate = kFallbackSampleRate;
}
WAVEFORMATEX fmt; WAVEFORMATEX fmt;
fmt.wFormatTag = WAVE_FORMAT_PCM; fmt.wFormatTag = WAVE_FORMAT_PCM;