System: Fix sync to host refresh audio stretching
This commit is contained in:
parent
e01efaa681
commit
14ba3b7312
|
@ -453,6 +453,7 @@ void SPU::CreateOutputStream()
|
|||
}
|
||||
|
||||
s_audio_stream->SetOutputVolume(System::GetAudioOutputVolume());
|
||||
s_audio_stream->SetNominalRate(System::GetAudioNominalRate());
|
||||
s_audio_stream->SetPaused(System::IsPaused());
|
||||
}
|
||||
|
||||
|
|
|
@ -2681,6 +2681,11 @@ float System::GetTargetSpeed()
|
|||
return s_target_speed;
|
||||
}
|
||||
|
||||
float System::GetAudioNominalRate()
|
||||
{
|
||||
return s_throttler_enabled ? s_target_speed : 1.0f;
|
||||
}
|
||||
|
||||
void System::UpdatePerformanceCounters()
|
||||
{
|
||||
const float frame_time = static_cast<float>(s_frame_timer.GetTimeMillisecondsAndReset());
|
||||
|
@ -2869,15 +2874,7 @@ void System::UpdateSpeedLimiterState()
|
|||
// Update audio output.
|
||||
AudioStream* stream = SPU::GetOutputStream();
|
||||
stream->SetOutputVolume(GetAudioOutputVolume());
|
||||
|
||||
// Adjust nominal rate when resampling, or syncing to host.
|
||||
const bool rate_adjust =
|
||||
(s_syncing_to_host || g_settings.audio_stream_parameters.stretch_mode == AudioStretchMode::Resample) &&
|
||||
s_target_speed > 0.0f;
|
||||
stream->SetNominalRate(rate_adjust ? s_target_speed : 1.0f);
|
||||
|
||||
if (old_target_speed < s_target_speed)
|
||||
stream->UpdateTargetTempo(s_target_speed);
|
||||
stream->SetNominalRate(GetAudioNominalRate());
|
||||
|
||||
UpdateThrottlePeriod();
|
||||
ResetThrottler();
|
||||
|
|
|
@ -285,6 +285,7 @@ void SingleStepCPU();
|
|||
|
||||
/// Sets target emulation speed.
|
||||
float GetTargetSpeed();
|
||||
float GetAudioNominalRate();
|
||||
|
||||
/// Adjusts the throttle frequency, i.e. how many times we should sleep per second.
|
||||
void SetThrottleFrequency(float frequency);
|
||||
|
|
|
@ -541,25 +541,8 @@ void AudioStream::SetNominalRate(float tempo)
|
|||
m_nominal_rate = tempo;
|
||||
if (m_parameters.stretch_mode == AudioStretchMode::Resample)
|
||||
m_soundtouch->setRate(tempo);
|
||||
}
|
||||
|
||||
void AudioStream::UpdateTargetTempo(float tempo)
|
||||
{
|
||||
if (m_parameters.stretch_mode != AudioStretchMode::TimeStretch)
|
||||
return;
|
||||
|
||||
// undo sqrt()
|
||||
if (tempo)
|
||||
tempo *= tempo;
|
||||
|
||||
m_average_position = AVERAGING_WINDOW;
|
||||
m_average_available = AVERAGING_WINDOW;
|
||||
std::fill_n(m_average_fullness.data(), AVERAGING_WINDOW, tempo);
|
||||
else if (m_parameters.stretch_mode == AudioStretchMode::TimeStretch && m_stretch_inactive)
|
||||
m_soundtouch->setTempo(tempo);
|
||||
m_stretch_reset = 0;
|
||||
m_stretch_inactive = false;
|
||||
m_stretch_ok_count = 0;
|
||||
m_dynamic_target_usage = static_cast<float>(m_target_buffer_size) * m_nominal_rate;
|
||||
}
|
||||
|
||||
void AudioStream::SetStretchMode(AudioStretchMode mode)
|
||||
|
|
|
@ -190,7 +190,6 @@ public:
|
|||
/// Nominal rate is used for both resampling and timestretching, input samples are assumed to be this amount faster
|
||||
/// than the sample rate.
|
||||
void SetNominalRate(float tempo);
|
||||
void UpdateTargetTempo(float tempo);
|
||||
|
||||
void SetStretchMode(AudioStretchMode mode);
|
||||
|
||||
|
|
Loading…
Reference in New Issue