From ac03facaa964da7ce001a501801bcd9e65001ea4 Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Fri, 8 Feb 2019 20:32:42 -0600 Subject: [PATCH] Add single sample push. --- apu/apu.cpp | 6 +++--- apu/resampler.h | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/apu/apu.cpp b/apu/apu.cpp index 2eae5b8e..6479d041 100644 --- a/apu/apu.cpp +++ b/apu/apu.cpp @@ -33,7 +33,7 @@ namespace SNES { #include "bapu/dsp/blargg_endian.h" CPU cpu; -} +} // namespace SNES namespace spc { @@ -57,7 +57,7 @@ static uint32 ratio_numerator = APU_NUMERATOR_NTSC; static uint32 ratio_denominator = APU_DENOMINATOR_NTSC; static double dynamic_rate_multiplier = 1.0; -} +} // namespace spc namespace msu { @@ -66,7 +66,7 @@ static const int buffer_size = MAX_SAMPLE_FRAMES * 6; static uint8 mixing_buffer[buffer_size]; static Resampler *resampler = NULL; static std::vector resample_buffer; -} +} // namespace msu static void UpdatePlaybackRate(void); static void SPCSnapshotCallback(void); diff --git a/apu/resampler.h b/apu/resampler.h index f82b3f45..322cb744 100644 --- a/apu/resampler.h +++ b/apu/resampler.h @@ -95,12 +95,27 @@ struct Resampler return true; } + inline void push(int16_t l, int16_t r) + { + if (space_empty() >= 2) + { + int end = start + size; + if (end > buffer_size) + end -= buffer_size; + buffer[end] = l; + buffer[end + 1] = r; + size += 2; + } + } + inline bool push(int16_t *src, int num_samples) { if (space_empty() < num_samples) return false; - int end = (start + size) % buffer_size; + int end = start + size; + if (end > buffer_size) + end -= buffer_size; int first_write_size = min(num_samples, buffer_size - end); memcpy(buffer + end, src, first_write_size * 2);