From a6b04f53e09810d4a9a1db37c23636889e54dfbe Mon Sep 17 00:00:00 2001 From: "Dr. Dystopia" Date: Thu, 22 May 2025 11:28:52 +0200 Subject: [PATCH] AudioCommon: Remove unused qualifiers and make variables constant --- Source/Core/AudioCommon/AudioCommon.cpp | 13 +++++++------ Source/Core/AudioCommon/CubebStream.cpp | 4 ++-- Source/Core/AudioCommon/Mixer.cpp | 21 ++++++++++++--------- Source/Core/AudioCommon/OpenALStream.cpp | 19 ++++++++++--------- Source/Core/AudioCommon/SurroundDecoder.cpp | 2 +- Source/Core/AudioCommon/WASAPIStream.cpp | 5 +++-- 6 files changed, 35 insertions(+), 29 deletions(-) diff --git a/Source/Core/AudioCommon/AudioCommon.cpp b/Source/Core/AudioCommon/AudioCommon.cpp index de046a9aab..bc1efe01d4 100644 --- a/Source/Core/AudioCommon/AudioCommon.cpp +++ b/Source/Core/AudioCommon/AudioCommon.cpp @@ -166,7 +166,8 @@ void UpdateSoundStream(Core::System& system) if (sound_stream) { - int volume = Config::Get(Config::MAIN_AUDIO_MUTED) ? 0 : Config::Get(Config::MAIN_AUDIO_VOLUME); + int const volume = + Config::Get(Config::MAIN_AUDIO_MUTED) ? 0 : Config::Get(Config::MAIN_AUDIO_VOLUME); sound_stream->SetVolume(volume); } } @@ -192,7 +193,7 @@ void SetSoundStreamRunning(Core::System& system, bool running) void SendAIBuffer(Core::System& system, const short* samples, unsigned int num_samples) { - SoundStream* sound_stream = system.GetSoundStream(); + const SoundStream* const sound_stream = system.GetSoundStream(); if (!sound_stream) return; @@ -212,9 +213,9 @@ void SendAIBuffer(Core::System& system, const short* samples, unsigned int num_s void StartAudioDump(Core::System& system) { - SoundStream* sound_stream = system.GetSoundStream(); + const SoundStream* const sound_stream = system.GetSoundStream(); - std::time_t start_time = std::time(nullptr); + std::time_t const start_time = std::time(nullptr); std::string path_prefix = File::GetUserPath(D_DUMPAUDIO_IDX) + SConfig::GetInstance().GetGameID(); @@ -232,7 +233,7 @@ void StartAudioDump(Core::System& system) void StopAudioDump(Core::System& system) { - SoundStream* sound_stream = system.GetSoundStream(); + const SoundStream* const sound_stream = system.GetSoundStream(); if (!sound_stream) return; @@ -265,7 +266,7 @@ void DecreaseVolume(Core::System& system, unsigned short offset) void ToggleMuteVolume(Core::System& system) { - bool isMuted = Config::Get(Config::MAIN_AUDIO_MUTED); + bool const isMuted = Config::Get(Config::MAIN_AUDIO_MUTED); Config::SetBaseOrCurrent(Config::MAIN_AUDIO_MUTED, !isMuted); UpdateSoundStream(system); } diff --git a/Source/Core/AudioCommon/CubebStream.cpp b/Source/Core/AudioCommon/CubebStream.cpp index 4f97b9edd6..70e2c71d14 100644 --- a/Source/Core/AudioCommon/CubebStream.cpp +++ b/Source/Core/AudioCommon/CubebStream.cpp @@ -23,7 +23,7 @@ constexpr u32 BUFFER_SAMPLES = 512; long CubebStream::DataCallback(cubeb_stream* stream, void* user_data, const void* /*input_buffer*/, void* output_buffer, long num_frames) { - auto* self = static_cast(user_data); + const auto* const self = static_cast(user_data); if (self->m_stereo) self->m_mixer->Mix(static_cast(output_buffer), num_frames); @@ -44,7 +44,7 @@ CubebStream::CubebStream() Common::Event sync_event; m_work_queue.Push([this, &sync_event] { Common::ScopeGuard sync_event_guard([&sync_event] { sync_event.Set(); }); - auto result = ::CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE); + auto const result = CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE); m_coinit_success = result == S_OK; m_should_couninit = result == S_OK || result == S_FALSE; }); diff --git a/Source/Core/AudioCommon/Mixer.cpp b/Source/Core/AudioCommon/Mixer.cpp index b52371d994..b981ebf45b 100644 --- a/Source/Core/AudioCommon/Mixer.cpp +++ b/Source/Core/AudioCommon/Mixer.cpp @@ -182,7 +182,8 @@ std::size_t Mixer::MixSurround(float* samples, std::size_t num_samples) memset(samples, 0, num_samples * SURROUND_CHANNELS * sizeof(float)); - std::size_t needed_frames = m_surround_decoder.QueryFramesNeededForSurroundOutput(num_samples); + std::size_t const needed_frames = + m_surround_decoder.QueryFramesNeededForSurroundOutput(num_samples); constexpr std::size_t max_samples = 0x8000; ASSERT_MSG(AUDIO, needed_frames <= max_samples, @@ -190,7 +191,7 @@ std::size_t Mixer::MixSurround(float* samples, std::size_t num_samples) needed_frames, max_samples); std::array buffer; - std::size_t available_frames = Mix(buffer.data(), static_cast(needed_frames)); + std::size_t const available_frames = Mix(buffer.data(), static_cast(needed_frames)); if (available_frames != needed_frames) { ERROR_LOG_FMT(AUDIO, @@ -229,7 +230,7 @@ void Mixer::PushSamples(const s16* samples, std::size_t num_samples) if (m_log_dsp_audio) { const s32 sample_rate_divisor = m_dma_mixer.GetInputSampleRateDivisor(); - auto volume = m_dma_mixer.GetVolume(); + auto const volume = m_dma_mixer.GetVolume(); m_wave_writer_dsp.AddStereoSamplesBE(samples, static_cast(num_samples), sample_rate_divisor, volume.first, volume.second); } @@ -241,7 +242,7 @@ void Mixer::PushStreamingSamples(const s16* samples, std::size_t num_samples) if (m_log_dtk_audio) { const s32 sample_rate_divisor = m_streaming_mixer.GetInputSampleRateDivisor(); - auto volume = m_streaming_mixer.GetVolume(); + auto const volume = m_streaming_mixer.GetVolume(); m_wave_writer_dtk.AddStereoSamplesBE(samples, static_cast(num_samples), sample_rate_divisor, volume.first, volume.second); } @@ -286,7 +287,8 @@ void Mixer::PushSkylanderPortalSamples(const u8* samples, std::size_t num_sample { for (std::size_t i = 0; i < num_samples; ++i) { - s16 sample = static_cast(samples[i * 2 + 1]) << 8 | static_cast(samples[i * 2]); + s16 const sample = + static_cast(samples[i * 2 + 1]) << 8 | static_cast(samples[i * 2]); samples_stereo[i * 2] = sample; samples_stereo[i * 2 + 1] = sample; } @@ -335,7 +337,8 @@ void Mixer::StartLogDTKAudio(const std::string& filename) { if (!m_log_dtk_audio) { - bool success = m_wave_writer_dtk.Start(filename, m_streaming_mixer.GetInputSampleRateDivisor()); + bool const success = + m_wave_writer_dtk.Start(filename, m_streaming_mixer.GetInputSampleRateDivisor()); if (success) { m_log_dtk_audio = true; @@ -372,7 +375,7 @@ void Mixer::StartLogDSPAudio(const std::string& filename) { if (!m_log_dsp_audio) { - bool success = m_wave_writer_dsp.Start(filename, m_dma_mixer.GetInputSampleRateDivisor()); + bool const success = m_wave_writer_dsp.Start(filename, m_dma_mixer.GetInputSampleRateDivisor()); if (success) { m_log_dsp_audio = true; @@ -494,10 +497,10 @@ void Mixer::MixerFifo::Enqueue() 0.0002984010f, 0.0002102045f, 0.0001443499f, 0.0000961509f, 0.0000616906f, 0.0000377350f, 0.0000216492f, 0.0000113187f, 0.0000050749f, 0.0000016272f}; - const std::size_t head = m_queue_head.load(std::memory_order_acquire); + std::size_t const head = m_queue_head.load(std::memory_order_acquire); // Check if we run out of space in the circular queue. (rare) - std::size_t next_head = (head + 1) & GRANULE_QUEUE_MASK; + std::size_t const next_head = (head + 1) & GRANULE_QUEUE_MASK; if (next_head == m_queue_tail.load(std::memory_order_acquire)) { WARN_LOG_FMT(AUDIO, diff --git a/Source/Core/AudioCommon/OpenALStream.cpp b/Source/Core/AudioCommon/OpenALStream.cpp index 31ae9b047e..a059d428c0 100644 --- a/Source/Core/AudioCommon/OpenALStream.cpp +++ b/Source/Core/AudioCommon/OpenALStream.cpp @@ -76,7 +76,7 @@ static bool InitLibrary() if (!InitFunctions()) { - ::FreeLibrary(s_openal_dll); + FreeLibrary(s_openal_dll); s_openal_dll = nullptr; return false; } @@ -168,7 +168,7 @@ bool OpenALStream::SetRunning(bool running) static ALenum CheckALError(const char* desc) { - ALenum err = palGetError(); + ALenum const err = palGetError(); if (err != AL_NO_ERROR) { @@ -211,16 +211,16 @@ void OpenALStream::SoundLoop() { Common::SetCurrentThreadName("Audio thread - openal"); - bool float32_capable = palIsExtensionPresent("AL_EXT_float32") != 0; - bool surround_capable = palIsExtensionPresent("AL_EXT_MCFORMATS") || IsCreativeXFi(); + bool const float32_capable = palIsExtensionPresent("AL_EXT_float32") != 0; + bool const surround_capable = palIsExtensionPresent("AL_EXT_MCFORMATS") || IsCreativeXFi(); bool use_surround = Config::ShouldUseDPL2Decoder() && surround_capable; // As there is no extension to check for 32-bit fixed point support // and we know that only a X-Fi with hardware OpenAL supports it, // we just check if one is being used. - bool fixed32_capable = IsCreativeXFi(); + bool const fixed32_capable = IsCreativeXFi(); - u32 frequency = m_mixer->GetSampleRate(); + u32 const frequency = m_mixer->GetSampleRate(); u32 frames_per_buffer; // Can't have zero samples per buffer @@ -288,12 +288,12 @@ void OpenALStream::SoundLoop() num_buffers_queued -= num_buffers_processed; } - unsigned int min_frames = frames_per_buffer; + unsigned int const min_frames = frames_per_buffer; if (use_surround) { std::array dpl2; - u32 rendered_frames = static_cast(m_mixer->MixSurround(dpl2.data(), min_frames)); + u32 const rendered_frames = static_cast(m_mixer->MixSurround(dpl2.data(), min_frames)); if (rendered_frames < min_frames) continue; @@ -351,7 +351,8 @@ void OpenALStream::SoundLoop() } else { - u32 rendered_frames = static_cast(m_mixer->Mix(m_realtime_buffer.data(), min_frames)); + u32 const rendered_frames = + static_cast(m_mixer->Mix(m_realtime_buffer.data(), min_frames)); if (!rendered_frames) continue; diff --git a/Source/Core/AudioCommon/SurroundDecoder.cpp b/Source/Core/AudioCommon/SurroundDecoder.cpp index ffc0b00a2f..acab16816c 100644 --- a/Source/Core/AudioCommon/SurroundDecoder.cpp +++ b/Source/Core/AudioCommon/SurroundDecoder.cpp @@ -32,7 +32,7 @@ size_t SurroundDecoder::QueryFramesNeededForSurroundOutput(const size_t output_f if (m_decoded_fifo.size() < output_frames * SURROUND_CHANNELS) { // Output stereo frames needed to have at least the desired number of surround frames - size_t frames_needed = output_frames - m_decoded_fifo.size() / SURROUND_CHANNELS; + size_t const frames_needed = output_frames - m_decoded_fifo.size() / SURROUND_CHANNELS; return frames_needed + m_frame_block_size - frames_needed % m_frame_block_size; } diff --git a/Source/Core/AudioCommon/WASAPIStream.cpp b/Source/Core/AudioCommon/WASAPIStream.cpp index dddc1f6ebb..f06f760b6f 100644 --- a/Source/Core/AudioCommon/WASAPIStream.cpp +++ b/Source/Core/AudioCommon/WASAPIStream.cpp @@ -159,8 +159,9 @@ ComPtr WASAPIStream::GetDeviceByName(std::string_view name) bool WASAPIStream::Init() { ASSERT(m_enumerator == nullptr); - HRESULT result = CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_INPROC_SERVER, - IID_PPV_ARGS(m_enumerator.GetAddressOf())); + HRESULT const result = + CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_INPROC_SERVER, + IID_PPV_ARGS(m_enumerator.GetAddressOf())); if (!HandleWinAPI("Failed to create MMDeviceEnumerator", result)) return false;