diff options
Diffstat (limited to '')
-rw-r--r-- | src/audio_core/stream.cpp | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp index 82bff4b9e..689f51a1d 100644 --- a/src/audio_core/stream.cpp +++ b/src/audio_core/stream.cpp @@ -7,30 +7,37 @@ #include "core/core_timing.h" #include "core/core_timing_util.h" +#include "audio_core/sink.h" +#include "audio_core/sink_details.h" #include "audio_core/stream.h" namespace AudioCore { constexpr size_t MaxAudioBufferCount{32}; -/// Returns the sample size for the specified audio stream format -static size_t SampleSizeFromFormat(Stream::Format format) { +u32 Stream::GetNumChannels() const { switch (format) { - case Stream::Format::Mono16: + case Format::Mono16: + return 1; + case Format::Stereo16: return 2; - case Stream::Format::Stereo16: - return 4; - case Stream::Format::Multi51Channel16: - return 12; - }; - + case Format::Multi51Channel16: + return 6; + } LOG_CRITICAL(Audio, "Unimplemented format={}", static_cast<u32>(format)); UNREACHABLE(); return {}; } -Stream::Stream(int sample_rate, Format format, ReleaseCallback&& release_callback) - : sample_rate{sample_rate}, format{format}, release_callback{std::move(release_callback)} { +u32 Stream::GetSampleSize() const { + return GetNumChannels() * 2; +} + +Stream::Stream(u32 sample_rate, Format format, ReleaseCallback&& release_callback, + SinkStream& sink_stream) + : sample_rate{sample_rate}, format{format}, release_callback{std::move(release_callback)}, + sink_stream{sink_stream} { + release_event = CoreTiming::RegisterEvent( "Stream::Release", [this](u64 userdata, int cycles_late) { ReleaseActiveBuffer(); }); } @@ -45,7 +52,7 @@ void Stream::Stop() { } s64 Stream::GetBufferReleaseCycles(const Buffer& buffer) const { - const size_t num_samples{buffer.GetData().size() / SampleSizeFromFormat(format)}; + const size_t num_samples{buffer.GetData().size() / GetSampleSize()}; return CoreTiming::usToCycles((static_cast<u64>(num_samples) * 1000000) / sample_rate); } @@ -68,6 +75,10 @@ void Stream::PlayNextBuffer() { active_buffer = queued_buffers.front(); queued_buffers.pop(); + sink_stream.EnqueueSamples(GetNumChannels(), + reinterpret_cast<const s16*>(active_buffer->GetData().data()), + active_buffer->GetData().size() / GetSampleSize()); + CoreTiming::ScheduleEventThreadsafe(GetBufferReleaseCycles(*active_buffer), release_event, {}); } |