commit 8c084734707060e05476f74edb069d76e05b5a06
Author: Simon Howard <fraggle@gmail.com>
AuthorDate: Sat Feb 23 22:51:17 2008 +0000
Commit: Simon Howard <fraggle@gmail.com>
CommitDate: Sat Feb 23 22:51:17 2008 +0000
Perform a low-pass filter of converted sounds to filter out
high-frequency noise from the upscaling process.
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 1088
---
src/i_sdlsound.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/src/i_sdlsound.c b/src/i_sdlsound.c
index f89c2aea..b63be648 100644
--- a/src/i_sdlsound.c
+++ b/src/i_sdlsound.c
@@ -46,6 +46,7 @@
#include "doomdef.h"
+#define LOW_PASS_FILTER
#define NUM_CHANNELS 16
static boolean sound_initialised = false;
@@ -255,6 +256,33 @@ static void ExpandSoundData_SDL(byte *data,
expanded[i * 2] = expanded[i * 2 + 1] = sample;
}
+
+#ifdef LOW_PASS_FILTER
+ // Perform a low-pass filter on the upscaled sound to filter
+ // out high-frequency noise from the conversion process.
+
+ {
+ float rc, dt, alpha;
+
+ // Low-pass filter for cutoff frequency f:
+ //
+ // For sampling rate r, dt = 1 / r
+ // rc = 1 / 2*pi*f
+ // alpha = dt / (rc + dt)
+
+ // Filter to the half sample rate of the original sound effect
+ // (maximum frequency, by nyquist)
+
+ dt = 1.0 / mixer_freq;
+ rc = 1.0 / (3.14 * samplerate);
+ alpha = dt / (rc + dt);
+
+ for (i=1; i<expanded_length; ++i)
+ {
+ expanded[i] = alpha * expanded[i] + (1 - alpha) * expanded[i-1];
+ }
+ }
+#endif /* #ifdef LOW_PASS_FILTER */
}
}