From ea5dd02db9bdb9759a400907672ec6606bebb96b Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sat, 18 Mar 2023 20:57:00 +0000 Subject: audio: Wait for samples on the emulated DSP side to avoid desyncs Waiting on the host side is inaccurate and leads to desyncs in the event of the sink missing a deadline that require stalls to fix. By waiting for the sink to have space before even starting rendering such desyncs can be avoided. --- src/audio_core/renderer/adsp/audio_renderer.cpp | 2 ++ src/audio_core/renderer/adsp/audio_renderer.h | 1 + 2 files changed, 3 insertions(+) (limited to 'src/audio_core/renderer/adsp') diff --git a/src/audio_core/renderer/adsp/audio_renderer.cpp b/src/audio_core/renderer/adsp/audio_renderer.cpp index 42b4b167a..503f40349 100644 --- a/src/audio_core/renderer/adsp/audio_renderer.cpp +++ b/src/audio_core/renderer/adsp/audio_renderer.cpp @@ -189,6 +189,8 @@ void AudioRenderer::ThreadFunc() { max_time = std::min(command_buffer.time_limit, max_time); command_list_processor.SetProcessTimeMax(max_time); + streams[index]->WaitFreeSpace(); + // Process the command list { MICROPROFILE_SCOPE(Audio_Renderer); diff --git a/src/audio_core/renderer/adsp/audio_renderer.h b/src/audio_core/renderer/adsp/audio_renderer.h index 151f38c1b..f97f9401e 100644 --- a/src/audio_core/renderer/adsp/audio_renderer.h +++ b/src/audio_core/renderer/adsp/audio_renderer.h @@ -12,6 +12,7 @@ #include "common/common_types.h" #include "common/reader_writer_queue.h" #include "common/thread.h" +#include "common/polyfill_thread.h" namespace Core { namespace Timing { -- cgit v1.2.3 From 237934b73690a56ff756d6e682fa336dee8c95a4 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sun, 26 Mar 2023 20:07:03 +0100 Subject: Run clang-format --- src/audio_core/renderer/adsp/audio_renderer.h | 2 +- src/audio_core/sink/sink_stream.cpp | 10 +++++----- src/audio_core/sink/sink_stream.h | 1 - 3 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src/audio_core/renderer/adsp') diff --git a/src/audio_core/renderer/adsp/audio_renderer.h b/src/audio_core/renderer/adsp/audio_renderer.h index f97f9401e..85ce6a269 100644 --- a/src/audio_core/renderer/adsp/audio_renderer.h +++ b/src/audio_core/renderer/adsp/audio_renderer.h @@ -10,9 +10,9 @@ #include "audio_core/renderer/adsp/command_buffer.h" #include "audio_core/renderer/adsp/command_list_processor.h" #include "common/common_types.h" +#include "common/polyfill_thread.h" #include "common/reader_writer_queue.h" #include "common/thread.h" -#include "common/polyfill_thread.h" namespace Core { namespace Timing { diff --git a/src/audio_core/sink/sink_stream.cpp b/src/audio_core/sink/sink_stream.cpp index a54c61845..084ac5edf 100644 --- a/src/audio_core/sink/sink_stream.cpp +++ b/src/audio_core/sink/sink_stream.cpp @@ -245,9 +245,7 @@ void SinkStream::ProcessAudioOutAndRender(std::span output_buffer, std::siz // Successfully dequeued a new buffer. queued_buffers--; - { - std::unique_lock lk{release_mutex}; - } + { std::unique_lock lk{release_mutex}; } release_cv.notify_one(); } @@ -276,7 +274,8 @@ void SinkStream::ProcessAudioOutAndRender(std::span output_buffer, std::siz { std::scoped_lock lk{sample_count_lock}; - last_sample_count_update_time = Core::Timing::CyclesToUs(system.CoreTiming().GetClockTicks()); + last_sample_count_update_time = + Core::Timing::CyclesToUs(system.CoreTiming().GetClockTicks()); min_played_sample_count = max_played_sample_count; max_played_sample_count += actual_frames_written; } @@ -315,7 +314,8 @@ u64 SinkStream::GetExpectedPlayedSampleCount() { void SinkStream::WaitFreeSpace() { std::unique_lock lk{release_mutex}; - release_cv.wait(lk, [this]() { return queued_buffers < max_queue_size || system.IsShuttingDown(); }); + release_cv.wait( + lk, [this]() { return queued_buffers < max_queue_size || system.IsShuttingDown(); }); } } // namespace AudioCore::Sink diff --git a/src/audio_core/sink/sink_stream.h b/src/audio_core/sink/sink_stream.h index 709f3b0ec..9806e6d98 100644 --- a/src/audio_core/sink/sink_stream.h +++ b/src/audio_core/sink/sink_stream.h @@ -16,7 +16,6 @@ #include "common/reader_writer_queue.h" #include "common/ring_buffer.h" #include "common/thread.h" -#include "common/polyfill_thread.h" namespace Core { class System; -- cgit v1.2.3