Smooth out the DSP callback by adding a 5ms wait time limit

master
Kelebek1 2023-05-10 17:59:21 +07:00
parent f35c14fb73
commit d75bcdd077
4 changed files with 12 additions and 16 deletions

@ -154,6 +154,11 @@ void AudioRenderer::ThreadFunc() {
return; return;
case RenderMessage::AudioRenderer_Render: { case RenderMessage::AudioRenderer_Render: {
if (system.IsShuttingDown()) [[unlikely]] {
std::this_thread::sleep_for(std::chrono::milliseconds(5));
mailbox->ADSPSendMessage(RenderMessage::AudioRenderer_RenderResponse);
continue;
}
std::array<bool, MaxRendererSessions> buffers_reset{}; std::array<bool, MaxRendererSessions> buffers_reset{};
std::array<u64, MaxRendererSessions> render_times_taken{}; std::array<u64, MaxRendererSessions> render_times_taken{};
const auto start_time{system.CoreTiming().GetClockTicks()}; const auto start_time{system.CoreTiming().GetClockTicks()};

@ -27,7 +27,7 @@ bool SystemManager::InitializeUnsafe() {
if (!active) { if (!active) {
if (adsp.Start()) { if (adsp.Start()) {
active = true; active = true;
thread = std::jthread([this](std::stop_token stop_token) { ThreadFunc(); }); thread = std::jthread([this](std::stop_token stop_token) { ThreadFunc(stop_token); });
} }
} }
@ -39,8 +39,7 @@ void SystemManager::Stop() {
return; return;
} }
active = false; active = false;
update.store(true); thread.request_stop();
update.notify_all();
thread.join(); thread.join();
adsp.Stop(); adsp.Stop();
} }
@ -85,12 +84,12 @@ bool SystemManager::Remove(System& system_) {
return true; return true;
} }
void SystemManager::ThreadFunc() { void SystemManager::ThreadFunc(std::stop_token stop_token) {
static constexpr char name[]{"AudioRenderSystemManager"}; static constexpr char name[]{"AudioRenderSystemManager"};
MicroProfileOnThreadCreate(name); MicroProfileOnThreadCreate(name);
Common::SetCurrentThreadName(name); Common::SetCurrentThreadName(name);
Common::SetCurrentThreadPriority(Common::ThreadPriority::High); Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
while (active) { while (active && !stop_token.stop_requested()) {
{ {
std::scoped_lock l{mutex1}; std::scoped_lock l{mutex1};

@ -66,13 +66,7 @@ private:
/** /**
* Main thread responsible for command generation. * Main thread responsible for command generation.
*/ */
void ThreadFunc(); void ThreadFunc(std::stop_token stop_token);
enum class StreamState {
Filling,
Steady,
Draining,
};
/// Core system /// Core system
Core::System& core; Core::System& core;
@ -90,8 +84,6 @@ private:
ADSP::ADSP& adsp; ADSP::ADSP& adsp;
/// AudioRenderer mailbox for communication /// AudioRenderer mailbox for communication
ADSP::AudioRenderer_Mailbox* mailbox{}; ADSP::AudioRenderer_Mailbox* mailbox{};
/// Atomic for main thread to wait on
std::atomic<bool> update{};
}; };
} // namespace AudioCore::AudioRenderer } // namespace AudioCore::AudioRenderer

@ -271,8 +271,8 @@ u64 SinkStream::GetExpectedPlayedSampleCount() {
void SinkStream::WaitFreeSpace() { void SinkStream::WaitFreeSpace() {
std::unique_lock lk{release_mutex}; std::unique_lock lk{release_mutex};
release_cv.wait( release_cv.wait_for(lk, std::chrono::milliseconds(5),
lk, [this]() { return queued_buffers < max_queue_size || system.IsShuttingDown(); }); [this]() { return queued_buffers < max_queue_size; });
} }
} // namespace AudioCore::Sink } // namespace AudioCore::Sink