2026-09-09 16:05:11

Signed-off-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
lizzie
2026-09-09 16:05:11 +00:00
committed by crueter
parent 09f05f0313
commit 773c29ed85
4 changed files with 24 additions and 30 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ void Manager::ReleaseSessionId(Core::System& system, const size_t session_id) {
Result Manager::LinkToManager(Core::System& system) { Result Manager::LinkToManager(Core::System& system) {
std::scoped_lock l{mutex}; std::scoped_lock l{mutex};
if (!linked_to_manager) { if (!linked_to_manager) {
system.AudioCore().GetAudioManager().SetInManager(&Manager::BufferReleaseAndRegister); system.AudioCore().GetAudioManager().SetInManager(this, &Manager::BufferReleaseAndRegister);
linked_to_manager = true; linked_to_manager = true;
} }
+5 -3
View File
@@ -25,7 +25,7 @@ AudioManager::AudioManager(Core::System& system) {
const auto event_type = Event::Type(i); const auto event_type = Event::Type(i);
if (events.CheckAudioEventSet(event_type) || timed_out) { if (events.CheckAudioEventSet(event_type) || timed_out) {
if (buffer_events[i]) { if (buffer_events[i]) {
buffer_events[i](this, system); buffer_events[i](buffer_data[i], system);
} }
} }
events.SetAudioEvent(event_type, false); events.SetAudioEvent(event_type, false);
@@ -42,12 +42,13 @@ void AudioManager::Shutdown() {
} }
} }
Result AudioManager::SetOutManager(BufferEventFunc buffer_func) { Result AudioManager::SetOutManager(void *data, BufferEventFunc buffer_func) {
if (thread.joinable()) { if (thread.joinable()) {
std::scoped_lock l{lock}; std::scoped_lock l{lock};
const auto index{events.GetManagerIndex(Event::Type::AudioOutManager)}; const auto index{events.GetManagerIndex(Event::Type::AudioOutManager)};
if (buffer_events[index] == nullptr) { if (buffer_events[index] == nullptr) {
buffer_events[index] = std::move(buffer_func); buffer_events[index] = std::move(buffer_func);
buffer_data[index] = data;
needs_update = true; needs_update = true;
events.SetAudioEvent(Event::Type::AudioOutManager, true); events.SetAudioEvent(Event::Type::AudioOutManager, true);
} }
@@ -56,12 +57,13 @@ Result AudioManager::SetOutManager(BufferEventFunc buffer_func) {
return Service::Audio::ResultOperationFailed; return Service::Audio::ResultOperationFailed;
} }
Result AudioManager::SetInManager(BufferEventFunc buffer_func) { Result AudioManager::SetInManager(void *data, BufferEventFunc buffer_func) {
if (thread.joinable()) { if (thread.joinable()) {
std::scoped_lock l{lock}; std::scoped_lock l{lock};
const auto index{events.GetManagerIndex(Event::Type::AudioInManager)}; const auto index{events.GetManagerIndex(Event::Type::AudioInManager)};
if (buffer_events[index] == nullptr) { if (buffer_events[index] == nullptr) {
buffer_events[index] = std::move(buffer_func); buffer_events[index] = std::move(buffer_func);
buffer_data[index] = data;
needs_update = true; needs_update = true;
events.SetAudioEvent(Event::Type::AudioInManager, true); events.SetAudioEvent(Event::Type::AudioInManager, true);
} }
+10 -15
View File
@@ -47,21 +47,15 @@ public:
*/ */
void Shutdown(); void Shutdown();
/** /// Register the out manager, keeping a function to be called when the out event is signalled.
* Register the out manager, keeping a function to be called when the out event is signalled. /// @param buffer_func - Function to be called on signal.
* /// @return Result code.
* @param buffer_func - Function to be called on signal. Result SetOutManager(void *data, BufferEventFunc buffer_func);
* @return Result code.
*/
Result SetOutManager(BufferEventFunc buffer_func);
/** /// Register the in manager, keeping a function to be called when the in event is signalled.
* Register the in manager, keeping a function to be called when the in event is signalled. /// @param buffer_func - Function to be called on signal.
* /// @return Result code.
* @param buffer_func - Function to be called on signal. Result SetInManager(void *data, BufferEventFunc buffer_func);
* @return Result code.
*/
Result SetInManager(BufferEventFunc buffer_func);
/** /**
* Set an event to signalled, and signal the thread. * Set an event to signalled, and signal the thread.
@@ -76,8 +70,9 @@ private:
bool needs_update{}; bool needs_update{};
/// Events to be set and signalled /// Events to be set and signalled
Event events{}; Event events{};
/// Callbacks for each manager /// Callbacks (and user data) for each manager
std::array<BufferEventFunc, 3> buffer_events{}; std::array<BufferEventFunc, 3> buffer_events{};
std::array<void*, 3> buffer_data{};
/// General lock /// General lock
std::mutex lock{}; std::mutex lock{};
/// Main thread for waiting and callbacks /// Main thread for waiting and callbacks
+8 -11
View File
@@ -43,7 +43,7 @@ void Manager::ReleaseSessionId(Core::System& system, const size_t session_id) {
Result Manager::LinkToManager(Core::System& system) { Result Manager::LinkToManager(Core::System& system) {
std::scoped_lock l{mutex}; std::scoped_lock l{mutex};
if (!linked_to_manager) { if (!linked_to_manager) {
system.AudioCore().GetAudioManager().SetOutManager(&Manager::BufferReleaseAndRegister); system.AudioCore().GetAudioManager().SetOutManager(this, &Manager::BufferReleaseAndRegister);
linked_to_manager = true; linked_to_manager = true;
} }
@@ -51,18 +51,15 @@ Result Manager::LinkToManager(Core::System& system) {
} }
void Manager::Start(Core::System& system) { void Manager::Start(Core::System& system) {
if (sessions_started) { if (!sessions_started) {
return; std::scoped_lock l{mutex};
} for (auto& session : sessions) {
if (session) {
std::scoped_lock l{mutex}; session->StartSession();
for (auto& session : sessions) { }
if (session) {
session->StartSession();
} }
sessions_started = true;
} }
sessions_started = true;
} }
void Manager::BufferReleaseAndRegister(void *data, Core::System& system) noexcept { void Manager::BufferReleaseAndRegister(void *data, Core::System& system) noexcept {