Rework ADSP into a wrapper for apps
This commit is contained in:
parent
5ce41fa213
commit
ebd19dec99
173 changed files with 1051 additions and 1257 deletions
|
|
@ -2,6 +2,14 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
add_library(audio_core STATIC
|
||||
adsp/adsp.cpp
|
||||
adsp/adsp.h
|
||||
adsp/mailbox.h
|
||||
adsp/apps/audio_renderer/audio_renderer.cpp
|
||||
adsp/apps/audio_renderer/audio_renderer.h
|
||||
adsp/apps/audio_renderer/command_buffer.h
|
||||
adsp/apps/audio_renderer/command_list_processor.cpp
|
||||
adsp/apps/audio_renderer/command_list_processor.h
|
||||
audio_core.cpp
|
||||
audio_core.h
|
||||
audio_event.h
|
||||
|
|
@ -32,13 +40,6 @@ add_library(audio_core STATIC
|
|||
out/audio_out_system.cpp
|
||||
out/audio_out_system.h
|
||||
precompiled_headers.h
|
||||
renderer/adsp/adsp.cpp
|
||||
renderer/adsp/adsp.h
|
||||
renderer/adsp/audio_renderer.cpp
|
||||
renderer/adsp/audio_renderer.h
|
||||
renderer/adsp/command_buffer.h
|
||||
renderer/adsp/command_list_processor.cpp
|
||||
renderer/adsp/command_list_processor.h
|
||||
renderer/audio_device.cpp
|
||||
renderer/audio_device.h
|
||||
renderer/audio_renderer.h
|
||||
|
|
|
|||
18
src/audio_core/adsp/adsp.cpp
Normal file
18
src/audio_core/adsp/adsp.cpp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "audio_core/adsp/adsp.h"
|
||||
#include "core/core.h"
|
||||
|
||||
namespace AudioCore::ADSP {
|
||||
|
||||
ADSP::ADSP(Core::System& system, Sink::Sink& sink) {
|
||||
audio_renderer =
|
||||
std::make_unique<AudioRenderer::AudioRenderer>(system, system.ApplicationMemory(), sink);
|
||||
}
|
||||
|
||||
AudioRenderer::AudioRenderer& ADSP::AudioRenderer() {
|
||||
return *audio_renderer.get();
|
||||
}
|
||||
|
||||
} // namespace AudioCore::ADSP
|
||||
50
src/audio_core/adsp/adsp.h
Normal file
50
src/audio_core/adsp/adsp.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "audio_core/adsp/apps/audio_renderer/audio_renderer.h"
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
} // namespace Core
|
||||
|
||||
namespace AudioCore {
|
||||
namespace Sink {
|
||||
class Sink;
|
||||
}
|
||||
|
||||
namespace ADSP {
|
||||
|
||||
/**
|
||||
* Represents the ADSP embedded within the audio sysmodule.
|
||||
* This is a 32-bit Linux4Tegra kernel from nVidia, which is launched with the sysmodule on boot.
|
||||
*
|
||||
* The kernel will run the apps you write for it, Nintendo have the following:
|
||||
*
|
||||
* Gmix - Responsible for mixing final audio and sending it out to hardware. This is last place all
|
||||
* audio samples end up, and we skip it entirely, since we have very different backends and
|
||||
* mixing is implicitly handled by the OS (but also due to lack of research/simplicity).
|
||||
*
|
||||
* AudioRenderer - Receives command lists generated by the audio render
|
||||
* system on the host, processes them, and sends the samples to Gmix.
|
||||
*
|
||||
* OpusDecoder - Contains libopus, and decodes Opus audio packets into raw pcm data.
|
||||
*
|
||||
* Communication between the host and ADSP is done through mailboxes, and mapping of shared memory.
|
||||
*/
|
||||
class ADSP {
|
||||
public:
|
||||
explicit ADSP(Core::System& system, Sink::Sink& sink);
|
||||
~ADSP() = default;
|
||||
|
||||
AudioRenderer::AudioRenderer& AudioRenderer();
|
||||
|
||||
private:
|
||||
/// AudioRenderer app
|
||||
std::unique_ptr<AudioRenderer::AudioRenderer> audio_renderer{};
|
||||
};
|
||||
|
||||
} // namespace ADSP
|
||||
} // namespace AudioCore
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
|
||||
#include "audio_core/adsp/apps/audio_renderer/audio_renderer.h"
|
||||
#include "audio_core/audio_core.h"
|
||||
#include "audio_core/common/common.h"
|
||||
#include "audio_core/renderer/adsp/audio_renderer.h"
|
||||
#include "audio_core/sink/sink.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/microprofile.h"
|
||||
|
|
@ -16,95 +16,29 @@
|
|||
|
||||
MICROPROFILE_DEFINE(Audio_Renderer, "Audio", "DSP", MP_RGB(60, 19, 97));
|
||||
|
||||
namespace AudioCore::AudioRenderer::ADSP {
|
||||
namespace AudioCore::ADSP::AudioRenderer {
|
||||
|
||||
void AudioRenderer_Mailbox::HostSendMessage(RenderMessage message_) {
|
||||
adsp_messages.enqueue(message_);
|
||||
adsp_event.Set();
|
||||
}
|
||||
|
||||
RenderMessage AudioRenderer_Mailbox::HostWaitMessage() {
|
||||
host_event.Wait();
|
||||
RenderMessage msg{RenderMessage::Invalid};
|
||||
if (!host_messages.try_dequeue(msg)) {
|
||||
LOG_ERROR(Service_Audio, "Failed to dequeue host message!");
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
void AudioRenderer_Mailbox::ADSPSendMessage(const RenderMessage message_) {
|
||||
host_messages.enqueue(message_);
|
||||
host_event.Set();
|
||||
}
|
||||
|
||||
RenderMessage AudioRenderer_Mailbox::ADSPWaitMessage() {
|
||||
adsp_event.Wait();
|
||||
RenderMessage msg{RenderMessage::Invalid};
|
||||
if (!adsp_messages.try_dequeue(msg)) {
|
||||
LOG_ERROR(Service_Audio, "Failed to dequeue ADSP message!");
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
CommandBuffer& AudioRenderer_Mailbox::GetCommandBuffer(const u32 session_id) {
|
||||
return command_buffers[session_id];
|
||||
}
|
||||
|
||||
void AudioRenderer_Mailbox::SetCommandBuffer(const u32 session_id, const CommandBuffer& buffer) {
|
||||
command_buffers[session_id] = buffer;
|
||||
}
|
||||
|
||||
u64 AudioRenderer_Mailbox::GetRenderTimeTaken() const {
|
||||
return command_buffers[0].render_time_taken + command_buffers[1].render_time_taken;
|
||||
}
|
||||
|
||||
u64 AudioRenderer_Mailbox::GetSignalledTick() const {
|
||||
return signalled_tick;
|
||||
}
|
||||
|
||||
void AudioRenderer_Mailbox::SetSignalledTick(const u64 tick) {
|
||||
signalled_tick = tick;
|
||||
}
|
||||
|
||||
void AudioRenderer_Mailbox::ClearRemainCount(const u32 session_id) {
|
||||
command_buffers[session_id].remaining_command_count = 0;
|
||||
}
|
||||
|
||||
u32 AudioRenderer_Mailbox::GetRemainCommandCount(const u32 session_id) const {
|
||||
return command_buffers[session_id].remaining_command_count;
|
||||
}
|
||||
|
||||
void AudioRenderer_Mailbox::ClearCommandBuffers() {
|
||||
command_buffers[0].buffer = 0;
|
||||
command_buffers[0].size = 0;
|
||||
command_buffers[0].reset_buffers = false;
|
||||
command_buffers[1].buffer = 0;
|
||||
command_buffers[1].size = 0;
|
||||
command_buffers[1].reset_buffers = false;
|
||||
}
|
||||
|
||||
AudioRenderer::AudioRenderer(Core::System& system_)
|
||||
: system{system_}, sink{system.AudioCore().GetOutputSink()} {
|
||||
CreateSinkStreams();
|
||||
}
|
||||
AudioRenderer::AudioRenderer(Core::System& system_, Core::Memory::Memory& memory_,
|
||||
Sink::Sink& sink_)
|
||||
: system{system_}, memory{memory_}, sink{sink_} {}
|
||||
|
||||
AudioRenderer::~AudioRenderer() {
|
||||
Stop();
|
||||
for (auto& stream : streams) {
|
||||
if (stream) {
|
||||
sink.CloseStream(stream);
|
||||
}
|
||||
stream = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioRenderer::Start(AudioRenderer_Mailbox* mailbox_) {
|
||||
if (running) {
|
||||
void AudioRenderer::Start() {
|
||||
CreateSinkStreams();
|
||||
|
||||
mailbox.Initialize(AppMailboxId::AudioRenderer);
|
||||
|
||||
main_thread = std::jthread([this](std::stop_token stop_token) { Main(stop_token); });
|
||||
|
||||
mailbox.Send(Direction::DSP, {Message::InitializeOK, {}});
|
||||
if (mailbox.Receive(Direction::Host).msg != Message::InitializeOK) {
|
||||
LOG_ERROR(Service_Audio, "Host Audio Renderer -- Failed to receive shutdown "
|
||||
"message response from ADSP!");
|
||||
return;
|
||||
}
|
||||
|
||||
mailbox = mailbox_;
|
||||
thread = std::jthread([this](std::stop_token stop_token) { ThreadFunc(stop_token); });
|
||||
running = true;
|
||||
}
|
||||
|
||||
|
|
@ -113,13 +47,63 @@ void AudioRenderer::Stop() {
|
|||
return;
|
||||
}
|
||||
|
||||
for (auto& stream : streams) {
|
||||
stream->Stop();
|
||||
mailbox.Send(Direction::DSP, {Message::Shutdown, {}});
|
||||
if (mailbox.Receive(Direction::Host).msg != Message::Shutdown) {
|
||||
LOG_ERROR(Service_Audio, "Host Audio Renderer -- Failed to receive shutdown "
|
||||
"message response from ADSP!");
|
||||
}
|
||||
main_thread.request_stop();
|
||||
main_thread.join();
|
||||
|
||||
for (auto& stream : streams) {
|
||||
if (stream) {
|
||||
stream->Stop();
|
||||
sink.CloseStream(stream);
|
||||
stream = nullptr;
|
||||
}
|
||||
}
|
||||
thread.join();
|
||||
running = false;
|
||||
}
|
||||
|
||||
void AudioRenderer::Signal() {
|
||||
signalled_tick = system.CoreTiming().GetGlobalTimeNs().count();
|
||||
Send(Direction::DSP, {Message::Render, {}});
|
||||
}
|
||||
|
||||
void AudioRenderer::Wait() {
|
||||
auto received = Receive(Direction::Host);
|
||||
if (received.msg != Message::RenderResponse) {
|
||||
LOG_ERROR(Service_Audio,
|
||||
"Did not receive the expected render response from the AudioRenderer! Expected "
|
||||
"{}, got {}",
|
||||
Message::RenderResponse, received.msg);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioRenderer::Send(Direction dir, MailboxMessage message) {
|
||||
mailbox.Send(dir, std::move(message));
|
||||
}
|
||||
|
||||
MailboxMessage AudioRenderer::Receive(Direction dir, bool block) {
|
||||
return mailbox.Receive(dir, block);
|
||||
}
|
||||
|
||||
void AudioRenderer::SetCommandBuffer(s32 session_id, CommandBuffer& buffer) noexcept {
|
||||
command_buffers[session_id] = buffer;
|
||||
}
|
||||
|
||||
u32 AudioRenderer::GetRemainCommandCount(s32 session_id) const noexcept {
|
||||
return command_buffers[session_id].remaining_command_count;
|
||||
}
|
||||
|
||||
void AudioRenderer::ClearRemainCommandCount(s32 session_id) noexcept {
|
||||
command_buffers[session_id].remaining_command_count = 0;
|
||||
}
|
||||
|
||||
u64 AudioRenderer::GetRenderingStartTick(s32 session_id) const noexcept {
|
||||
return (1000 * command_buffers[session_id].render_time_taken_us) + signalled_tick;
|
||||
}
|
||||
|
||||
void AudioRenderer::CreateSinkStreams() {
|
||||
u32 channels{sink.GetDeviceChannels()};
|
||||
for (u32 i = 0; i < MaxRendererSessions; i++) {
|
||||
|
|
@ -130,41 +114,45 @@ void AudioRenderer::CreateSinkStreams() {
|
|||
}
|
||||
}
|
||||
|
||||
void AudioRenderer::ThreadFunc(std::stop_token stop_token) {
|
||||
void AudioRenderer::Main(std::stop_token stop_token) {
|
||||
static constexpr char name[]{"AudioRenderer"};
|
||||
MicroProfileOnThreadCreate(name);
|
||||
Common::SetCurrentThreadName(name);
|
||||
Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
|
||||
if (mailbox->ADSPWaitMessage() != RenderMessage::AudioRenderer_InitializeOK) {
|
||||
|
||||
// TODO: Create buffer map/unmap thread + mailbox
|
||||
// TODO: Create gMix devices, initialize them here
|
||||
|
||||
if (mailbox.Receive(Direction::DSP).msg != Message::InitializeOK) {
|
||||
LOG_ERROR(Service_Audio,
|
||||
"ADSP Audio Renderer -- Failed to receive initialize message from host!");
|
||||
return;
|
||||
}
|
||||
|
||||
mailbox->ADSPSendMessage(RenderMessage::AudioRenderer_InitializeOK);
|
||||
mailbox.Send(Direction::Host, {Message::InitializeOK, {}});
|
||||
|
||||
// 0.12 seconds (2304000 / 19200000)
|
||||
// 0.12 seconds (2,304,000 / 19,200,000)
|
||||
constexpr u64 max_process_time{2'304'000ULL};
|
||||
|
||||
while (!stop_token.stop_requested()) {
|
||||
auto message{mailbox->ADSPWaitMessage()};
|
||||
switch (message) {
|
||||
case RenderMessage::AudioRenderer_Shutdown:
|
||||
mailbox->ADSPSendMessage(RenderMessage::AudioRenderer_Shutdown);
|
||||
auto received{mailbox.Receive(Direction::DSP)};
|
||||
switch (received.msg) {
|
||||
case Message::Shutdown:
|
||||
mailbox.Send(Direction::Host, {Message::Shutdown, {}});
|
||||
return;
|
||||
|
||||
case RenderMessage::AudioRenderer_Render: {
|
||||
case Message::Render: {
|
||||
if (system.IsShuttingDown()) [[unlikely]] {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||
mailbox->ADSPSendMessage(RenderMessage::AudioRenderer_RenderResponse);
|
||||
mailbox.Send(Direction::Host, {Message::RenderResponse, {}});
|
||||
continue;
|
||||
}
|
||||
std::array<bool, MaxRendererSessions> buffers_reset{};
|
||||
std::array<u64, MaxRendererSessions> render_times_taken{};
|
||||
const auto start_time{system.CoreTiming().GetClockTicks()};
|
||||
const auto start_time{system.CoreTiming().GetGlobalTimeUs().count()};
|
||||
|
||||
for (u32 index = 0; index < 2; index++) {
|
||||
auto& command_buffer{mailbox->GetCommandBuffer(index)};
|
||||
for (u32 index = 0; index < MaxRendererSessions; index++) {
|
||||
auto& command_buffer{command_buffers[index]};
|
||||
auto& command_list_processor{command_list_processors[index]};
|
||||
|
||||
// Check this buffer is valid, as it may not be used.
|
||||
|
|
@ -176,14 +164,14 @@ void AudioRenderer::ThreadFunc(std::stop_token stop_token) {
|
|||
command_buffer.size, streams[index]);
|
||||
}
|
||||
|
||||
if (command_buffer.reset_buffers && !buffers_reset[index]) {
|
||||
if (command_buffer.reset_buffer && !buffers_reset[index]) {
|
||||
streams[index]->ClearQueue();
|
||||
buffers_reset[index] = true;
|
||||
}
|
||||
|
||||
u64 max_time{max_process_time};
|
||||
if (index == 1 && command_buffer.applet_resource_user_id ==
|
||||
mailbox->GetCommandBuffer(0).applet_resource_user_id) {
|
||||
command_buffers[0].applet_resource_user_id) {
|
||||
max_time = max_process_time - render_times_taken[0];
|
||||
if (render_times_taken[0] > max_process_time) {
|
||||
max_time = 0;
|
||||
|
|
@ -193,7 +181,9 @@ void AudioRenderer::ThreadFunc(std::stop_token stop_token) {
|
|||
max_time = std::min(command_buffer.time_limit, max_time);
|
||||
command_list_processor.SetProcessTimeMax(max_time);
|
||||
|
||||
streams[index]->WaitFreeSpace(stop_token);
|
||||
if (index == 0) {
|
||||
streams[index]->WaitFreeSpace(stop_token);
|
||||
}
|
||||
|
||||
// Process the command list
|
||||
{
|
||||
|
|
@ -202,24 +192,24 @@ void AudioRenderer::ThreadFunc(std::stop_token stop_token) {
|
|||
command_list_processor.Process(index) - start_time;
|
||||
}
|
||||
|
||||
const auto end_time{system.CoreTiming().GetClockTicks()};
|
||||
const auto end_time{system.CoreTiming().GetGlobalTimeUs().count()};
|
||||
|
||||
command_buffer.remaining_command_count =
|
||||
command_list_processor.GetRemainingCommandCount();
|
||||
command_buffer.render_time_taken = end_time - start_time;
|
||||
command_buffer.render_time_taken_us = end_time - start_time;
|
||||
}
|
||||
}
|
||||
|
||||
mailbox->ADSPSendMessage(RenderMessage::AudioRenderer_RenderResponse);
|
||||
mailbox.Send(Direction::Host, {Message::RenderResponse, {}});
|
||||
} break;
|
||||
|
||||
default:
|
||||
LOG_WARNING(Service_Audio,
|
||||
"ADSP AudioRenderer received an invalid message, msg={:02X}!",
|
||||
static_cast<u32>(message));
|
||||
received.msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace AudioCore::AudioRenderer::ADSP
|
||||
} // namespace AudioCore::ADSP::AudioRenderer
|
||||
115
src/audio_core/adsp/apps/audio_renderer/audio_renderer.h
Normal file
115
src/audio_core/adsp/apps/audio_renderer/audio_renderer.h
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
||||
#include "audio_core/adsp/apps/audio_renderer/command_buffer.h"
|
||||
#include "audio_core/adsp/apps/audio_renderer/command_list_processor.h"
|
||||
#include "audio_core/adsp/mailbox.h"
|
||||
#include "common/common_types.h"
|
||||
#include "common/polyfill_thread.h"
|
||||
#include "common/reader_writer_queue.h"
|
||||
#include "common/thread.h"
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
namespace Timing {
|
||||
struct EventType;
|
||||
}
|
||||
namespace Memory {
|
||||
class Memory;
|
||||
}
|
||||
class System;
|
||||
} // namespace Core
|
||||
|
||||
namespace AudioCore {
|
||||
namespace Sink {
|
||||
class Sink;
|
||||
}
|
||||
|
||||
namespace ADSP::AudioRenderer {
|
||||
|
||||
enum Message : u32 {
|
||||
Invalid = 0x00,
|
||||
MapUnmap_Map = 0x01,
|
||||
MapUnmap_MapResponse = 0x02,
|
||||
MapUnmap_Unmap = 0x03,
|
||||
MapUnmap_UnmapResponse = 0x04,
|
||||
MapUnmap_InvalidateCache = 0x05,
|
||||
MapUnmap_InvalidateCacheResponse = 0x06,
|
||||
MapUnmap_Shutdown = 0x07,
|
||||
MapUnmap_ShutdownResponse = 0x08,
|
||||
InitializeOK = 0x16,
|
||||
RenderResponse = 0x20,
|
||||
Render = 0x2A,
|
||||
Shutdown = 0x34,
|
||||
};
|
||||
|
||||
/**
|
||||
* The AudioRenderer application running on the ADSP.
|
||||
*/
|
||||
class AudioRenderer {
|
||||
public:
|
||||
explicit AudioRenderer(Core::System& system, Core::Memory::Memory& memory, Sink::Sink& sink);
|
||||
~AudioRenderer();
|
||||
|
||||
/**
|
||||
* Start the AudioRenderer.
|
||||
*
|
||||
* @param mailbox The mailbox to use for this session.
|
||||
*/
|
||||
void Start();
|
||||
|
||||
/**
|
||||
* Stop the AudioRenderer.
|
||||
*/
|
||||
void Stop();
|
||||
|
||||
void Signal();
|
||||
void Wait();
|
||||
|
||||
void Send(Direction dir, MailboxMessage message);
|
||||
MailboxMessage Receive(Direction dir, bool block = true);
|
||||
|
||||
void SetCommandBuffer(s32 session_id, CommandBuffer& buffer) noexcept;
|
||||
u32 GetRemainCommandCount(s32 session_id) const noexcept;
|
||||
void ClearRemainCommandCount(s32 session_id) noexcept;
|
||||
u64 GetRenderingStartTick(s32 session_id) const noexcept;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Main AudioRenderer thread, responsible for processing the command lists.
|
||||
*/
|
||||
void Main(std::stop_token stop_token);
|
||||
|
||||
/**
|
||||
* Creates the streams which will receive the processed samples.
|
||||
*/
|
||||
void CreateSinkStreams();
|
||||
|
||||
/// Core system
|
||||
Core::System& system;
|
||||
/// Memory
|
||||
Core::Memory::Memory& memory;
|
||||
/// The output sink the AudioRenderer will use
|
||||
Sink::Sink& sink;
|
||||
/// The active mailbox
|
||||
Mailbox mailbox;
|
||||
/// Main thread
|
||||
std::jthread main_thread{};
|
||||
/// The current state
|
||||
std::atomic<bool> running{};
|
||||
std::array<CommandBuffer, MaxRendererSessions> command_buffers{};
|
||||
/// The command lists to process
|
||||
std::array<CommandListProcessor, MaxRendererSessions> command_list_processors{};
|
||||
/// The streams which will receive the processed samples
|
||||
std::array<Sink::SinkStream*, MaxRendererSessions> streams{};
|
||||
u64 signalled_tick{0};
|
||||
};
|
||||
|
||||
} // namespace ADSP::AudioRenderer
|
||||
} // namespace AudioCore
|
||||
23
src/audio_core/adsp/apps/audio_renderer/command_buffer.h
Normal file
23
src/audio_core/adsp/apps/audio_renderer/command_buffer.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "audio_core/common/common.h"
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace AudioCore::ADSP::AudioRenderer {
|
||||
|
||||
struct CommandBuffer {
|
||||
// Set by the host
|
||||
CpuAddr buffer{};
|
||||
u64 size{};
|
||||
u64 time_limit{};
|
||||
u64 applet_resource_user_id{};
|
||||
bool reset_buffer{};
|
||||
// Set by the DSP
|
||||
u32 remaining_command_count{};
|
||||
u64 render_time_taken_us{};
|
||||
};
|
||||
|
||||
} // namespace AudioCore::ADSP::AudioRenderer
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "audio_core/renderer/adsp/command_list_processor.h"
|
||||
#include "audio_core/adsp/apps/audio_renderer/command_list_processor.h"
|
||||
#include "audio_core/renderer/command/command_list_header.h"
|
||||
#include "audio_core/renderer/command/commands.h"
|
||||
#include "common/settings.h"
|
||||
|
|
@ -11,15 +11,15 @@
|
|||
#include "core/core_timing.h"
|
||||
#include "core/memory.h"
|
||||
|
||||
namespace AudioCore::AudioRenderer::ADSP {
|
||||
namespace AudioCore::ADSP::AudioRenderer {
|
||||
|
||||
void CommandListProcessor::Initialize(Core::System& system_, CpuAddr buffer, u64 size,
|
||||
Sink::SinkStream* stream_) {
|
||||
system = &system_;
|
||||
memory = &system->ApplicationMemory();
|
||||
stream = stream_;
|
||||
header = reinterpret_cast<CommandListHeader*>(buffer);
|
||||
commands = reinterpret_cast<u8*>(buffer + sizeof(CommandListHeader));
|
||||
header = reinterpret_cast<Renderer::CommandListHeader*>(buffer);
|
||||
commands = reinterpret_cast<u8*>(buffer + sizeof(Renderer::CommandListHeader));
|
||||
commands_buffer_size = size;
|
||||
command_count = header->command_count;
|
||||
sample_count = header->sample_count;
|
||||
|
|
@ -38,7 +38,7 @@ u32 CommandListProcessor::GetRemainingCommandCount() const {
|
|||
}
|
||||
|
||||
void CommandListProcessor::SetBuffer(const CpuAddr buffer, const u64 size) {
|
||||
commands = reinterpret_cast<u8*>(buffer + sizeof(CommandListHeader));
|
||||
commands = reinterpret_cast<u8*>(buffer + sizeof(Renderer::CommandListHeader));
|
||||
commands_buffer_size = size;
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ Sink::SinkStream* CommandListProcessor::GetOutputSinkStream() const {
|
|||
}
|
||||
|
||||
u64 CommandListProcessor::Process(u32 session_id) {
|
||||
const auto start_time_{system->CoreTiming().GetClockTicks()};
|
||||
const auto start_time_{system->CoreTiming().GetGlobalTimeUs().count()};
|
||||
const auto command_base{CpuAddr(commands)};
|
||||
|
||||
if (processed_command_count > 0) {
|
||||
|
|
@ -60,12 +60,12 @@ u64 CommandListProcessor::Process(u32 session_id) {
|
|||
std::string dump{fmt::format("\nSession {}\n", session_id)};
|
||||
|
||||
for (u32 index = 0; index < command_count; index++) {
|
||||
auto& command{*reinterpret_cast<ICommand*>(commands)};
|
||||
auto& command{*reinterpret_cast<Renderer::ICommand*>(commands)};
|
||||
|
||||
if (command.magic != 0xCAFEBABE) {
|
||||
LOG_ERROR(Service_Audio, "Command has invalid magic! Expected 0xCAFEBABE, got {:08X}",
|
||||
command.magic);
|
||||
return system->CoreTiming().GetClockTicks() - start_time_;
|
||||
return system->CoreTiming().GetGlobalTimeUs().count() - start_time_;
|
||||
}
|
||||
|
||||
auto current_offset{CpuAddr(commands) - command_base};
|
||||
|
|
@ -74,8 +74,8 @@ u64 CommandListProcessor::Process(u32 session_id) {
|
|||
LOG_ERROR(Service_Audio,
|
||||
"Command exceeded command buffer, buffer size {:08X}, command ends at {:08X}",
|
||||
commands_buffer_size,
|
||||
CpuAddr(commands) + command.size - sizeof(CommandListHeader));
|
||||
return system->CoreTiming().GetClockTicks() - start_time_;
|
||||
CpuAddr(commands) + command.size - sizeof(Renderer::CommandListHeader));
|
||||
return system->CoreTiming().GetGlobalTimeUs().count() - start_time_;
|
||||
}
|
||||
|
||||
if (Settings::values.dump_audio_commands) {
|
||||
|
|
@ -101,8 +101,8 @@ u64 CommandListProcessor::Process(u32 session_id) {
|
|||
last_dump = dump;
|
||||
}
|
||||
|
||||
end_time = system->CoreTiming().GetClockTicks();
|
||||
end_time = system->CoreTiming().GetGlobalTimeUs().count();
|
||||
return end_time - start_time_;
|
||||
}
|
||||
|
||||
} // namespace AudioCore::AudioRenderer::ADSP
|
||||
} // namespace AudioCore::ADSP::AudioRenderer
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
#include <span>
|
||||
|
||||
#include "audio_core/common/common.h"
|
||||
#include "audio_core/renderer/command/command_list_header.h"
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Core {
|
||||
|
|
@ -20,10 +21,11 @@ namespace Sink {
|
|||
class SinkStream;
|
||||
}
|
||||
|
||||
namespace AudioRenderer {
|
||||
namespace Renderer {
|
||||
struct CommandListHeader;
|
||||
}
|
||||
|
||||
namespace ADSP {
|
||||
namespace ADSP::AudioRenderer {
|
||||
|
||||
/**
|
||||
* A processor for command lists given to the AudioRenderer.
|
||||
|
|
@ -85,7 +87,7 @@ public:
|
|||
/// Stream for the processed samples
|
||||
Sink::SinkStream* stream{};
|
||||
/// Header info for this command list
|
||||
CommandListHeader* header{};
|
||||
Renderer::CommandListHeader* header{};
|
||||
/// The command buffer
|
||||
u8* commands{};
|
||||
/// The command buffer size
|
||||
|
|
@ -114,6 +116,5 @@ public:
|
|||
std::string last_dump{};
|
||||
};
|
||||
|
||||
} // namespace ADSP
|
||||
} // namespace AudioRenderer
|
||||
} // namespace ADSP::AudioRenderer
|
||||
} // namespace AudioCore
|
||||
69
src/audio_core/adsp/mailbox.h
Normal file
69
src/audio_core/adsp/mailbox.h
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/bounded_threadsafe_queue.h"
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace AudioCore::ADSP {
|
||||
|
||||
enum class AppMailboxId : u32 {
|
||||
Invalid = 0,
|
||||
AudioRenderer = 50,
|
||||
AudioRendererMemoryMapUnmap = 51,
|
||||
};
|
||||
|
||||
enum class Direction : u32 {
|
||||
Host,
|
||||
DSP,
|
||||
};
|
||||
|
||||
struct MailboxMessage {
|
||||
u32 msg;
|
||||
std::span<u8> data;
|
||||
};
|
||||
|
||||
class Mailbox {
|
||||
public:
|
||||
void Initialize(AppMailboxId id_) {
|
||||
Reset();
|
||||
id = id_;
|
||||
}
|
||||
|
||||
AppMailboxId Id() const noexcept {
|
||||
return id;
|
||||
}
|
||||
|
||||
void Send(Direction dir, MailboxMessage&& message) {
|
||||
auto& queue = dir == Direction::Host ? host_queue : adsp_queue;
|
||||
queue.EmplaceWait(std::move(message));
|
||||
}
|
||||
|
||||
MailboxMessage Receive(Direction dir, bool block = true) {
|
||||
auto& queue = dir == Direction::Host ? host_queue : adsp_queue;
|
||||
MailboxMessage t;
|
||||
if (block) {
|
||||
queue.PopWait(t);
|
||||
} else {
|
||||
queue.TryPop(t);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
void Reset() {
|
||||
id = AppMailboxId::Invalid;
|
||||
MailboxMessage t;
|
||||
while (host_queue.TryPop(t)) {
|
||||
}
|
||||
while (adsp_queue.TryPop(t)) {
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
AppMailboxId id{0};
|
||||
Common::SPSCQueue<MailboxMessage> host_queue;
|
||||
Common::SPSCQueue<MailboxMessage> adsp_queue;
|
||||
};
|
||||
|
||||
} // namespace AudioCore::ADSP
|
||||
|
|
@ -11,7 +11,7 @@ namespace AudioCore {
|
|||
AudioCore::AudioCore(Core::System& system) : audio_manager{std::make_unique<AudioManager>()} {
|
||||
CreateSinks();
|
||||
// Must be created after the sinks
|
||||
adsp = std::make_unique<AudioRenderer::ADSP::ADSP>(system, *output_sink);
|
||||
adsp = std::make_unique<ADSP::ADSP>(system, *output_sink);
|
||||
}
|
||||
|
||||
AudioCore ::~AudioCore() {
|
||||
|
|
@ -43,7 +43,7 @@ Sink::Sink& AudioCore::GetInputSink() {
|
|||
return *input_sink;
|
||||
}
|
||||
|
||||
AudioRenderer::ADSP::ADSP& AudioCore::GetADSP() {
|
||||
ADSP::ADSP& AudioCore::ADSP() {
|
||||
return *adsp;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
#include "audio_core/adsp/adsp.h"
|
||||
#include "audio_core/audio_manager.h"
|
||||
#include "audio_core/renderer/adsp/adsp.h"
|
||||
#include "audio_core/sink/sink.h"
|
||||
|
||||
namespace Core {
|
||||
|
|
@ -55,7 +55,7 @@ public:
|
|||
*
|
||||
* @return Ref to the ADSP.
|
||||
*/
|
||||
AudioRenderer::ADSP::ADSP& GetADSP();
|
||||
ADSP::ADSP& ADSP();
|
||||
|
||||
private:
|
||||
/**
|
||||
|
|
@ -70,7 +70,7 @@ private:
|
|||
/// Sink used for audio input
|
||||
std::unique_ptr<Sink::Sink> input_sink;
|
||||
/// The ADSP in the sysmodule
|
||||
std::unique_ptr<AudioRenderer::ADSP::ADSP> adsp;
|
||||
std::unique_ptr<ADSP::ADSP> adsp;
|
||||
};
|
||||
|
||||
} // namespace AudioCore
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ void Manager::BufferReleaseAndRegister() {
|
|||
}
|
||||
}
|
||||
|
||||
u32 Manager::GetDeviceNames(std::vector<AudioRenderer::AudioDevice::AudioDeviceName>& names,
|
||||
u32 Manager::GetDeviceNames(std::vector<Renderer::AudioDevice::AudioDeviceName>& names,
|
||||
[[maybe_unused]] const u32 max_count,
|
||||
[[maybe_unused]] const bool filter) {
|
||||
std::scoped_lock l{mutex};
|
||||
|
|
|
|||
|
|
@ -65,8 +65,8 @@ public:
|
|||
*
|
||||
* @return Number of names written.
|
||||
*/
|
||||
u32 GetDeviceNames(std::vector<AudioRenderer::AudioDevice::AudioDeviceName>& names,
|
||||
u32 max_count, bool filter);
|
||||
u32 GetDeviceNames(std::vector<Renderer::AudioDevice::AudioDeviceName>& names, u32 max_count,
|
||||
bool filter);
|
||||
|
||||
/// Core system
|
||||
Core::System& system;
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ void Manager::BufferReleaseAndRegister() {
|
|||
}
|
||||
|
||||
u32 Manager::GetAudioOutDeviceNames(
|
||||
std::vector<AudioRenderer::AudioDevice::AudioDeviceName>& names) const {
|
||||
std::vector<Renderer::AudioDevice::AudioDeviceName>& names) const {
|
||||
names.emplace_back("DeviceOut");
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,8 +61,7 @@ public:
|
|||
* @param names - Output container to write names to.
|
||||
* @return Number of names written.
|
||||
*/
|
||||
u32 GetAudioOutDeviceNames(
|
||||
std::vector<AudioRenderer::AudioDevice::AudioDeviceName>& names) const;
|
||||
u32 GetAudioOutDeviceNames(std::vector<Renderer::AudioDevice::AudioDeviceName>& names) const;
|
||||
|
||||
/// Core system
|
||||
Core::System& system;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#include "audio_core/common/feature_support.h"
|
||||
#include "core/core.h"
|
||||
|
||||
namespace AudioCore::AudioRenderer {
|
||||
namespace AudioCore::Renderer {
|
||||
|
||||
Manager::Manager(Core::System& system_)
|
||||
: system{system_}, system_manager{std::make_unique<SystemManager>(system)} {
|
||||
|
|
@ -67,4 +67,4 @@ bool Manager::RemoveSystem(System& system_) {
|
|||
return system_manager->Remove(system_);
|
||||
}
|
||||
|
||||
} // namespace AudioCore::AudioRenderer
|
||||
} // namespace AudioCore::Renderer
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class System;
|
|||
namespace AudioCore {
|
||||
struct AudioRendererParameterInternal;
|
||||
|
||||
namespace AudioRenderer {
|
||||
namespace Renderer {
|
||||
/**
|
||||
* Wrapper for the audio system manager, handles service calls.
|
||||
*/
|
||||
|
|
@ -101,5 +101,5 @@ private:
|
|||
std::unique_ptr<SystemManager> system_manager{};
|
||||
};
|
||||
|
||||
} // namespace AudioRenderer
|
||||
} // namespace Renderer
|
||||
} // namespace AudioCore
|
||||
|
|
|
|||
|
|
@ -51,10 +51,10 @@ struct AudioRendererSystemContext {
|
|||
s32 session_id;
|
||||
s8 channels;
|
||||
s16 mix_buffer_count;
|
||||
AudioRenderer::BehaviorInfo* behavior;
|
||||
Renderer::BehaviorInfo* behavior;
|
||||
std::span<s32> depop_buffer;
|
||||
AudioRenderer::UpsamplerManager* upsampler_manager;
|
||||
AudioRenderer::MemoryPoolInfo* memory_pool_info;
|
||||
Renderer::UpsamplerManager* upsampler_manager;
|
||||
Renderer::MemoryPoolInfo* memory_pool_info;
|
||||
};
|
||||
|
||||
} // namespace AudioCore
|
||||
|
|
|
|||
|
|
@ -1,117 +0,0 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "audio_core/renderer/adsp/adsp.h"
|
||||
#include "audio_core/renderer/adsp/command_buffer.h"
|
||||
#include "audio_core/sink/sink.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/core.h"
|
||||
#include "core/core_timing.h"
|
||||
#include "core/memory.h"
|
||||
|
||||
namespace AudioCore::AudioRenderer::ADSP {
|
||||
|
||||
ADSP::ADSP(Core::System& system_, Sink::Sink& sink_)
|
||||
: system{system_}, memory{system.ApplicationMemory()}, sink{sink_} {}
|
||||
|
||||
ADSP::~ADSP() {
|
||||
ClearCommandBuffers();
|
||||
}
|
||||
|
||||
State ADSP::GetState() const {
|
||||
if (running) {
|
||||
return State::Started;
|
||||
}
|
||||
return State::Stopped;
|
||||
}
|
||||
|
||||
AudioRenderer_Mailbox* ADSP::GetRenderMailbox() {
|
||||
return &render_mailbox;
|
||||
}
|
||||
|
||||
void ADSP::ClearRemainCount(const u32 session_id) {
|
||||
render_mailbox.ClearRemainCount(session_id);
|
||||
}
|
||||
|
||||
u64 ADSP::GetSignalledTick() const {
|
||||
return render_mailbox.GetSignalledTick();
|
||||
}
|
||||
|
||||
u64 ADSP::GetTimeTaken() const {
|
||||
return render_mailbox.GetRenderTimeTaken();
|
||||
}
|
||||
|
||||
u64 ADSP::GetRenderTimeTaken(const u32 session_id) {
|
||||
return render_mailbox.GetCommandBuffer(session_id).render_time_taken;
|
||||
}
|
||||
|
||||
u32 ADSP::GetRemainCommandCount(const u32 session_id) const {
|
||||
return render_mailbox.GetRemainCommandCount(session_id);
|
||||
}
|
||||
|
||||
void ADSP::SendCommandBuffer(const u32 session_id, const CommandBuffer& command_buffer) {
|
||||
render_mailbox.SetCommandBuffer(session_id, command_buffer);
|
||||
}
|
||||
|
||||
u64 ADSP::GetRenderingStartTick(const u32 session_id) {
|
||||
return render_mailbox.GetSignalledTick() +
|
||||
render_mailbox.GetCommandBuffer(session_id).render_time_taken;
|
||||
}
|
||||
|
||||
bool ADSP::Start() {
|
||||
if (running) {
|
||||
return running;
|
||||
}
|
||||
|
||||
running = true;
|
||||
systems_active++;
|
||||
audio_renderer = std::make_unique<AudioRenderer>(system);
|
||||
audio_renderer->Start(&render_mailbox);
|
||||
render_mailbox.HostSendMessage(RenderMessage::AudioRenderer_InitializeOK);
|
||||
if (render_mailbox.HostWaitMessage() != RenderMessage::AudioRenderer_InitializeOK) {
|
||||
LOG_ERROR(
|
||||
Service_Audio,
|
||||
"Host Audio Renderer -- Failed to receive initialize message response from ADSP!");
|
||||
}
|
||||
return running;
|
||||
}
|
||||
|
||||
void ADSP::Stop() {
|
||||
systems_active--;
|
||||
if (running && systems_active == 0) {
|
||||
{
|
||||
std::scoped_lock l{mailbox_lock};
|
||||
render_mailbox.HostSendMessage(RenderMessage::AudioRenderer_Shutdown);
|
||||
if (render_mailbox.HostWaitMessage() != RenderMessage::AudioRenderer_Shutdown) {
|
||||
LOG_ERROR(Service_Audio, "Host Audio Renderer -- Failed to receive shutdown "
|
||||
"message response from ADSP!");
|
||||
}
|
||||
}
|
||||
audio_renderer->Stop();
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ADSP::Signal() {
|
||||
const auto signalled_tick{system.CoreTiming().GetClockTicks()};
|
||||
render_mailbox.SetSignalledTick(signalled_tick);
|
||||
render_mailbox.HostSendMessage(RenderMessage::AudioRenderer_Render);
|
||||
}
|
||||
|
||||
void ADSP::Wait() {
|
||||
std::scoped_lock l{mailbox_lock};
|
||||
auto response{render_mailbox.HostWaitMessage()};
|
||||
if (response != RenderMessage::AudioRenderer_RenderResponse) {
|
||||
LOG_ERROR(Service_Audio, "Invalid ADSP response message, expected 0x{:02X}, got 0x{:02X}",
|
||||
static_cast<u32>(RenderMessage::AudioRenderer_RenderResponse),
|
||||
static_cast<u32>(response));
|
||||
}
|
||||
|
||||
ClearCommandBuffers();
|
||||
}
|
||||
|
||||
void ADSP::ClearCommandBuffers() {
|
||||
render_mailbox.ClearCommandBuffers();
|
||||
}
|
||||
|
||||
} // namespace AudioCore::AudioRenderer::ADSP
|
||||
|
|
@ -1,171 +0,0 @@
|
|||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include "audio_core/renderer/adsp/audio_renderer.h"
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace Core {
|
||||
namespace Memory {
|
||||
class Memory;
|
||||
}
|
||||
class System;
|
||||
} // namespace Core
|
||||
|
||||
namespace AudioCore {
|
||||
namespace Sink {
|
||||
class Sink;
|
||||
}
|
||||
|
||||
namespace AudioRenderer::ADSP {
|
||||
struct CommandBuffer;
|
||||
|
||||
enum class State {
|
||||
Started,
|
||||
Stopped,
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents the ADSP embedded within the audio sysmodule.
|
||||
* This is a 32-bit Linux4Tegra kernel from nVidia, which is launched with the sysmodule on boot.
|
||||
*
|
||||
* The kernel will run apps you program for it, Nintendo have the following:
|
||||
*
|
||||
* Gmix - Responsible for mixing final audio and sending it out to hardware. This is last place all
|
||||
* audio samples end up, and we skip it entirely, since we have very different backends and
|
||||
* mixing is implicitly handled by the OS (but also due to lack of research/simplicity).
|
||||
*
|
||||
* AudioRenderer - Receives command lists generated by the audio render
|
||||
* system, processes them, and sends the samples to Gmix.
|
||||
*
|
||||
* OpusDecoder - Contains libopus, and controls processing Opus audio and sends it to Gmix.
|
||||
* Not much research done here, TODO if needed.
|
||||
*
|
||||
* We only implement the AudioRenderer for now.
|
||||
*
|
||||
* Communication for the apps is done through mailboxes, and some shared memory.
|
||||
*/
|
||||
class ADSP {
|
||||
public:
|
||||
explicit ADSP(Core::System& system, Sink::Sink& sink);
|
||||
~ADSP();
|
||||
|
||||
/**
|
||||
* Start the ADSP.
|
||||
*
|
||||
* @return True if started or already running, otherwise false.
|
||||
*/
|
||||
bool Start();
|
||||
|
||||
/**
|
||||
* Stop the ADSP.
|
||||
*/
|
||||
void Stop();
|
||||
|
||||
/**
|
||||
* Get the ADSP's state.
|
||||
*
|
||||
* @return Started or Stopped.
|
||||
*/
|
||||
State GetState() const;
|
||||
|
||||
/**
|
||||
* Get the AudioRenderer mailbox to communicate with it.
|
||||
*
|
||||
* @return The AudioRenderer mailbox.
|
||||
*/
|
||||
AudioRenderer_Mailbox* GetRenderMailbox();
|
||||
|
||||
/**
|
||||
* Get the tick the ADSP was signalled.
|
||||
*
|
||||
* @return The tick the ADSP was signalled.
|
||||
*/
|
||||
u64 GetSignalledTick() const;
|
||||
|
||||
/**
|
||||
* Get the total time it took for the ADSP to run the last command lists (both command lists).
|
||||
*
|
||||
* @return The tick the ADSP was signalled.
|
||||
*/
|
||||
u64 GetTimeTaken() const;
|
||||
|
||||
/**
|
||||
* Get the last time a given command list took to run.
|
||||
*
|
||||
* @param session_id - The session id to check (0 or 1).
|
||||
* @return The time it took.
|
||||
*/
|
||||
u64 GetRenderTimeTaken(u32 session_id);
|
||||
|
||||
/**
|
||||
* Clear the remaining command count for a given session.
|
||||
*
|
||||
* @param session_id - The session id to check (0 or 1).
|
||||
*/
|
||||
void ClearRemainCount(u32 session_id);
|
||||
|
||||
/**
|
||||
* Get the remaining number of commands left to process for a command list.
|
||||
*
|
||||
* @param session_id - The session id to check (0 or 1).
|
||||
* @return The number of commands remaining.
|
||||
*/
|
||||
u32 GetRemainCommandCount(u32 session_id) const;
|
||||
|
||||
/**
|
||||
* Get the last tick a command list started processing.
|
||||
*
|
||||
* @param session_id - The session id to check (0 or 1).
|
||||
* @return The last tick the given command list started.
|
||||
*/
|
||||
u64 GetRenderingStartTick(u32 session_id);
|
||||
|
||||
/**
|
||||
* Set a command buffer to be processed.
|
||||
*
|
||||
* @param session_id - The session id to check (0 or 1).
|
||||
* @param command_buffer - The command buffer to process.
|
||||
*/
|
||||
void SendCommandBuffer(u32 session_id, const CommandBuffer& command_buffer);
|
||||
|
||||
/**
|
||||
* Clear the command buffers (does not clear the time taken or the remaining command count)
|
||||
*/
|
||||
void ClearCommandBuffers();
|
||||
|
||||
/**
|
||||
* Signal the AudioRenderer to begin processing.
|
||||
*/
|
||||
void Signal();
|
||||
|
||||
/**
|
||||
* Wait for the AudioRenderer to finish processing.
|
||||
*/
|
||||
void Wait();
|
||||
|
||||
private:
|
||||
/// Core system
|
||||
Core::System& system;
|
||||
/// Core memory
|
||||
Core::Memory::Memory& memory;
|
||||
/// Number of systems active, used to prevent accidental shutdowns
|
||||
u8 systems_active{0};
|
||||
/// ADSP running state
|
||||
std::atomic<bool> running{false};
|
||||
/// Output sink used by the ADSP
|
||||
Sink::Sink& sink;
|
||||
/// AudioRenderer app
|
||||
std::unique_ptr<AudioRenderer> audio_renderer{};
|
||||
/// Communication for the AudioRenderer
|
||||
AudioRenderer_Mailbox render_mailbox{};
|
||||
/// Mailbox lock ffor the render mailbox
|
||||
std::mutex mailbox_lock;
|
||||
};
|
||||
|
||||
} // namespace AudioRenderer::ADSP
|
||||
} // namespace AudioCore
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue