early-access version 3591
This commit is contained in:
@@ -188,6 +188,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);
|
||||
|
@@ -15,14 +15,9 @@ MICROPROFILE_DEFINE(Audio_RenderSystemManager, "Audio", "Render System Manager",
|
||||
MP_RGB(60, 19, 97));
|
||||
|
||||
namespace AudioCore::AudioRenderer {
|
||||
constexpr std::chrono::nanoseconds RENDER_TIME{5'000'000UL};
|
||||
|
||||
SystemManager::SystemManager(Core::System& core_)
|
||||
: core{core_}, adsp{core.AudioCore().GetADSP()}, mailbox{adsp.GetRenderMailbox()},
|
||||
thread_event{Core::Timing::CreateEvent(
|
||||
"AudioRendererSystemManager", [this](std::uintptr_t, s64 time, std::chrono::nanoseconds) {
|
||||
return ThreadFunc2(time);
|
||||
})} {}
|
||||
: core{core_}, adsp{core.AudioCore().GetADSP()}, mailbox{adsp.GetRenderMailbox()} {}
|
||||
|
||||
SystemManager::~SystemManager() {
|
||||
Stop();
|
||||
@@ -32,9 +27,7 @@ bool SystemManager::InitializeUnsafe() {
|
||||
if (!active) {
|
||||
if (adsp.Start()) {
|
||||
active = true;
|
||||
thread = std::jthread([this](std::stop_token stop_token) { ThreadFunc(stop_token); });
|
||||
core.CoreTiming().ScheduleLoopingEvent(std::chrono::nanoseconds(0), RENDER_TIME,
|
||||
thread_event);
|
||||
thread = std::jthread([this](std::stop_token stop_token) { ThreadFunc(); });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,13 +38,9 @@ void SystemManager::Stop() {
|
||||
if (!active) {
|
||||
return;
|
||||
}
|
||||
core.CoreTiming().UnscheduleEvent(thread_event, {});
|
||||
active = false;
|
||||
{
|
||||
std::scoped_lock l{cv_mutex};
|
||||
do_update = false;
|
||||
}
|
||||
thread.request_stop();
|
||||
update.store(true);
|
||||
update.notify_all();
|
||||
thread.join();
|
||||
adsp.Stop();
|
||||
}
|
||||
@@ -96,12 +85,12 @@ bool SystemManager::Remove(System& system_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void SystemManager::ThreadFunc(std::stop_token stop_token) {
|
||||
void SystemManager::ThreadFunc() {
|
||||
static constexpr char name[]{"AudioRenderSystemManager"};
|
||||
MicroProfileOnThreadCreate(name);
|
||||
Common::SetCurrentThreadName(name);
|
||||
Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
|
||||
while (active && !stop_token.stop_requested()) {
|
||||
while (active) {
|
||||
{
|
||||
std::scoped_lock l{mutex1};
|
||||
|
||||
@@ -114,20 +103,7 @@ void SystemManager::ThreadFunc(std::stop_token stop_token) {
|
||||
|
||||
adsp.Signal();
|
||||
adsp.Wait();
|
||||
|
||||
std::unique_lock l{cv_mutex};
|
||||
Common::CondvarWait(update_cv, l, stop_token, [this]() { return do_update; });
|
||||
do_update = false;
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<std::chrono::nanoseconds> SystemManager::ThreadFunc2(s64 time) {
|
||||
{
|
||||
std::scoped_lock l{cv_mutex};
|
||||
do_update = true;
|
||||
}
|
||||
update_cv.notify_all();
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
} // namespace AudioCore::AudioRenderer
|
||||
|
@@ -66,12 +66,13 @@ private:
|
||||
/**
|
||||
* Main thread responsible for command generation.
|
||||
*/
|
||||
void ThreadFunc(std::stop_token stop_token);
|
||||
void ThreadFunc();
|
||||
|
||||
/**
|
||||
* Signalling core timing thread to run ThreadFunc.
|
||||
*/
|
||||
std::optional<std::chrono::nanoseconds> ThreadFunc2(s64 time);
|
||||
enum class StreamState {
|
||||
Filling,
|
||||
Steady,
|
||||
Draining,
|
||||
};
|
||||
|
||||
/// Core system
|
||||
Core::System& core;
|
||||
@@ -89,12 +90,8 @@ private:
|
||||
ADSP::ADSP& adsp;
|
||||
/// AudioRenderer mailbox for communication
|
||||
ADSP::AudioRenderer_Mailbox* mailbox{};
|
||||
/// Core timing event to signal main thread
|
||||
std::shared_ptr<Core::Timing::EventType> thread_event;
|
||||
/// Atomic for main thread to wait on
|
||||
std::mutex cv_mutex{};
|
||||
bool do_update{};
|
||||
std::condition_variable_any update_cv{};
|
||||
std::atomic<bool> update{};
|
||||
};
|
||||
|
||||
} // namespace AudioCore::AudioRenderer
|
||||
|
@@ -268,4 +268,10 @@ u64 SinkStream::GetExpectedPlayedSampleCount() {
|
||||
return std::min<u64>(exp_played_sample_count, max_played_sample_count) + TargetSampleCount * 3;
|
||||
}
|
||||
|
||||
void SinkStream::WaitFreeSpace() {
|
||||
std::unique_lock lk{release_mutex};
|
||||
release_cv.wait(
|
||||
lk, [this]() { return queued_buffers < max_queue_size || system.IsShuttingDown(); });
|
||||
}
|
||||
|
||||
} // namespace AudioCore::Sink
|
||||
|
@@ -207,6 +207,11 @@ public:
|
||||
*/
|
||||
u64 GetExpectedPlayedSampleCount();
|
||||
|
||||
/**
|
||||
* Waits for free space in the sample ring buffer
|
||||
*/
|
||||
void WaitFreeSpace();
|
||||
|
||||
protected:
|
||||
/// Core system
|
||||
Core::System& system;
|
||||
|
Reference in New Issue
Block a user