diff options
author | Chris Robinson <[email protected]> | 2015-11-01 04:43:55 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2015-11-01 05:41:06 -0800 |
commit | c57f57192067e2d68cfe4ab0fc9479d2453bfbda (patch) | |
tree | fb9dabd6296c87ff72f4271774ae9951898d9227 /OpenAL32/alFilter.c | |
parent | f094d94608e00b1b08bd8c607d16651072323bb5 (diff) |
Pass in the Q parameter for setting the filter parameters
Also better handle the peaking filter gain.
Diffstat (limited to 'OpenAL32/alFilter.c')
-rw-r--r-- | OpenAL32/alFilter.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/OpenAL32/alFilter.c b/OpenAL32/alFilter.c index bced3a7f..3cf82c32 100644 --- a/OpenAL32/alFilter.c +++ b/OpenAL32/alFilter.c @@ -32,6 +32,8 @@ extern inline struct ALfilter *LookupFilter(ALCdevice *device, ALuint id); extern inline struct ALfilter *RemoveFilter(ALCdevice *device, ALuint id); extern inline ALfloat ALfilterState_processSingle(ALfilterState *filter, ALfloat sample); +extern inline ALfloat calc_rcpQ_from_slope(ALfloat gain, ALfloat slope); +extern inline ALfloat calc_rcpQ_from_bandwidth(ALfloat freq_mult, ALfloat bandwidth); static void InitFilterParams(ALfilter *filter, ALenum type); @@ -336,7 +338,7 @@ void ALfilterState_clear(ALfilterState *filter) filter->y[1] = 0.0f; } -void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat gain, ALfloat freq_mult, ALfloat bandwidth) +void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat gain, ALfloat freq_mult, ALfloat rcpQ) { ALfloat alpha, sqrtgain_alpha_2; ALfloat w0, sin_w0, cos_w0; @@ -347,12 +349,12 @@ void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat g w0 = F_TAU * freq_mult; sin_w0 = sinf(w0); cos_w0 = cosf(w0); + alpha = sin_w0/2.0f * rcpQ; /* Calculate filter coefficients depending on filter type */ switch(type) { case ALfilterType_HighShelf: - alpha = sin_w0/2.0f*sqrtf((gain + 1.0f/gain)*(1.0f/0.75f - 1.0f) + 2.0f); sqrtgain_alpha_2 = 2.0f * sqrtf(gain) * alpha; filter->b[0] = gain*((gain+1.0f) + (gain-1.0f)*cos_w0 + sqrtgain_alpha_2); filter->b[1] = -2.0f*gain*((gain-1.0f) + (gain+1.0f)*cos_w0 ); @@ -362,7 +364,6 @@ void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat g filter->a[2] = (gain+1.0f) - (gain-1.0f)*cos_w0 - sqrtgain_alpha_2; break; case ALfilterType_LowShelf: - alpha = sin_w0/2.0f*sqrtf((gain + 1.0f/gain)*(1.0f/0.75f - 1.0f) + 2.0f); sqrtgain_alpha_2 = 2.0f * sqrtf(gain) * alpha; filter->b[0] = gain*((gain+1.0f) - (gain-1.0f)*cos_w0 + sqrtgain_alpha_2); filter->b[1] = 2.0f*gain*((gain-1.0f) - (gain+1.0f)*cos_w0 ); @@ -372,7 +373,7 @@ void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat g filter->a[2] = (gain+1.0f) + (gain-1.0f)*cos_w0 - sqrtgain_alpha_2; break; case ALfilterType_Peaking: - alpha = sin_w0 * sinhf(logf(2.0f) / 2.0f * bandwidth * w0 / sin_w0); + gain = sqrtf(gain); filter->b[0] = 1.0f + alpha * gain; filter->b[1] = -2.0f * cos_w0; filter->b[2] = 1.0f - alpha * gain; @@ -382,7 +383,6 @@ void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat g break; case ALfilterType_LowPass: - alpha = sin_w0 * sinhf(logf(2.0f) / 2.0f * bandwidth * w0 / sin_w0); filter->b[0] = (1.0f - cos_w0) / 2.0f; filter->b[1] = 1.0f - cos_w0; filter->b[2] = (1.0f - cos_w0) / 2.0f; @@ -391,7 +391,6 @@ void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat g filter->a[2] = 1.0f - alpha; break; case ALfilterType_HighPass: - alpha = sin_w0 * sinhf(logf(2.0f) / 2.0f * bandwidth * w0 / sin_w0); filter->b[0] = (1.0f + cos_w0) / 2.0f; filter->b[1] = -(1.0f + cos_w0); filter->b[2] = (1.0f + cos_w0) / 2.0f; @@ -400,7 +399,6 @@ void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat g filter->a[2] = 1.0f - alpha; break; case ALfilterType_BandPass: - alpha = sin_w0 * sinhf(logf(2.0f) / 2.0f * bandwidth * w0 / sin_w0); filter->b[0] = alpha; filter->b[1] = 0; filter->b[2] = -alpha; |