From 922e17f6776aad24ea8886c7098b3e0a100c489f Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 6 Dec 2020 18:13:27 +1000 Subject: [PATCH] CommonHostInterface: Don't use sleep throttle when syncing to audio at standard speed --- .../app/src/cpp/android_host_interface.cpp | 2 +- src/duckstation-qt/qthostinterface.cpp | 2 +- src/duckstation-sdl/sdl_host_interface.cpp | 2 +- src/frontend-common/common_host_interface.cpp | 20 +++++++++++-------- src/frontend-common/common_host_interface.h | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/android/app/src/cpp/android_host_interface.cpp b/android/app/src/cpp/android_host_interface.cpp index 449d5c149..dd7b411db 100644 --- a/android/app/src/cpp/android_host_interface.cpp +++ b/android/app/src/cpp/android_host_interface.cpp @@ -424,7 +424,7 @@ void AndroidHostInterface::EmulationThreadLoop() { System::UpdatePerformanceCounters(); - if (m_speed_limiter_enabled) + if (m_use_sleep_throttler) System::Throttle(); } } diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index 58015c4aa..c32ef9712 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -1328,7 +1328,7 @@ void QtHostInterface::threadEntryPoint() System::UpdatePerformanceCounters(); - if (m_speed_limiter_enabled) + if (m_use_sleep_throttler) System::Throttle(); m_worker_thread_event_loop->processEvents(QEventLoop::AllEvents); diff --git a/src/duckstation-sdl/sdl_host_interface.cpp b/src/duckstation-sdl/sdl_host_interface.cpp index cb86449d9..01754d19f 100644 --- a/src/duckstation-sdl/sdl_host_interface.cpp +++ b/src/duckstation-sdl/sdl_host_interface.cpp @@ -1817,7 +1817,7 @@ void SDLHostInterface::Run() { System::UpdatePerformanceCounters(); - if (m_speed_limiter_enabled) + if (m_use_sleep_throttler) System::Throttle(); } } diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index 7e0e4d214..0b0e3c3bd 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -601,16 +601,20 @@ bool CommonHostInterface::ResumeSystemFromMostRecentState() void CommonHostInterface::UpdateSpeedLimiterState() { const float target_speed = m_fast_forward_enabled ? g_settings.fast_forward_speed : g_settings.emulation_speed; - m_speed_limiter_enabled = (target_speed != 0.0f); + const bool speed_limiter_enabled = (target_speed != 0.0f); const bool is_non_standard_speed = (std::abs(target_speed - 1.0f) > 0.05f); const bool audio_sync_enabled = - !System::IsRunning() || (m_speed_limiter_enabled && g_settings.audio_sync_enabled && !is_non_standard_speed); + !System::IsRunning() || (speed_limiter_enabled && g_settings.audio_sync_enabled && !is_non_standard_speed); const bool video_sync_enabled = - !System::IsRunning() || (m_speed_limiter_enabled && g_settings.video_sync_enabled && !is_non_standard_speed); - const float max_display_fps = m_speed_limiter_enabled ? 0.0f : g_settings.display_max_fps; - Log_InfoPrintf("Syncing to %s%s", audio_sync_enabled ? "audio" : "", - (audio_sync_enabled && video_sync_enabled) ? " and video" : (video_sync_enabled ? "video" : "")); + !System::IsRunning() || (speed_limiter_enabled && g_settings.video_sync_enabled && !is_non_standard_speed); + const float max_display_fps = speed_limiter_enabled ? 0.0f : g_settings.display_max_fps; + m_use_sleep_throttler = + speed_limiter_enabled && + (!audio_sync_enabled || g_settings.audio_backend == AudioBackend::Null || target_speed != 1.0f); + Log_InfoPrintf("Syncing to %s%s (%s)", audio_sync_enabled ? "audio" : "", + (audio_sync_enabled && video_sync_enabled) ? " and video" : (video_sync_enabled ? "video" : ""), + m_use_sleep_throttler ? "sleep throttler" : "no sleep throttler"); Log_InfoPrintf("Max display fps: %f", max_display_fps); if (m_audio_stream) @@ -627,11 +631,11 @@ void CommonHostInterface::UpdateSpeedLimiterState() } if (g_settings.increase_timer_resolution) - SetTimerResolutionIncreased(m_speed_limiter_enabled); + SetTimerResolutionIncreased(speed_limiter_enabled); if (System::IsValid()) { - System::SetTargetSpeed(m_speed_limiter_enabled ? target_speed : 1.0f); + System::SetTargetSpeed(speed_limiter_enabled ? target_speed : 1.0f); System::ResetPerformanceCounters(); } } diff --git a/src/frontend-common/common_host_interface.h b/src/frontend-common/common_host_interface.h index ce0694a99..b138b7b34 100644 --- a/src/frontend-common/common_host_interface.h +++ b/src/frontend-common/common_host_interface.h @@ -344,7 +344,7 @@ protected: bool m_frame_step_request = false; bool m_fast_forward_enabled = false; bool m_timer_resolution_increased = false; - bool m_speed_limiter_enabled = true; + bool m_use_sleep_throttler = true; private: void InitializeUserDirectory();