citra-emu
/
citra
Archived
1
0
Fork 0

audiocore/{hle, lle}: remove dependence on static core timing

This commit is contained in:
SachinVin 2023-05-14 09:57:29 +05:30
parent fa8c530e10
commit 975ee15635
5 changed files with 27 additions and 22 deletions

View File

@ -40,7 +40,7 @@ using Service::DSP::DSP_DSP;
namespace AudioCore { namespace AudioCore {
DspHle::DspHle() : DspHle(Core::System::GetInstance().Memory()) {} DspHle::DspHle() : DspHle(Core::System::GetInstance().Memory(), Core::System::GetInstance().CoreTiming()) {}
template <class Archive> template <class Archive>
void DspHle::serialize(Archive& ar, const unsigned int) { void DspHle::serialize(Archive& ar, const unsigned int) {
@ -58,7 +58,7 @@ static constexpr u64 audio_frame_ticks = samples_per_frame * 4096 * 2ull; ///< U
struct DspHle::Impl final { struct DspHle::Impl final {
public: public:
explicit Impl(DspHle& parent, Memory::MemorySystem& memory); explicit Impl(DspHle& parent, Memory::MemorySystem& memory, Core::Timing& timing);
~Impl(); ~Impl();
DspState GetDspState() const; DspState GetDspState() const;
@ -100,6 +100,7 @@ private:
HLE::Mixers mixers{}; HLE::Mixers mixers{};
DspHle& parent; DspHle& parent;
Core::Timing& core_timing;
Core::TimingEventType* tick_event{}; Core::TimingEventType* tick_event{};
std::unique_ptr<HLE::DecoderBase> decoder{}; std::unique_ptr<HLE::DecoderBase> decoder{};
@ -118,7 +119,8 @@ private:
friend class boost::serialization::access; friend class boost::serialization::access;
}; };
DspHle::Impl::Impl(DspHle& parent_, Memory::MemorySystem& memory) : parent(parent_) { DspHle::Impl::Impl(DspHle& parent_, Memory::MemorySystem& memory, Core::Timing& timing)
: parent(parent_), core_timing(timing) {
dsp_memory.raw_memory.fill(0); dsp_memory.raw_memory.fill(0);
for (auto& source : sources) { for (auto& source : sources) {
@ -152,17 +154,15 @@ DspHle::Impl::Impl(DspHle& parent_, Memory::MemorySystem& memory) : parent(paren
decoder = std::make_unique<HLE::NullDecoder>(); decoder = std::make_unique<HLE::NullDecoder>();
} }
Core::Timing& timing = Core::System::GetInstance().CoreTiming();
tick_event = tick_event =
timing.RegisterEvent("AudioCore::DspHle::tick_event", [this](u64, s64 cycles_late) { core_timing.RegisterEvent("AudioCore::DspHle::tick_event", [this](u64, s64 cycles_late) {
this->AudioTickCallback(cycles_late); this->AudioTickCallback(cycles_late);
}); });
timing.ScheduleEvent(audio_frame_ticks, tick_event); core_timing.ScheduleEvent(audio_frame_ticks, tick_event);
} }
DspHle::Impl::~Impl() { DspHle::Impl::~Impl() {
Core::Timing& timing = Core::System::GetInstance().CoreTiming(); core_timing.UnscheduleEvent(tick_event, 0);
timing.UnscheduleEvent(tick_event, 0);
} }
DspState DspHle::Impl::GetDspState() const { DspState DspHle::Impl::GetDspState() const {
@ -457,11 +457,11 @@ void DspHle::Impl::AudioTickCallback(s64 cycles_late) {
} }
// Reschedule recurrent event // Reschedule recurrent event
Core::Timing& timing = Core::System::GetInstance().CoreTiming(); core_timing.ScheduleEvent(audio_frame_ticks - cycles_late, tick_event);
timing.ScheduleEvent(audio_frame_ticks - cycles_late, tick_event);
} }
DspHle::DspHle(Memory::MemorySystem& memory) : impl(std::make_unique<Impl>(*this, memory)) {} DspHle::DspHle(Memory::MemorySystem& memory, Core::Timing& timing)
: impl(std::make_unique<Impl>(*this, memory, timing)) {}
DspHle::~DspHle() = default; DspHle::~DspHle() = default;
u16 DspHle::RecvData(u32 register_number) { u16 DspHle::RecvData(u32 register_number) {

View File

@ -22,7 +22,7 @@ namespace AudioCore {
class DspHle final : public DspInterface { class DspHle final : public DspInterface {
public: public:
explicit DspHle(Memory::MemorySystem& memory); explicit DspHle(Memory::MemorySystem& memory, Core::Timing& timing);
~DspHle(); ~DspHle();
u16 RecvData(u32 register_number) override; u16 RecvData(u32 register_number) override;

View File

@ -122,8 +122,8 @@ static u8 PipeIndexToSlotIndex(u8 pipe_index, PipeDirection direction) {
} }
struct DspLle::Impl final { struct DspLle::Impl final {
Impl(bool multithread) : multithread(multithread) { Impl(Core::Timing& timing, bool multithread) : core_timing(timing), multithread(multithread) {
teakra_slice_event = Core::System::GetInstance().CoreTiming().RegisterEvent( teakra_slice_event = core_timing.RegisterEvent(
"DSP slice", [this](u64, int late) { TeakraSliceEvent(static_cast<u64>(late)); }); "DSP slice", [this](u64, int late) { TeakraSliceEvent(static_cast<u64>(late)); });
} }
@ -137,6 +137,7 @@ struct DspLle::Impl final {
bool semaphore_signaled = false; bool semaphore_signaled = false;
bool data_signaled = false; bool data_signaled = false;
Core::Timing& core_timing;
Core::TimingEventType* teakra_slice_event; Core::TimingEventType* teakra_slice_event;
std::atomic<bool> loaded = false; std::atomic<bool> loaded = false;
@ -185,7 +186,7 @@ struct DspLle::Impl final {
next = 0; next = 0;
else else
next -= late; next -= late;
Core::System::GetInstance().CoreTiming().ScheduleEvent(next, teakra_slice_event, 0); core_timing.ScheduleEvent(next, teakra_slice_event, 0);
} }
u8* GetDspDataPointer(u32 baddr) { u8* GetDspDataPointer(u32 baddr) {
@ -326,7 +327,7 @@ struct DspLle::Impl final {
// TODO: load special segment // TODO: load special segment
Core::System::GetInstance().CoreTiming().ScheduleEvent(TeakraSlice, teakra_slice_event, 0); core_timing.ScheduleEvent(TeakraSlice, teakra_slice_event, 0);
if (multithread) { if (multithread) {
teakra_thread = std::thread(&Impl::TeakraThread, this); teakra_thread = std::thread(&Impl::TeakraThread, this);
@ -371,7 +372,7 @@ struct DspLle::Impl final {
teakra.RecvData(2); // discard the value teakra.RecvData(2); // discard the value
Core::System::GetInstance().CoreTiming().UnscheduleEvent(teakra_slice_event, 0); core_timing.UnscheduleEvent(teakra_slice_event, 0);
StopTeakraThread(); StopTeakraThread();
} }
}; };
@ -475,8 +476,8 @@ void DspLle::UnloadComponent() {
impl->UnloadComponent(); impl->UnloadComponent();
} }
DspLle::DspLle(Memory::MemorySystem& memory, bool multithread) DspLle::DspLle(Memory::MemorySystem& memory,Core::Timing& timing, bool multithread)
: impl(std::make_unique<Impl>(multithread)) { : impl(std::make_unique<Impl>(timing, multithread)) {
Teakra::AHBMCallback ahbm; Teakra::AHBMCallback ahbm;
ahbm.read8 = [&memory](u32 address) -> u8 { ahbm.read8 = [&memory](u32 address) -> u8 {
return *memory.GetFCRAMPointer(address - Memory::FCRAM_PADDR); return *memory.GetFCRAMPointer(address - Memory::FCRAM_PADDR);

View File

@ -6,11 +6,15 @@
#include "audio_core/dsp_interface.h" #include "audio_core/dsp_interface.h"
namespace Core {
class Timing;
}
namespace AudioCore { namespace AudioCore {
class DspLle final : public DspInterface { class DspLle final : public DspInterface {
public: public:
explicit DspLle(Memory::MemorySystem& memory, bool multithread); explicit DspLle(Memory::MemorySystem& memory, Core::Timing& timing, bool multithread);
~DspLle() override; ~DspLle() override;
u16 RecvData(u32 register_number) override; u16 RecvData(u32 register_number) override;

View File

@ -400,10 +400,10 @@ System::ResultStatus System::Init(Frontend::EmuWindow& emu_window,
const auto audio_emulation = Settings::values.audio_emulation.GetValue(); const auto audio_emulation = Settings::values.audio_emulation.GetValue();
if (audio_emulation == Settings::AudioEmulation::HLE) { if (audio_emulation == Settings::AudioEmulation::HLE) {
dsp_core = std::make_unique<AudioCore::DspHle>(*memory); dsp_core = std::make_unique<AudioCore::DspHle>(*memory, *timing);
} else { } else {
const bool multithread = audio_emulation == Settings::AudioEmulation::LLEMultithreaded; const bool multithread = audio_emulation == Settings::AudioEmulation::LLEMultithreaded;
dsp_core = std::make_unique<AudioCore::DspLle>(*memory, multithread); dsp_core = std::make_unique<AudioCore::DspLle>(*memory, *timing, multithread);
} }
memory->SetDSP(*dsp_core); memory->SetDSP(*dsp_core);