diff --git a/src/audio_core/hle/hle.cpp b/src/audio_core/hle/hle.cpp index 18297ecee8..d1514e30bc 100644 --- a/src/audio_core/hle/hle.cpp +++ b/src/audio_core/hle/hle.cpp @@ -40,7 +40,7 @@ using Service::DSP::DSP_DSP; namespace AudioCore { -DspHle::DspHle() : DspHle(Core::System::GetInstance().Memory()) {} +DspHle::DspHle() : DspHle(Core::System::GetInstance().Memory(), Core::System::GetInstance().CoreTiming()) {} template 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 { public: - explicit Impl(DspHle& parent, Memory::MemorySystem& memory); + explicit Impl(DspHle& parent, Memory::MemorySystem& memory, Core::Timing& timing); ~Impl(); DspState GetDspState() const; @@ -100,6 +100,7 @@ private: HLE::Mixers mixers{}; DspHle& parent; + Core::Timing& core_timing; Core::TimingEventType* tick_event{}; std::unique_ptr decoder{}; @@ -118,7 +119,8 @@ private: 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); for (auto& source : sources) { @@ -152,17 +154,15 @@ DspHle::Impl::Impl(DspHle& parent_, Memory::MemorySystem& memory) : parent(paren decoder = std::make_unique(); } - Core::Timing& timing = Core::System::GetInstance().CoreTiming(); 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); }); - timing.ScheduleEvent(audio_frame_ticks, tick_event); + core_timing.ScheduleEvent(audio_frame_ticks, tick_event); } DspHle::Impl::~Impl() { - Core::Timing& timing = Core::System::GetInstance().CoreTiming(); - timing.UnscheduleEvent(tick_event, 0); + core_timing.UnscheduleEvent(tick_event, 0); } DspState DspHle::Impl::GetDspState() const { @@ -457,11 +457,11 @@ void DspHle::Impl::AudioTickCallback(s64 cycles_late) { } // Reschedule recurrent event - Core::Timing& timing = Core::System::GetInstance().CoreTiming(); - timing.ScheduleEvent(audio_frame_ticks - cycles_late, tick_event); + core_timing.ScheduleEvent(audio_frame_ticks - cycles_late, tick_event); } -DspHle::DspHle(Memory::MemorySystem& memory) : impl(std::make_unique(*this, memory)) {} +DspHle::DspHle(Memory::MemorySystem& memory, Core::Timing& timing) + : impl(std::make_unique(*this, memory, timing)) {} DspHle::~DspHle() = default; u16 DspHle::RecvData(u32 register_number) { diff --git a/src/audio_core/hle/hle.h b/src/audio_core/hle/hle.h index 11ec2820a6..014a3b73c7 100644 --- a/src/audio_core/hle/hle.h +++ b/src/audio_core/hle/hle.h @@ -22,7 +22,7 @@ namespace AudioCore { class DspHle final : public DspInterface { public: - explicit DspHle(Memory::MemorySystem& memory); + explicit DspHle(Memory::MemorySystem& memory, Core::Timing& timing); ~DspHle(); u16 RecvData(u32 register_number) override; diff --git a/src/audio_core/lle/lle.cpp b/src/audio_core/lle/lle.cpp index fbb6f1f07e..09202e4896 100644 --- a/src/audio_core/lle/lle.cpp +++ b/src/audio_core/lle/lle.cpp @@ -122,8 +122,8 @@ static u8 PipeIndexToSlotIndex(u8 pipe_index, PipeDirection direction) { } struct DspLle::Impl final { - Impl(bool multithread) : multithread(multithread) { - teakra_slice_event = Core::System::GetInstance().CoreTiming().RegisterEvent( + Impl(Core::Timing& timing, bool multithread) : core_timing(timing), multithread(multithread) { + teakra_slice_event = core_timing.RegisterEvent( "DSP slice", [this](u64, int late) { TeakraSliceEvent(static_cast(late)); }); } @@ -137,6 +137,7 @@ struct DspLle::Impl final { bool semaphore_signaled = false; bool data_signaled = false; + Core::Timing& core_timing; Core::TimingEventType* teakra_slice_event; std::atomic loaded = false; @@ -185,7 +186,7 @@ struct DspLle::Impl final { next = 0; else next -= late; - Core::System::GetInstance().CoreTiming().ScheduleEvent(next, teakra_slice_event, 0); + core_timing.ScheduleEvent(next, teakra_slice_event, 0); } u8* GetDspDataPointer(u32 baddr) { @@ -326,7 +327,7 @@ struct DspLle::Impl final { // TODO: load special segment - Core::System::GetInstance().CoreTiming().ScheduleEvent(TeakraSlice, teakra_slice_event, 0); + core_timing.ScheduleEvent(TeakraSlice, teakra_slice_event, 0); if (multithread) { teakra_thread = std::thread(&Impl::TeakraThread, this); @@ -371,7 +372,7 @@ struct DspLle::Impl final { teakra.RecvData(2); // discard the value - Core::System::GetInstance().CoreTiming().UnscheduleEvent(teakra_slice_event, 0); + core_timing.UnscheduleEvent(teakra_slice_event, 0); StopTeakraThread(); } }; @@ -475,8 +476,8 @@ void DspLle::UnloadComponent() { impl->UnloadComponent(); } -DspLle::DspLle(Memory::MemorySystem& memory, bool multithread) - : impl(std::make_unique(multithread)) { +DspLle::DspLle(Memory::MemorySystem& memory,Core::Timing& timing, bool multithread) + : impl(std::make_unique(timing, multithread)) { Teakra::AHBMCallback ahbm; ahbm.read8 = [&memory](u32 address) -> u8 { return *memory.GetFCRAMPointer(address - Memory::FCRAM_PADDR); diff --git a/src/audio_core/lle/lle.h b/src/audio_core/lle/lle.h index dc3647aa08..c2ac175a5f 100644 --- a/src/audio_core/lle/lle.h +++ b/src/audio_core/lle/lle.h @@ -6,11 +6,15 @@ #include "audio_core/dsp_interface.h" +namespace Core { +class Timing; +} + namespace AudioCore { class DspLle final : public DspInterface { public: - explicit DspLle(Memory::MemorySystem& memory, bool multithread); + explicit DspLle(Memory::MemorySystem& memory, Core::Timing& timing, bool multithread); ~DspLle() override; u16 RecvData(u32 register_number) override; diff --git a/src/core/core.cpp b/src/core/core.cpp index 31de0537e9..e1710b4b74 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -400,10 +400,10 @@ System::ResultStatus System::Init(Frontend::EmuWindow& emu_window, const auto audio_emulation = Settings::values.audio_emulation.GetValue(); if (audio_emulation == Settings::AudioEmulation::HLE) { - dsp_core = std::make_unique(*memory); + dsp_core = std::make_unique(*memory, *timing); } else { const bool multithread = audio_emulation == Settings::AudioEmulation::LLEMultithreaded; - dsp_core = std::make_unique(*memory, multithread); + dsp_core = std::make_unique(*memory, *timing, multithread); } memory->SetDSP(*dsp_core);