From 7d398919a02ca515f4b1aab2bf6cb10d570cc239 Mon Sep 17 00:00:00 2001 From: Patrik Nilsson <113925545+pnn64@users.noreply.github.com> Date: Sun, 1 Jun 2025 13:36:25 +0200 Subject: [PATCH] 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. --- src/RageSoundManager.cpp | 3 ++- src/RageSoundReader_Chain.cpp | 6 +++++- src/arch/Sound/ALSA9Helpers.cpp | 4 ++++ src/arch/Sound/DSoundHelpers.cpp | 3 ++- src/arch/Sound/RageSoundDriver.h | 2 +- src/arch/Sound/RageSoundDriver_AU.mm | 4 +++- src/arch/Sound/RageSoundDriver_DSound_Software.cpp | 2 ++ src/arch/Sound/RageSoundDriver_Null.cpp | 5 +++-- src/arch/Sound/RageSoundDriver_OSS.cpp | 3 ++- src/arch/Sound/RageSoundDriver_PulseAudio.cpp | 2 ++ src/arch/Sound/RageSoundDriver_WaveOut.cpp | 2 ++ 11 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/RageSoundManager.cpp b/src/RageSoundManager.cpp index 527ac8d2cd..33e3b04cc3 100644 --- a/src/RageSoundManager.cpp +++ b/src/RageSoundManager.cpp @@ -135,7 +135,8 @@ int RageSoundManager::GetDriverSampleRate() const if( m_pDriver == nullptr ) 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. diff --git a/src/RageSoundReader_Chain.cpp b/src/RageSoundReader_Chain.cpp index 3020eee663..ba4d134915 100644 --- a/src/RageSoundReader_Chain.cpp +++ b/src/RageSoundReader_Chain.cpp @@ -1,4 +1,5 @@ #include "global.h" +#include "PrefsManager.h" #include "RageSoundReader_Chain.h" #include "RageSoundReader_FileReader.h" #include "RageSoundReader_Resample_Good.h" @@ -6,6 +7,7 @@ #include "RageSoundReader_Pan.h" #include "RageLog.h" #include "RageUtil.h" +#include "RageSound.h" #include "RageSoundMixBuffer.h" #include "RageSoundUtil.h" @@ -25,7 +27,9 @@ RageSoundReader_Chain::RageSoundReader_Chain() { m_iPreferredSampleRate = PREFSMAN->m_iSoundPreferredSampleRate; if (m_iPreferredSampleRate == 0) - m_iPreferredSampleRate = 44100; // Default if system default (0) is chosen + { + m_iPreferredSampleRate = kFallbackSampleRate; + } m_iActualSampleRate = -1; m_iChannels = 0; diff --git a/src/arch/Sound/ALSA9Helpers.cpp b/src/arch/Sound/ALSA9Helpers.cpp index 9f084e1860..218385bcfc 100644 --- a/src/arch/Sound/ALSA9Helpers.cpp +++ b/src/arch/Sound/ALSA9Helpers.cpp @@ -230,9 +230,13 @@ RString Alsa9Buf::Init( int channels_, preferred_writeahead = iWriteahead; preferred_chunksize = iChunkSize; if( iSampleRate == 0 ) + { samplerate = kFallbackSampleRate; + } else + { samplerate = iSampleRate; + } GetSoundCardDebugInfo(); diff --git a/src/arch/Sound/DSoundHelpers.cpp b/src/arch/Sound/DSoundHelpers.cpp index d8eb131f13..928e4c6dae 100644 --- a/src/arch/Sound/DSoundHelpers.cpp +++ b/src/arch/Sound/DSoundHelpers.cpp @@ -200,7 +200,8 @@ RString DSoundBuf::Init( DSound &ds, DSoundBuf::hw hardware, waveformat.wFormatTag = WAVE_FORMAT_PCM; 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; bNeedCtrlFrequency = true; diff --git a/src/arch/Sound/RageSoundDriver.h b/src/arch/Sound/RageSoundDriver.h index 75616341bc..a4c8ff9f37 100644 --- a/src/arch/Sound/RageSoundDriver.h +++ b/src/arch/Sound/RageSoundDriver.h @@ -13,7 +13,7 @@ class RageSoundBase; class RageTimer; 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 { diff --git a/src/arch/Sound/RageSoundDriver_AU.mm b/src/arch/Sound/RageSoundDriver_AU.mm index 28366266be..db44f5cac2 100644 --- a/src/arch/Sound/RageSoundDriver_AU.mm +++ b/src/arch/Sound/RageSoundDriver_AU.mm @@ -151,7 +151,9 @@ RString RageSoundDriver_AU::Init() streamFormat.mBitsPerChannel = kBitsPerChannel; if( streamFormat.mSampleRate <= 0.0 ) - streamFormat.mSampleRate = 44100.0; + { + streamFormat.mSampleRate = kFallbackSampleRate; + } m_iSampleRate = int( streamFormat.mSampleRate ); m_TimeScale = streamFormat.mSampleRate / AudioGetHostClockFrequency(); diff --git a/src/arch/Sound/RageSoundDriver_DSound_Software.cpp b/src/arch/Sound/RageSoundDriver_DSound_Software.cpp index 58bc1bc009..fc3f4b699a 100644 --- a/src/arch/Sound/RageSoundDriver_DSound_Software.cpp +++ b/src/arch/Sound/RageSoundDriver_DSound_Software.cpp @@ -97,7 +97,9 @@ RString RageSoundDriver_DSound_Software::Init() m_pPCM = new DSoundBuf; m_iSampleRate = PREFSMAN->m_iSoundPreferredSampleRate; if( m_iSampleRate == 0 ) + { 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 067b1d9e85..32878b8ade 100644 --- a/src/arch/Sound/RageSoundDriver_Null.cpp +++ b/src/arch/Sound/RageSoundDriver_Null.cpp @@ -31,8 +31,9 @@ int64_t RageSoundDriver_Null::GetPosition() const RageSoundDriver_Null::RageSoundDriver_Null() { m_iSampleRate = PREFSMAN->m_iSoundPreferredSampleRate; - if( m_iSampleRate == 0 ) - m_iSampleRate = kFallbackSampleRate; + { + m_iSampleRate = kFallbackSampleRate; + } m_iLastCursorPos = GetPosition(); StartDecodeThread(); } diff --git a/src/arch/Sound/RageSoundDriver_OSS.cpp b/src/arch/Sound/RageSoundDriver_OSS.cpp index 029f341508..f1fc526126 100644 --- a/src/arch/Sound/RageSoundDriver_OSS.cpp +++ b/src/arch/Sound/RageSoundDriver_OSS.cpp @@ -195,7 +195,8 @@ RString RageSoundDriver_OSS::Init() // Determine the target sample rate based on preference int targetSampleRate = PREFSMAN->m_iSoundPreferredSampleRate; - if (targetSampleRate == 0) { + if (targetSampleRate == 0) + { targetSampleRate = kFallbackSampleRate; } diff --git a/src/arch/Sound/RageSoundDriver_PulseAudio.cpp b/src/arch/Sound/RageSoundDriver_PulseAudio.cpp index 12bef491f0..74cd2881d3 100644 --- a/src/arch/Sound/RageSoundDriver_PulseAudio.cpp +++ b/src/arch/Sound/RageSoundDriver_PulseAudio.cpp @@ -29,7 +29,9 @@ m_PulseMainLoop(nullptr), m_PulseCtx(nullptr), m_PulseStream(nullptr) { m_ss.rate = PREFSMAN->m_iSoundPreferredSampleRate; if( m_ss.rate == 0 ) + { 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 b05b553f85..0ae39a6c19 100644 --- a/src/arch/Sound/RageSoundDriver_WaveOut.cpp +++ b/src/arch/Sound/RageSoundDriver_WaveOut.cpp @@ -125,7 +125,9 @@ RString RageSoundDriver_WaveOut::Init() b_InitSuccess = false; m_iSampleRate = PREFSMAN->m_iSoundPreferredSampleRate; if( m_iSampleRate == 0 ) + { m_iSampleRate = kFallbackSampleRate; + } WAVEFORMATEX fmt; fmt.wFormatTag = WAVE_FORMAT_PCM;