From 8cc18164ee2ecdbc11a503279796a7bfc7c6fd5e Mon Sep 17 00:00:00 2001 From: "Dr. Dystopia" Date: Sun, 22 Dec 2024 12:28:21 +0100 Subject: [PATCH] Split `SetSoundStreamRunning` into `StartSoundStream` and `StopSoundStream` --- Source/Core/AudioCommon/AudioCommon.cpp | 37 ++++++++++++++++++------- Source/Core/AudioCommon/AudioCommon.h | 3 +- Source/Core/Core/HW/CPU.cpp | 2 +- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Source/Core/AudioCommon/AudioCommon.cpp b/Source/Core/AudioCommon/AudioCommon.cpp index d9fee4ef72..6332dc8844 100644 --- a/Source/Core/AudioCommon/AudioCommon.cpp +++ b/Source/Core/AudioCommon/AudioCommon.cpp @@ -73,7 +73,7 @@ void PostInitSoundStream(Core::System& system) // This needs to be called after AudioInterface::Init and SerialInterface::Init (for GBA devices) // where input sample rates are set UpdateSoundStream(system); - SetSoundStreamRunning(system, true); + StartSoundStream(system); if (Config::Get(Config::MAIN_DUMP_AUDIO) && !system.IsAudioDumpStarted()) StartAudioDump(system); @@ -86,7 +86,7 @@ void ShutdownSoundStream(Core::System& system) if (Config::Get(Config::MAIN_DUMP_AUDIO) && system.IsAudioDumpStarted()) StopAudioDump(system); - SetSoundStreamRunning(system, false); + StopSoundStream(system); system.SetSoundStream(nullptr); INFO_LOG_FMT(AUDIO, "Done shutting down sound stream"); @@ -170,23 +170,40 @@ void UpdateSoundStream(Core::System& system) } } -void SetSoundStreamRunning(Core::System& system, bool running) +void StartSoundStream(Core::System& system) { SoundStream* sound_stream = system.GetSoundStream(); if (!sound_stream) return; - if (system.IsSoundStreamRunning() == running) + if (system.IsSoundStreamRunning()) return; - system.SetSoundStreamRunning(running); - if (sound_stream->SetRunning(running)) + system.SetSoundStreamRunning(true); + + if (sound_stream->SetRunning(true)) return; - if (running) - ERROR_LOG_FMT(AUDIO, "Error starting stream."); - else - ERROR_LOG_FMT(AUDIO, "Error stopping stream."); + + ERROR_LOG_FMT(AUDIO, "Error starting stream."); +} + +void StopSoundStream(Core::System& system) +{ + SoundStream* sound_stream = system.GetSoundStream(); + + if (!sound_stream) + return; + + if (!system.IsSoundStreamRunning()) + return; + + system.SetSoundStreamRunning(false); + + if (sound_stream->SetRunning(false)) + return; + + ERROR_LOG_FMT(AUDIO, "Error stopping stream."); } void SendAIBuffer(Core::System& system, const short* samples, unsigned int num_samples) diff --git a/Source/Core/AudioCommon/AudioCommon.h b/Source/Core/AudioCommon/AudioCommon.h index f883f32f85..d858cc2ed0 100644 --- a/Source/Core/AudioCommon/AudioCommon.h +++ b/Source/Core/AudioCommon/AudioCommon.h @@ -30,7 +30,8 @@ bool SupportsDPL2Decoder(std::string_view backend); bool SupportsLatencyControl(std::string_view backend); bool SupportsVolumeChanges(std::string_view backend); void UpdateSoundStream(Core::System& system); -void SetSoundStreamRunning(Core::System& system, bool running); +void StartSoundStream(Core::System& system); +void StopSoundStream(Core::System& system); void SendAIBuffer(Core::System& system, const short* samples, unsigned int num_samples); void StartAudioDump(Core::System& system); void StopAudioDump(Core::System& system); diff --git a/Source/Core/Core/HW/CPU.cpp b/Source/Core/Core/HW/CPU.cpp index 1eae912476..6bc10fddf0 100644 --- a/Source/Core/Core/HW/CPU.cpp +++ b/Source/Core/Core/HW/CPU.cpp @@ -176,7 +176,7 @@ void CPUManager::RunAdjacentSystems(bool running) m_system.GetFifo().EmulatorState(running); // Core is responsible for shutting down the sound stream. if (m_state != State::PowerDown) - AudioCommon::SetSoundStreamRunning(m_system, running); + running ? AudioCommon::StartSoundStream(m_system) : AudioCommon::StopSoundStream(m_system); } void CPUManager::Stop()