diff options
author | Chris Robinson <[email protected]> | 2013-06-06 03:24:44 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2013-06-06 03:24:44 -0700 |
commit | 647398d7c6b6198ca85675ae75ff0debc275fc3b (patch) | |
tree | 701ec596eefac86290f9a5c531de62d7562dd807 /OpenAL32 | |
parent | dcefeac6e6afd5c21e0e463c6f780f14ea8eeab5 (diff) |
Use ALfilterState for the distortion effect filters
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/Include/alFilter.h | 8 | ||||
-rw-r--r-- | OpenAL32/alFilter.c | 19 |
2 files changed, 27 insertions, 0 deletions
diff --git a/OpenAL32/Include/alFilter.h b/OpenAL32/Include/alFilter.h index 6e9abd6a..690a496b 100644 --- a/OpenAL32/Include/alFilter.h +++ b/OpenAL32/Include/alFilter.h @@ -9,10 +9,18 @@ extern "C" { #define LOWPASSFREQREF (5000) + +/* Filters implementation is based on the "Cookbook formulae for audio * + * EQ biquad filter coefficients" by Robert Bristow-Johnson * + * http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt */ + typedef enum ALfilterType { ALfilterType_HighShelf, ALfilterType_LowShelf, ALfilterType_Peaking, + + ALfilterType_LowPass, + ALfilterType_BandPass, } ALfilterType; typedef struct ALfilterState { diff --git a/OpenAL32/alFilter.c b/OpenAL32/alFilter.c index abfcbdd4..f15a2800 100644 --- a/OpenAL32/alFilter.c +++ b/OpenAL32/alFilter.c @@ -392,6 +392,25 @@ void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat g filter->a[1] = -2.0f * cosf(w0); filter->a[2] = 1.0f - alpha / gain; break; + + case ALfilterType_LowPass: + alpha = sinf(w0) * sinhf(logf(2.0f) / 2.0f * bandwidth * w0 / sinf(w0)); + filter->b[0] = (1.0f - cosf(w0)) / 2.0f; + filter->b[1] = 1.0f - cosf(w0); + filter->b[2] = (1.0f - cosf(w0)) / 2.0f; + filter->a[0] = 1.0f + alpha; + filter->a[1] = -2.0f * cosf(w0); + filter->a[2] = 1.0f - alpha; + break; + case ALfilterType_BandPass: + alpha = sinf(w0) * sinhf(logf(2.0f) / 2.0f * bandwidth * w0 / sinf(w0)); + filter->b[0] = alpha; + filter->b[1] = 0; + filter->b[2] = -alpha; + filter->a[0] = 1.0f + alpha; + filter->a[1] = -2.0f * cosf(w0); + filter->a[2] = 1.0f - alpha; + break; } filter->b[2] /= filter->a[0]; |