audio_core: pass in memory reference

Because HLE::Source is initialized as an array in the member initializer, it is hard to let it accept the reference on ctor, so it has a second init stage performed by DspHle::Impl::Impl
This commit is contained in:
Weiyi Wang 2018-11-21 11:36:24 -05:00
parent 8bb404c82a
commit ec01975549
4 changed files with 24 additions and 4 deletions

View file

@ -24,7 +24,7 @@ static constexpr u64 audio_frame_ticks = 1310252ull; ///< Units: ARM11 cycles
struct DspHle::Impl final { struct DspHle::Impl final {
public: public:
explicit Impl(DspHle& parent); explicit Impl(DspHle& parent, Memory::MemorySystem& memory);
~Impl(); ~Impl();
DspState GetDspState() const; DspState GetDspState() const;
@ -69,9 +69,13 @@ private:
std::weak_ptr<DSP_DSP> dsp_dsp; std::weak_ptr<DSP_DSP> dsp_dsp;
}; };
DspHle::Impl::Impl(DspHle& parent_) : parent(parent_) { DspHle::Impl::Impl(DspHle& parent_, Memory::MemorySystem& memory) : parent(parent_) {
dsp_memory.raw_memory.fill(0); dsp_memory.raw_memory.fill(0);
for (auto& source : sources) {
source.SetMemory(memory);
}
Core::Timing& timing = Core::System::GetInstance().CoreTiming(); Core::Timing& timing = Core::System::GetInstance().CoreTiming();
tick_event = tick_event =
timing.RegisterEvent("AudioCore::DspHle::tick_event", [this](u64, s64 cycles_late) { timing.RegisterEvent("AudioCore::DspHle::tick_event", [this](u64, s64 cycles_late) {
@ -335,7 +339,7 @@ void DspHle::Impl::AudioTickCallback(s64 cycles_late) {
timing.ScheduleEvent(audio_frame_ticks - cycles_late, tick_event); timing.ScheduleEvent(audio_frame_ticks - cycles_late, tick_event);
} }
DspHle::DspHle() : impl(std::make_unique<Impl>(*this)) {} DspHle::DspHle(Memory::MemorySystem& memory) : impl(std::make_unique<Impl>(*this, memory)) {}
DspHle::~DspHle() = default; DspHle::~DspHle() = default;
DspState DspHle::GetDspState() const { DspState DspHle::GetDspState() const {

View file

@ -13,11 +13,15 @@
#include "core/hle/service/dsp/dsp_dsp.h" #include "core/hle/service/dsp/dsp_dsp.h"
#include "core/memory.h" #include "core/memory.h"
namespace Memory {
class MemorySystem;
}
namespace AudioCore { namespace AudioCore {
class DspHle final : public DspInterface { class DspHle final : public DspInterface {
public: public:
DspHle(); explicit DspHle(Memory::MemorySystem& memory);
~DspHle(); ~DspHle();
DspState GetDspState() const override; DspState GetDspState() const override;

View file

@ -45,6 +45,10 @@ void Source::Reset() {
state = {}; state = {};
} }
void Source::SetMemory(Memory::MemorySystem& memory) {
memory_system = &memory;
}
void Source::ParseConfig(SourceConfiguration::Configuration& config, void Source::ParseConfig(SourceConfiguration::Configuration& config,
const s16_le (&adpcm_coeffs)[16]) { const s16_le (&adpcm_coeffs)[16]) {
if (!config.dirty_raw) { if (!config.dirty_raw) {

View file

@ -14,6 +14,10 @@
#include "audio_core/interpolate.h" #include "audio_core/interpolate.h"
#include "common/common_types.h" #include "common/common_types.h"
namespace Memory {
class MemorySystem;
}
namespace AudioCore { namespace AudioCore {
namespace HLE { namespace HLE {
@ -35,6 +39,9 @@ public:
/// Resets internal state. /// Resets internal state.
void Reset(); void Reset();
/// Sets the memory system to read data from
void SetMemory(Memory::MemorySystem& memory);
/** /**
* This is called once every audio frame. This performs per-source processing every frame. * This is called once every audio frame. This performs per-source processing every frame.
* @param config The new configuration we've got for this Source from the application. * @param config The new configuration we've got for this Source from the application.
@ -56,6 +63,7 @@ public:
private: private:
const std::size_t source_id; const std::size_t source_id;
Memory::MemorySystem* memory_system;
StereoFrame16 current_frame; StereoFrame16 current_frame;
using Format = SourceConfiguration::Configuration::Format; using Format = SourceConfiguration::Configuration::Format;