System: Reset throttler when audio buffers underflow

Should hopefully reduce the chances of the audio source ending up out of
phase from the emulation when vsync is disabled.
This commit is contained in:
Connor McLaughlin
2020-12-07 02:43:46 +10:00
parent c8f33e340b
commit b44a654943
4 changed files with 28 additions and 4 deletions

View File

@ -1216,8 +1216,22 @@ void UpdateThrottlePeriod()
static_cast<s32>(1000000000.0 / static_cast<double>(s_throttle_frequency) / static_cast<double>(s_target_speed));
}
void ResetThrottler()
{
s_last_throttle_time = 0;
s_throttle_timer.Reset();
}
void Throttle()
{
// Reset the throttler on audio buffer overflow, so we don't end up out of phase.
if (g_host_interface->GetAudioStream()->DidUnderflow())
{
Log_DevPrintf("Audio buffer underflowed, resetting throttler");
ResetThrottler();
return;
}
// Allow variance of up to 40ms either way.
constexpr s64 MAX_VARIANCE_TIME = INT64_C(40000000);
@ -1239,8 +1253,7 @@ void Throttle()
s_speed_lost_time_timestamp.Reset();
}
#endif
s_last_throttle_time = 0;
s_throttle_timer.Reset();
ResetThrottler();
}
else if (sleep_time >= MINIMUM_SLEEP_TIME)
{
@ -1294,8 +1307,7 @@ void ResetPerformanceCounters()
s_average_frame_time_accumulator = 0.0f;
s_worst_frame_time_accumulator = 0.0f;
s_fps_timer.Reset();
s_throttle_timer.Reset();
s_last_throttle_time = 0;
ResetThrottler();
}
bool LoadEXE(const char* filename)

View File

@ -154,6 +154,7 @@ void SetThrottleFrequency(float frequency);
/// Updates the throttle period, call when target emulation speed changes.
void UpdateThrottlePeriod();
void ResetThrottler();
/// Throttles the system, i.e. sleeps until it's time to execute the next frame.
void Throttle();