diff options
author | Simon Howard | 2008-02-23 22:51:17 +0000 |
---|---|---|
committer | Simon Howard | 2008-02-23 22:51:17 +0000 |
commit | 8c084734707060e05476f74edb069d76e05b5a06 (patch) | |
tree | bc587d4081db570bd7cb459386f765b54679a11d /src/i_sdlsound.c | |
parent | 8764a4a9cd040906651180771d7c65d334dc1774 (diff) | |
download | chocolate-doom-8c084734707060e05476f74edb069d76e05b5a06.tar.gz chocolate-doom-8c084734707060e05476f74edb069d76e05b5a06.tar.bz2 chocolate-doom-8c084734707060e05476f74edb069d76e05b5a06.zip |
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
Diffstat (limited to 'src/i_sdlsound.c')
-rw-r--r-- | src/i_sdlsound.c | 28 |
1 files changed, 28 insertions, 0 deletions
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 */ } } |