diff options
Diffstat (limited to 'src/audio_core/hle')
| -rw-r--r-- | src/audio_core/hle/dsp.cpp | 49 | ||||
| -rw-r--r-- | src/audio_core/hle/dsp.h | 18 |
2 files changed, 46 insertions, 21 deletions
diff --git a/src/audio_core/hle/dsp.cpp b/src/audio_core/hle/dsp.cpp index c89356edc..4d44bd2d9 100644 --- a/src/audio_core/hle/dsp.cpp +++ b/src/audio_core/hle/dsp.cpp @@ -2,14 +2,43 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include <memory> + #include "audio_core/hle/dsp.h" #include "audio_core/hle/pipe.h" +#include "audio_core/sink.h" namespace DSP { namespace HLE { -SharedMemory g_region0; -SharedMemory g_region1; +std::array<SharedMemory, 2> g_regions; + +static size_t CurrentRegionIndex() { + // The region with the higher frame counter is chosen unless there is wraparound. + // This function only returns a 0 or 1. + + if (g_regions[0].frame_counter == 0xFFFFu && g_regions[1].frame_counter != 0xFFFEu) { + // Wraparound has occured. + return 1; + } + + if (g_regions[1].frame_counter == 0xFFFFu && g_regions[0].frame_counter != 0xFFFEu) { + // Wraparound has occured. + return 0; + } + + return (g_regions[0].frame_counter > g_regions[1].frame_counter) ? 0 : 1; +} + +static SharedMemory& ReadRegion() { + return g_regions[CurrentRegionIndex()]; +} + +static SharedMemory& WriteRegion() { + return g_regions[1 - CurrentRegionIndex()]; +} + +static std::unique_ptr<AudioCore::Sink> sink; void Init() { DSP::HLE::ResetPipes(); @@ -22,20 +51,8 @@ bool Tick() { return true; } -SharedMemory& CurrentRegion() { - // The region with the higher frame counter is chosen unless there is wraparound. - - if (g_region0.frame_counter == 0xFFFFu && g_region1.frame_counter != 0xFFFEu) { - // Wraparound has occured. - return g_region1; - } - - if (g_region1.frame_counter == 0xFFFFu && g_region0.frame_counter != 0xFFFEu) { - // Wraparound has occured. - return g_region0; - } - - return (g_region0.frame_counter > g_region1.frame_counter) ? g_region0 : g_region1; +void SetSink(std::unique_ptr<AudioCore::Sink> sink_) { + sink = std::move(sink_); } } // namespace HLE diff --git a/src/audio_core/hle/dsp.h b/src/audio_core/hle/dsp.h index c76350bdd..4f2410c27 100644 --- a/src/audio_core/hle/dsp.h +++ b/src/audio_core/hle/dsp.h @@ -4,7 +4,9 @@ #pragma once +#include <array> #include <cstddef> +#include <memory> #include <type_traits> #include "audio_core/hle/common.h" @@ -14,6 +16,10 @@ #include "common/common_types.h" #include "common/swap.h" +namespace AudioCore { +class Sink; +} + namespace DSP { namespace HLE { @@ -30,10 +36,9 @@ namespace HLE { struct SharedMemory; constexpr VAddr region0_base = 0x1FF50000; -extern SharedMemory g_region0; - constexpr VAddr region1_base = 0x1FF70000; -extern SharedMemory g_region1; + +extern std::array<SharedMemory, 2> g_regions; /** * The DSP is native 16-bit. The DSP also appears to be big-endian. When reading 32-bit numbers from @@ -535,8 +540,11 @@ void Shutdown(); */ bool Tick(); -/// Returns a mutable reference to the current region. Current region is selected based on the frame counter. -SharedMemory& CurrentRegion(); +/** + * Set the output sink. This must be called before calling Tick(). + * @param sink The sink to which audio will be output to. + */ +void SetSink(std::unique_ptr<AudioCore::Sink> sink); } // namespace HLE } // namespace DSP |
