early-access version 2824
This commit is contained in:
@@ -15,12 +15,17 @@ MICROPROFILE_DEFINE(Audio_RenderSystemManager, "Audio", "Render System Manager",
|
||||
MP_RGB(60, 19, 97));
|
||||
|
||||
namespace AudioCore::AudioRenderer {
|
||||
constexpr std::chrono::nanoseconds BaseRenderTime{5'000'000UL};
|
||||
constexpr std::chrono::nanoseconds RenderTimeOffset{400'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 userdata, std::chrono::nanoseconds ns_late) { ThreadFunc2(); })} {}
|
||||
"AudioRendererSystemManager", [this](std::uintptr_t, s64 time, std::chrono::nanoseconds) {
|
||||
return ThreadFunc2(time);
|
||||
})} {
|
||||
core.CoreTiming().RegisterPauseCallback([this](bool paused) { PauseCallback(paused); });
|
||||
}
|
||||
|
||||
SystemManager::~SystemManager() {
|
||||
Stop();
|
||||
@@ -30,9 +35,9 @@ bool SystemManager::InitializeUnsafe() {
|
||||
if (!active) {
|
||||
if (adsp.Start()) {
|
||||
active = true;
|
||||
core.CoreTiming().ScheduleLoopingEvent(std::chrono::nanoseconds(2'304'000ULL * 2),
|
||||
thread_event);
|
||||
thread = std::jthread([this](std::stop_token stop_token) { ThreadFunc(); });
|
||||
core.CoreTiming().ScheduleLoopingEvent(std::chrono::nanoseconds(0),
|
||||
BaseRenderTime - RenderTimeOffset, thread_event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,11 +100,13 @@ void SystemManager::ThreadFunc() {
|
||||
constexpr char name[]{"yuzu:AudioRenderSystemManager"};
|
||||
MicroProfileOnThreadCreate(name);
|
||||
Common::SetCurrentThreadName(name);
|
||||
Common::SetCurrentThreadPriority(Common::ThreadPriority::Critical);
|
||||
Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
|
||||
while (active) {
|
||||
{
|
||||
std::scoped_lock l{mutex1};
|
||||
|
||||
MICROPROFILE_SCOPE(Audio_RenderSystemManager);
|
||||
|
||||
for (auto system : systems) {
|
||||
system->SendCommandToDsp();
|
||||
}
|
||||
@@ -113,9 +120,43 @@ void SystemManager::ThreadFunc() {
|
||||
}
|
||||
}
|
||||
|
||||
void SystemManager::ThreadFunc2() {
|
||||
std::optional<std::chrono::nanoseconds> SystemManager::ThreadFunc2(s64 time) {
|
||||
std::optional<std::chrono::nanoseconds> new_schedule_time{std::nullopt};
|
||||
const auto queue_size{core.AudioCore().GetStreamQueue()};
|
||||
switch (state) {
|
||||
case StreamState::Filling:
|
||||
if (queue_size >= 5) {
|
||||
new_schedule_time = BaseRenderTime;
|
||||
state = StreamState::Steady;
|
||||
}
|
||||
break;
|
||||
case StreamState::Steady:
|
||||
if (queue_size <= 2) {
|
||||
new_schedule_time = BaseRenderTime - RenderTimeOffset;
|
||||
state = StreamState::Filling;
|
||||
} else if (queue_size > 5) {
|
||||
new_schedule_time = BaseRenderTime + RenderTimeOffset;
|
||||
state = StreamState::Draining;
|
||||
}
|
||||
break;
|
||||
case StreamState::Draining:
|
||||
if (queue_size <= 5) {
|
||||
new_schedule_time = BaseRenderTime;
|
||||
state = StreamState::Steady;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
update.store(true);
|
||||
update.notify_all();
|
||||
return new_schedule_time;
|
||||
}
|
||||
|
||||
void SystemManager::PauseCallback(bool paused) {
|
||||
if (paused && core.IsPoweredOn() && core.IsShuttingDown()) {
|
||||
update.store(true);
|
||||
update.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace AudioCore::AudioRenderer
|
||||
|
||||
Reference in New Issue
Block a user