|
|
@ -1,14 +1,13 @@
|
|
|
|
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
|
|
|
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
|
|
|
|
#include "audio_core/audio_in_manager.h"
|
|
|
|
|
|
|
|
#include "audio_core/audio_manager.h"
|
|
|
|
#include "audio_core/audio_manager.h"
|
|
|
|
#include "audio_core/audio_out_manager.h"
|
|
|
|
|
|
|
|
#include "core/core.h"
|
|
|
|
#include "core/core.h"
|
|
|
|
|
|
|
|
#include "core/hle/service/audio/errors.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace AudioCore {
|
|
|
|
namespace AudioCore {
|
|
|
|
|
|
|
|
|
|
|
|
AudioManager::AudioManager(Core::System& system_) : system{system_} {
|
|
|
|
AudioManager::AudioManager() {
|
|
|
|
thread = std::jthread([this]() { ThreadFunc(); });
|
|
|
|
thread = std::jthread([this]() { ThreadFunc(); });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -27,7 +26,7 @@ Result AudioManager::SetOutManager(BufferEventFunc buffer_func) {
|
|
|
|
|
|
|
|
|
|
|
|
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] = buffer_func;
|
|
|
|
buffer_events[index] = std::move(buffer_func);
|
|
|
|
needs_update = true;
|
|
|
|
needs_update = true;
|
|
|
|
events.SetAudioEvent(Event::Type::AudioOutManager, true);
|
|
|
|
events.SetAudioEvent(Event::Type::AudioOutManager, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -43,7 +42,7 @@ Result AudioManager::SetInManager(BufferEventFunc buffer_func) {
|
|
|
|
|
|
|
|
|
|
|
|
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] = buffer_func;
|
|
|
|
buffer_events[index] = std::move(buffer_func);
|
|
|
|
needs_update = true;
|
|
|
|
needs_update = true;
|
|
|
|
events.SetAudioEvent(Event::Type::AudioInManager, true);
|
|
|
|
events.SetAudioEvent(Event::Type::AudioInManager, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -60,19 +59,21 @@ void AudioManager::ThreadFunc() {
|
|
|
|
running = true;
|
|
|
|
running = true;
|
|
|
|
|
|
|
|
|
|
|
|
while (running) {
|
|
|
|
while (running) {
|
|
|
|
auto timed_out{events.Wait(l, std::chrono::seconds(2))};
|
|
|
|
const auto timed_out{events.Wait(l, std::chrono::seconds(2))};
|
|
|
|
|
|
|
|
|
|
|
|
if (events.CheckAudioEventSet(Event::Type::Max)) {
|
|
|
|
if (events.CheckAudioEventSet(Event::Type::Max)) {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < buffer_events.size(); i++) {
|
|
|
|
for (size_t i = 0; i < buffer_events.size(); i++) {
|
|
|
|
if (events.CheckAudioEventSet(Event::Type(i)) || timed_out) {
|
|
|
|
const auto event_type = static_cast<Event::Type>(i);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (events.CheckAudioEventSet(event_type) || timed_out) {
|
|
|
|
if (buffer_events[i]) {
|
|
|
|
if (buffer_events[i]) {
|
|
|
|
buffer_events[i]();
|
|
|
|
buffer_events[i]();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
events.SetAudioEvent(Event::Type(i), false);
|
|
|
|
events.SetAudioEvent(event_type, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|