shithub: choc

Download patch

ref: 5e9a9a52dbebabda79f221caf318dd8fba4b0781
parent: 05cafe91729446ebd28f3fdab2302277c53530d1
author: Simon Howard <fraggle@gmail.com>
date: Sat Aug 7 12:07:00 EDT 2010

Fix sound resampling low pass filter.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 1951

--- a/src/i_sdlsound.c
+++ b/src/i_sdlsound.c
@@ -244,12 +244,15 @@
             // (maximum frequency, by nyquist)
 
             dt = 1.0f / mixer_freq;
-            rc = 1.0f / (3.14f * samplerate);
+            rc = 1.0f / (2 * 3.14f * samplerate);
             alpha = dt / (rc + dt);
 
-            for (i=1; i<expanded_length; ++i) 
+            // Both channels are processed in parallel, hence [i-2]:
+
+            for (i=2; i<expanded_length * 2; ++i)
             {
-                expanded[i] = (Sint16) (alpha * expanded[i] + (1 - alpha) * expanded[i-1]);
+                expanded[i] = (Sint16) (alpha * expanded[i]
+                                      + (1 - alpha) * expanded[i-2]);
             }
         }
 #endif /* #ifdef LOW_PASS_FILTER */