From 4763aecdbdbb6802d2b30ea93f62377dc7dd3f1f Mon Sep 17 00:00:00 2001 From: Clownacy Date: Fri, 18 Sep 2020 00:59:05 +0100 Subject: [PATCH] Correct Lanczos array initialisation I must have forgotten that Lanczos reads backwards too --- src/Backends/Audio/SoftwareMixer/Mixer.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Backends/Audio/SoftwareMixer/Mixer.cpp b/src/Backends/Audio/SoftwareMixer/Mixer.cpp index 6ff49696..c059012d 100644 --- a/src/Backends/Audio/SoftwareMixer/Mixer.cpp +++ b/src/Backends/Audio/SoftwareMixer/Mixer.cpp @@ -67,10 +67,6 @@ Mixer_Sound* Mixer_CreateSound(unsigned int frequency, const unsigned char *samp } #ifdef LANCZOS_RESAMPLER - // Blank samples outside the array bounds (we'll deal with the other half later) - for (size_t i = 0; i < LANCZOS_KERNEL_RADIUS - 1; ++i) - sound->samples[i] = 0; - sound->samples += LANCZOS_KERNEL_RADIUS - 1; #endif @@ -118,11 +114,21 @@ void Mixer_PlaySound(Mixer_Sound *sound, bool looping) // either blank samples or repeated samples #ifdef LANCZOS_RESAMPLER if (looping) - for (size_t i = 0; i < LANCZOS_KERNEL_RADIUS; ++i) + { + for (int i = -LANCZOS_KERNEL_RADIUS + 1; i < 0; ++i) + sound->samples[i] = sound->samples[sound->frames + i]; + + for (int i = 0; i < LANCZOS_KERNEL_RADIUS; ++i) sound->samples[sound->frames + i] = sound->samples[i]; + } else - for (size_t i = 0; i < LANCZOS_KERNEL_RADIUS; ++i) + { + for (int i = -LANCZOS_KERNEL_RADIUS + 1; i < 0; ++i) + sound->samples[i] = 0; + + for (int i = 0; i < LANCZOS_KERNEL_RADIUS; ++i) sound->samples[sound->frames + i] = 0; + } #else sound->samples[sound->frames] = looping ? sound->samples[0] : 0; #endif