Split SetSoundStreamRunning into StartSoundStream and StopSoundStream

This commit is contained in:
Dr. Dystopia 2024-12-22 12:28:21 +01:00
parent ac0d6cbaaa
commit 8cc18164ee
3 changed files with 30 additions and 12 deletions

View file

@ -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)

View file

@ -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);

View file

@ -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()