Qt: Fix audio sliders not applying correctly

This commit is contained in:
Connor McLaughlin 2021-01-13 02:36:11 +10:00
parent b3fd07e1b5
commit b5ffbfe826
8 changed files with 39 additions and 26 deletions

View file

@ -445,7 +445,7 @@ void AndroidHostInterface::EmulationThreadLoop(JNIEnv* env)
{
System::UpdatePerformanceCounters();
if (m_speed_limiter_enabled)
if (m_throttler_enabled)
System::Throttle();
}
}

View file

@ -1233,6 +1233,11 @@ void RunFrame()
g_gpu->ResetGraphicsAPIState();
}
float GetTargetSpeed()
{
return s_target_speed;
}
void SetTargetSpeed(float speed)
{
s_target_speed = speed;

View file

@ -149,6 +149,7 @@ void SingleStepCPU();
void RunFrame();
/// Sets target emulation speed.
float GetTargetSpeed();
void SetTargetSpeed(float speed);
/// Adjusts the throttle frequency, i.e. how many times we should sleep per second.

View file

@ -99,8 +99,7 @@ void AudioSettingsWidget::updateVolumeLabel()
void AudioSettingsWidget::onOutputVolumeChanged(int new_value)
{
m_host_interface->SetIntSettingValue("Audio", "OutputVolume", new_value);
if (!m_ui.muted->isChecked() && !QtHostInterface::GetInstance()->IsFastForwardEnabled())
m_host_interface->setAudioOutputVolume(new_value, m_ui.fastForwardVolume->value());
m_host_interface->setAudioOutputVolume(new_value, m_ui.fastForwardVolume->value());
updateVolumeLabel();
}
@ -108,8 +107,7 @@ void AudioSettingsWidget::onOutputVolumeChanged(int new_value)
void AudioSettingsWidget::onFastForwardVolumeChanged(int new_value)
{
m_host_interface->SetIntSettingValue("Audio", "FastForwardVolume", new_value);
if (!m_ui.muted->isChecked() && QtHostInterface::GetInstance()->IsFastForwardEnabled())
m_host_interface->setAudioOutputVolume(m_ui.volume->value(), new_value);
m_host_interface->setAudioOutputVolume(m_ui.volume->value(), new_value);
updateVolumeLabel();
}

View file

@ -1226,11 +1226,11 @@ void QtHostInterface::setAudioOutputVolume(int volume, int fast_forward_volume)
return;
}
if (m_audio_stream)
m_audio_stream->SetOutputVolume(m_speed_limiter_enabled ? volume : fast_forward_volume);
g_settings.audio_output_volume = volume;
g_settings.audio_fast_forward_volume = fast_forward_volume;
if (m_audio_stream)
m_audio_stream->SetOutputVolume(GetAudioOutputVolume());
}
void QtHostInterface::setAudioOutputMuted(bool muted)
@ -1400,7 +1400,7 @@ void QtHostInterface::threadEntryPoint()
System::UpdatePerformanceCounters();
if (m_speed_limiter_enabled)
if (m_throttler_enabled)
System::Throttle();
m_worker_thread_event_loop->processEvents(QEventLoop::AllEvents);

View file

@ -1877,7 +1877,7 @@ void SDLHostInterface::Run()
{
System::UpdatePerformanceCounters();
if (m_speed_limiter_enabled)
if (m_throttler_enabled)
System::Throttle();
}
}

View file

@ -475,7 +475,7 @@ std::unique_ptr<AudioStream> CommonHostInterface::CreateAudioStream(AudioBackend
s32 CommonHostInterface::GetAudioOutputVolume() const
{
return g_settings.GetAudioOutputVolume(!m_speed_limiter_enabled);
return g_settings.GetAudioOutputVolume(IsRunningAtNonStandardSpeed());
}
void CommonHostInterface::UpdateControllerInterface()
@ -602,12 +602,21 @@ bool CommonHostInterface::ResumeSystemFromMostRecentState()
return LoadState(path.c_str());
}
bool CommonHostInterface::IsRunningAtNonStandardSpeed() const
{
if (!System::IsValid())
return false;
const float target_speed = System::GetTargetSpeed();
return (target_speed <= 0.95f || target_speed >= 1.05f);
}
void CommonHostInterface::UpdateSpeedLimiterState()
{
float target_speed = m_turbo_enabled ?
g_settings.turbo_speed :
(m_fast_forward_enabled ? g_settings.fast_forward_speed : g_settings.emulation_speed);
m_speed_limiter_enabled = (target_speed != 0.0f);
m_throttler_enabled = (target_speed != 0.0f);
bool syncing_to_host = false;
if (g_settings.sync_to_host_refresh_rate && g_settings.audio_resampling && target_speed == 1.0f &&
@ -627,15 +636,21 @@ void CommonHostInterface::UpdateSpeedLimiterState()
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() || (m_throttler_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;
!System::IsRunning() || (m_throttler_enabled && g_settings.video_sync_enabled && !is_non_standard_speed);
const float max_display_fps = m_throttler_enabled ? 0.0f : g_settings.display_max_fps;
Log_InfoPrintf("Target speed: %f%%", target_speed * 100.0f);
Log_InfoPrintf("Syncing to %s%s", audio_sync_enabled ? "audio" : "",
(audio_sync_enabled && video_sync_enabled) ? " and video" : (video_sync_enabled ? "video" : ""));
Log_InfoPrintf("Max display fps: %f", max_display_fps);
if (System::IsValid())
{
System::SetTargetSpeed(target_speed);
System::ResetPerformanceCounters();
}
if (m_audio_stream)
{
const u32 input_sample_rate = (target_speed == 0.0f || !g_settings.audio_resampling) ?
@ -657,16 +672,10 @@ void CommonHostInterface::UpdateSpeedLimiterState()
}
if (g_settings.increase_timer_resolution)
SetTimerResolutionIncreased(m_speed_limiter_enabled);
if (System::IsValid())
{
System::SetTargetSpeed(m_speed_limiter_enabled ? target_speed : 1.0f);
System::ResetPerformanceCounters();
}
SetTimerResolutionIncreased(m_throttler_enabled);
if (syncing_to_host)
m_speed_limiter_enabled = false;
m_throttler_enabled = false;
}
void CommonHostInterface::RecreateSystem()

View file

@ -183,8 +183,8 @@ public:
/// Parses a fullscreen mode into its components (width * height @ refresh hz)
static bool ParseFullscreenMode(const std::string_view& mode, u32* width, u32* height, float* refresh_rate);
/// Returns true if fast forwarding is currently active.
bool IsFastForwardEnabled() const { return m_fast_forward_enabled; }
/// Returns true if fast forwarding or slow motion is currently active.
bool IsRunningAtNonStandardSpeed() const;
/// Requests the specified size for the render window. Not guaranteed to succeed (e.g. if in fullscreen).
virtual bool RequestRenderWindowSize(s32 new_window_width, s32 new_window_height);
@ -351,7 +351,7 @@ protected:
bool m_fast_forward_enabled = false;
bool m_turbo_enabled = false;
bool m_timer_resolution_increased = false;
bool m_speed_limiter_enabled = true;
bool m_throttler_enabled = true;
private:
void InitializeUserDirectory();