shithub: cstory

Download patch

ref: 4763aecdbdbb6802d2b30ea93f62377dc7dd3f1f
parent: d3e18d795d59fb2f380dd1df1faf2d95dece8ef4
author: Clownacy <Clownacy@users.noreply.github.com>
date: Thu Sep 17 20:59:05 EDT 2020

Correct Lanczos array initialisation

I must have forgotten that Lanczos reads backwards too

--- a/src/Backends/Audio/SoftwareMixer/Mixer.cpp
+++ b/src/Backends/Audio/SoftwareMixer/Mixer.cpp
@@ -67,10 +67,6 @@
 	}
 
 #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 @@
 	// 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