From 52e4a0f7450e5ecd8db7b9a881987110ee71cc00 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Wed, 27 Apr 2016 07:47:08 +0100 Subject: [PATCH] DSP: dsp::DSP semaphore indicates completion of audio frame config --- src/audio_core/audio_core.cpp | 7 ++-- src/audio_core/hle/dsp.cpp | 60 ++++++++++++++++++++++++-------- src/core/hle/service/dsp_dsp.cpp | 8 +++++ src/core/hle/service/dsp_dsp.h | 6 ++++ 4 files changed, 64 insertions(+), 17 deletions(-) diff --git a/src/audio_core/audio_core.cpp b/src/audio_core/audio_core.cpp index d42249ebd..46f196acd 100644 --- a/src/audio_core/audio_core.cpp +++ b/src/audio_core/audio_core.cpp @@ -24,12 +24,13 @@ static constexpr u64 audio_frame_ticks = 1310252ull; ///< Units: ARM11 cycles static void AudioTickCallback(u64 /*userdata*/, int cycles_late) { if (DSP::HLE::Tick()) { - // TODO(merry): Signal all the other interrupts as appropriate. DSP_DSP::SignalPipeInterrupt(DSP::HLE::DspPipe::Audio); - // HACK(merry): Added to prevent regressions. Will remove soon. - DSP_DSP::SignalPipeInterrupt(DSP::HLE::DspPipe::Binary); } + // TODO(merry): Signal all the other interrupts as appropriate. + // HACK(merry): Added to prevent regressions. Will remove soon. + DSP_DSP::SignalPipeInterrupt(DSP::HLE::DspPipe::Binary); + // Reschedule recurrent event CoreTiming::ScheduleEvent(audio_frame_ticks - cycles_late, tick_event); } diff --git a/src/audio_core/hle/dsp.cpp b/src/audio_core/hle/dsp.cpp index 0cdbdb06a..4c3091379 100644 --- a/src/audio_core/hle/dsp.cpp +++ b/src/audio_core/hle/dsp.cpp @@ -10,9 +10,13 @@ #include "audio_core/hle/source.h" #include "audio_core/sink.h" +#include "core/hle/service/dsp_dsp.h" + namespace DSP { namespace HLE { +// Region management + std::array g_regions; static size_t CurrentRegionIndex() { @@ -40,6 +44,8 @@ static SharedMemory& WriteRegion() { return g_regions[1 - CurrentRegionIndex()]; } +// Audio processing and mixing + static std::array sources = { Source(0), Source(1), Source(2), Source(3), Source(4), Source(5), Source(6), Source(7), Source(8), Source(9), Source(10), Source(11), @@ -47,19 +53,7 @@ static std::array sources = { Source(18), Source(19), Source(20), Source(21), Source(22), Source(23) }; -static std::unique_ptr sink; - -void Init() { - DSP::HLE::ResetPipes(); - for (auto& source : sources) { - source.Reset(); - } -} - -void Shutdown() { -} - -bool Tick() { +static StereoFrame16 GenerateCurrentFrame() { SharedMemory& read = ReadRegion(); SharedMemory& write = WriteRegion(); @@ -72,7 +66,45 @@ bool Tick() { } } - return true; + StereoFrame16 current_frame = {}; + + // TODO(merry): Reverb, Delay, Mixing + + return current_frame; +} + +// Audio output + +static std::unique_ptr sink; + +// Public interface + +void Init() { + DSP::HLE::ResetPipes(); + for (auto& source : sources) { + source.Reset(); + } +} + +void Shutdown() { +} + +bool Tick() { + bool signal_interrupt = false; + StereoFrame16 current_frame = {}; + + if (DSP_DSP::IsSemaphoreSignalled() && GetDspState() == DspState::On) { + // The ARM11 has finished writing to the shared memory region. + DSP_DSP::ResetSemaphore(); + + // Signal that we are done processing that shared memory region. + signal_interrupt = true; + current_frame = GenerateCurrentFrame(); + } + + // TODO(merry): Audio output + + return signal_interrupt; } void SetSink(std::unique_ptr sink_) { diff --git a/src/core/hle/service/dsp_dsp.cpp b/src/core/hle/service/dsp_dsp.cpp index 274fc751a..476cc7011 100644 --- a/src/core/hle/service/dsp_dsp.cpp +++ b/src/core/hle/service/dsp_dsp.cpp @@ -89,6 +89,14 @@ void SignalPipeInterrupt(DspPipe pipe) { interrupt_events.Signal(InterruptType::Pipe, pipe); } +void ResetSemaphore() { + semaphore_event->Clear(); +} + +bool IsSemaphoreSignalled() { + return semaphore_event->signaled; +} + /** * DSP_DSP::ConvertProcessAddressFromDspDram service function * Inputs: diff --git a/src/core/hle/service/dsp_dsp.h b/src/core/hle/service/dsp_dsp.h index 22f6687cc..74208b5e1 100644 --- a/src/core/hle/service/dsp_dsp.h +++ b/src/core/hle/service/dsp_dsp.h @@ -35,4 +35,10 @@ public: */ void SignalPipeInterrupt(DSP::HLE::DspPipe pipe); +/// Reset the dsp::DSP semaphore. +void ResetSemaphore(); + +/// Has the dsp::DSP semaphore been signalled? +bool IsSemaphoreSignalled(); + } // namespace DSP_DSP