From 01b99eff98e6f752f82bc018052d1a3a1286dd65 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 9 Oct 2021 08:17:55 -0700 Subject: [PATCH] Audio: Cleanup buffer wrap code. This is a bit more straight-forward. --- Core/HW/StereoResampler.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Core/HW/StereoResampler.cpp b/Core/HW/StereoResampler.cpp index 1705191eef..3f0f973a0b 100644 --- a/Core/HW/StereoResampler.cpp +++ b/Core/HW/StereoResampler.cpp @@ -118,7 +118,8 @@ inline void ClampBufferToS16(s16 *out, const s32 *in, size_t size, s8 volShift) size -= 8; } #elif PPSSPP_ARCH(ARM_NEON) - int16x4_t signedVolShift = vdup_n_s16 (-volShift); // Can only dynamic-shift right, but by a signed integer + // Dynamic shifts can only be left, but it's signed - negate to shift right. + int16x4_t signedVolShift = vdup_n_s16(-volShift); while (size >= 8) { int32x4_t in1 = vld1q_s32(in); int32x4_t in2 = vld1q_s32(in + 4); @@ -281,10 +282,11 @@ void StereoResampler::PushSamples(const s32 *samples, unsigned int numSamples) { return; } - int over_bytes = numSamples * 4 - (m_maxBufsize * 2 - (indexW & INDEX_MASK)) * sizeof(short); - if (over_bytes > 0) { - ClampBufferToS16WithVolume(&m_buffer[indexW & INDEX_MASK], samples, (numSamples * 4 - over_bytes) / 2); - ClampBufferToS16WithVolume(&m_buffer[0], samples + (numSamples * 4 - over_bytes) / sizeof(short), over_bytes / 2); + // Check if we need to roll over to the start of the buffer during the copy. + int indexW_left_samples = m_maxBufsize * 2 - (indexW & INDEX_MASK); + if (numSamples * 2 > indexW_left_samples) { + ClampBufferToS16WithVolume(&m_buffer[indexW & INDEX_MASK], samples, indexW_left_samples); + ClampBufferToS16WithVolume(&m_buffer[0], samples + indexW_left_samples, numSamples * 2 - indexW_left_samples); } else { ClampBufferToS16WithVolume(&m_buffer[indexW & INDEX_MASK], samples, numSamples * 2); }