Merge pull request #10027 from bylaws/master
Add some explicit latency to sample count reporting
This commit is contained in:
commit
4f77275cd5
2 changed files with 5 additions and 5 deletions
|
@ -252,8 +252,7 @@ void SinkStream::ProcessAudioOutAndRender(std::span<s16> output_buffer, std::siz
|
||||||
|
|
||||||
{
|
{
|
||||||
std::scoped_lock lk{sample_count_lock};
|
std::scoped_lock lk{sample_count_lock};
|
||||||
last_sample_count_update_time =
|
last_sample_count_update_time = system.CoreTiming().GetGlobalTimeNs();
|
||||||
Core::Timing::CyclesToUs(system.CoreTiming().GetClockTicks());
|
|
||||||
min_played_sample_count = max_played_sample_count;
|
min_played_sample_count = max_played_sample_count;
|
||||||
max_played_sample_count += actual_frames_written;
|
max_played_sample_count += actual_frames_written;
|
||||||
}
|
}
|
||||||
|
@ -261,12 +260,13 @@ void SinkStream::ProcessAudioOutAndRender(std::span<s16> output_buffer, std::siz
|
||||||
|
|
||||||
u64 SinkStream::GetExpectedPlayedSampleCount() {
|
u64 SinkStream::GetExpectedPlayedSampleCount() {
|
||||||
std::scoped_lock lk{sample_count_lock};
|
std::scoped_lock lk{sample_count_lock};
|
||||||
auto cur_time{Core::Timing::CyclesToUs(system.CoreTiming().GetClockTicks())};
|
auto cur_time{system.CoreTiming().GetGlobalTimeNs()};
|
||||||
auto time_delta{cur_time - last_sample_count_update_time};
|
auto time_delta{cur_time - last_sample_count_update_time};
|
||||||
auto exp_played_sample_count{min_played_sample_count +
|
auto exp_played_sample_count{min_played_sample_count +
|
||||||
(TargetSampleRate * time_delta) / std::chrono::seconds{1}};
|
(TargetSampleRate * time_delta) / std::chrono::seconds{1}};
|
||||||
|
|
||||||
return std::min<u64>(exp_played_sample_count, max_played_sample_count);
|
// Add 15ms of latency in sample reporting to allow for some leeway in scheduler timings
|
||||||
|
return std::min<u64>(exp_played_sample_count, max_played_sample_count) + TargetSampleCount * 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SinkStream::WaitFreeSpace() {
|
void SinkStream::WaitFreeSpace() {
|
||||||
|
|
|
@ -246,7 +246,7 @@ private:
|
||||||
/// Maximum number of total samples that can be played since the last callback
|
/// Maximum number of total samples that can be played since the last callback
|
||||||
u64 max_played_sample_count{};
|
u64 max_played_sample_count{};
|
||||||
/// The time the two above tracking variables were last written to
|
/// The time the two above tracking variables were last written to
|
||||||
std::chrono::microseconds last_sample_count_update_time{};
|
std::chrono::nanoseconds last_sample_count_update_time{};
|
||||||
/// Set by the audio render/in/out system which uses this stream
|
/// Set by the audio render/in/out system which uses this stream
|
||||||
f32 system_volume{1.0f};
|
f32 system_volume{1.0f};
|
||||||
/// Set via IAudioDevice service calls
|
/// Set via IAudioDevice service calls
|
||||||
|
|
Loading…
Reference in a new issue