From 5bb2b3ec6363f7db04cea92bdae84158d36a78fb Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 23 Dec 2019 17:05:43 +1000 Subject: [PATCH] Frontend: Add audio backend to settings (switch-while-running) --- src/core/spu.cpp | 5 ++-- src/core/spu.h | 1 - src/duckstation/sdl_host_interface.cpp | 34 ++++++++++++++++++++++---- src/duckstation/sdl_host_interface.h | 2 +- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/core/spu.cpp b/src/core/spu.cpp index 86d33c30e..c2c9465f4 100644 --- a/src/core/spu.cpp +++ b/src/core/spu.cpp @@ -21,7 +21,6 @@ SPU::~SPU() = default; void SPU::Initialize(System* system, DMA* dma, InterruptController* interrupt_controller) { - m_audio_stream = system->GetHostInterface()->GetAudioStream(); m_system = system; m_dma = dma; m_interrupt_controller = interrupt_controller; @@ -109,7 +108,7 @@ bool SPU::DoState(StateWrapper& sw) sw.DoBytes(m_ram.data(), RAM_SIZE); if (sw.IsReading()) - m_audio_stream->EmptyBuffers(); + m_system->GetHostInterface()->GetAudioStream()->EmptyBuffers(); return !sw.HasError(); } @@ -1006,7 +1005,7 @@ void SPU::GenerateSample() std::array out_samples; out_samples[0] = Clamp16(ApplyVolume(left_sum, m_main_volume_left.GetVolume())); out_samples[1] = Clamp16(ApplyVolume(right_sum, m_main_volume_right.GetVolume())); - m_audio_stream->WriteSamples(out_samples.data(), 1); + m_system->GetHostInterface()->GetAudioStream()->WriteSamples(out_samples.data(), 1); // Write to capture buffers. WriteToCaptureBuffer(0, cd_audio_left); diff --git a/src/core/spu.h b/src/core/spu.h index 21e354002..c40a99a24 100644 --- a/src/core/spu.h +++ b/src/core/spu.h @@ -287,7 +287,6 @@ private: System* m_system = nullptr; DMA* m_dma = nullptr; InterruptController* m_interrupt_controller = nullptr; - AudioStream* m_audio_stream = nullptr; SPUCNT m_SPUCNT = {}; SPUSTAT m_SPUSTAT = {}; diff --git a/src/duckstation/sdl_host_interface.cpp b/src/duckstation/sdl_host_interface.cpp index 9cc773628..69afc7287 100644 --- a/src/duckstation/sdl_host_interface.cpp +++ b/src/duckstation/sdl_host_interface.cpp @@ -201,10 +201,16 @@ void SDLHostInterface::SwitchGPURenderer() ClearImGuiFocus(); } -void SDLHostInterface::SwitchAudioRenderer() +void SDLHostInterface::SwitchAudioBackend() { m_audio_stream.reset(); CreateAudioStream(); + + if (m_system) + { + m_audio_stream->PauseOutput(false); + UpdateSpeedLimiterState(); + } } void SDLHostInterface::UpdateFullscreen() @@ -1162,14 +1168,26 @@ void SDLHostInterface::DrawSettingsWindow() } ImGui::NewLine(); - if (DrawSettingsSectionHeader("Host Synchronization")) + if (DrawSettingsSectionHeader("Audio")) { - if (ImGui::Checkbox("Sync To Audio", &m_settings.audio_sync_enabled)) + ImGui::Text("Backend:"); + ImGui::SameLine(indent); + + int backend = static_cast(m_settings.audio_backend); + if (ImGui::Combo( + "##backend", &backend, + [](void*, int index, const char** out_text) { + *out_text = Settings::GetAudioBackendDisplayName(static_cast(index)); + return true; + }, + nullptr, static_cast(AudioBackend::Count))) { + m_settings.audio_backend = static_cast(backend); settings_changed = true; - UpdateSpeedLimiterState(); + SwitchAudioBackend(); } - if (ImGui::Checkbox("Sync To Video", &m_settings.video_sync_enabled)) + + if (ImGui::Checkbox("Output Sync", &m_settings.audio_sync_enabled)) { settings_changed = true; UpdateSpeedLimiterState(); @@ -1292,6 +1310,12 @@ void SDLHostInterface::DrawSettingsWindow() m_display->SetDisplayLinearFiltering(m_settings.display_linear_filtering); settings_changed = true; } + + if (ImGui::Checkbox("VSync", &m_settings.video_sync_enabled)) + { + settings_changed = true; + UpdateSpeedLimiterState(); + } } ImGui::NewLine(); diff --git a/src/duckstation/sdl_host_interface.h b/src/duckstation/sdl_host_interface.h index b0eb8a420..f98db99ed 100644 --- a/src/duckstation/sdl_host_interface.h +++ b/src/duckstation/sdl_host_interface.h @@ -85,7 +85,7 @@ private: void QueueSwitchGPURenderer(); void SwitchGPURenderer(); - void SwitchAudioRenderer(); + void SwitchAudioBackend(); void UpdateFullscreen(); void UpdateControllerMapping();