diff options
author | Chris Robinson <[email protected]> | 2016-01-23 03:38:15 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2016-01-23 03:38:15 -0800 |
commit | 94816d007375295a8d767b06a483a060be292692 (patch) | |
tree | f66f29a492d2b4d93dc3b857f6003faa0f2cb44b /OpenAL32 | |
parent | 352d9afd642e94651e69dbb28ade50eea88eae0d (diff) |
Reorder filterstate properties
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/Include/alFilter.h | 15 | ||||
-rw-r--r-- | OpenAL32/alFilter.c | 85 |
2 files changed, 51 insertions, 49 deletions
diff --git a/OpenAL32/Include/alFilter.h b/OpenAL32/Include/alFilter.h index fa86af27..6f44e3b7 100644 --- a/OpenAL32/Include/alFilter.h +++ b/OpenAL32/Include/alFilter.h @@ -42,8 +42,9 @@ typedef enum ALfilterType { typedef struct ALfilterState { ALfloat x[2]; /* History of two last input samples */ ALfloat y[2]; /* History of two last output samples */ - ALfloat a[3]; /* Transfer function coefficients "a" */ - ALfloat b[3]; /* Transfer function coefficients "b" */ + ALfloat a1, a2; /* Transfer function coefficients "a" (a0 is pre-applied) */ + ALfloat b1, b2; /* Transfer function coefficients "b" (b0 is input_gain) */ + ALfloat input_gain; void (*process)(struct ALfilterState *self, ALfloat *restrict dst, const ALfloat *src, ALuint numsamples); } ALfilterState; @@ -82,11 +83,11 @@ inline ALfloat ALfilterState_processSingle(ALfilterState *filter, ALfloat sample { ALfloat outsmp; - outsmp = filter->b[0] * sample + - filter->b[1] * filter->x[0] + - filter->b[2] * filter->x[1] - - filter->a[1] * filter->y[0] - - filter->a[2] * filter->y[1]; + outsmp = filter->input_gain * sample + + filter->b1 * filter->x[0] + + filter->b2 * filter->x[1] - + filter->a1 * filter->y[0] - + filter->a2 * filter->y[1]; filter->x[1] = filter->x[0]; filter->x[0] = sample; filter->y[1] = filter->y[0]; diff --git a/OpenAL32/alFilter.c b/OpenAL32/alFilter.c index 6d088a45..4280f41e 100644 --- a/OpenAL32/alFilter.c +++ b/OpenAL32/alFilter.c @@ -337,6 +337,8 @@ void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat g { ALfloat alpha, sqrtgain_alpha_2; ALfloat w0, sin_w0, cos_w0; + ALfloat a[3] = { 1.0f, 0.0f, 0.0f }; + ALfloat b[3] = { 1.0f, 0.0f, 0.0f }; // Limit gain to -100dB gain = maxf(gain, 0.00001f); @@ -351,64 +353,63 @@ void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat g { case ALfilterType_HighShelf: 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 ); - filter->b[2] = gain*((gain+1.0f) + (gain-1.0f)*cos_w0 - sqrtgain_alpha_2); - filter->a[0] = (gain+1.0f) - (gain-1.0f)*cos_w0 + sqrtgain_alpha_2; - filter->a[1] = 2.0f* ((gain-1.0f) - (gain+1.0f)*cos_w0 ); - filter->a[2] = (gain+1.0f) - (gain-1.0f)*cos_w0 - sqrtgain_alpha_2; + b[0] = gain*((gain+1.0f) + (gain-1.0f)*cos_w0 + sqrtgain_alpha_2); + b[1] = -2.0f*gain*((gain-1.0f) + (gain+1.0f)*cos_w0 ); + b[2] = gain*((gain+1.0f) + (gain-1.0f)*cos_w0 - sqrtgain_alpha_2); + a[0] = (gain+1.0f) - (gain-1.0f)*cos_w0 + sqrtgain_alpha_2; + a[1] = 2.0f* ((gain-1.0f) - (gain+1.0f)*cos_w0 ); + a[2] = (gain+1.0f) - (gain-1.0f)*cos_w0 - sqrtgain_alpha_2; break; case ALfilterType_LowShelf: 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 ); - filter->b[2] = gain*((gain+1.0f) - (gain-1.0f)*cos_w0 - sqrtgain_alpha_2); - filter->a[0] = (gain+1.0f) + (gain-1.0f)*cos_w0 + sqrtgain_alpha_2; - filter->a[1] = -2.0f* ((gain-1.0f) + (gain+1.0f)*cos_w0 ); - filter->a[2] = (gain+1.0f) + (gain-1.0f)*cos_w0 - sqrtgain_alpha_2; + b[0] = gain*((gain+1.0f) - (gain-1.0f)*cos_w0 + sqrtgain_alpha_2); + b[1] = 2.0f*gain*((gain-1.0f) - (gain+1.0f)*cos_w0 ); + b[2] = gain*((gain+1.0f) - (gain-1.0f)*cos_w0 - sqrtgain_alpha_2); + a[0] = (gain+1.0f) + (gain-1.0f)*cos_w0 + sqrtgain_alpha_2; + a[1] = -2.0f* ((gain-1.0f) + (gain+1.0f)*cos_w0 ); + a[2] = (gain+1.0f) + (gain-1.0f)*cos_w0 - sqrtgain_alpha_2; break; case ALfilterType_Peaking: gain = sqrtf(gain); - filter->b[0] = 1.0f + alpha * gain; - filter->b[1] = -2.0f * cos_w0; - filter->b[2] = 1.0f - alpha * gain; - filter->a[0] = 1.0f + alpha / gain; - filter->a[1] = -2.0f * cos_w0; - filter->a[2] = 1.0f - alpha / gain; + b[0] = 1.0f + alpha * gain; + b[1] = -2.0f * cos_w0; + b[2] = 1.0f - alpha * gain; + a[0] = 1.0f + alpha / gain; + a[1] = -2.0f * cos_w0; + a[2] = 1.0f - alpha / gain; break; case ALfilterType_LowPass: - 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; - filter->a[0] = 1.0f + alpha; - filter->a[1] = -2.0f * cos_w0; - filter->a[2] = 1.0f - alpha; + b[0] = (1.0f - cos_w0) / 2.0f; + b[1] = 1.0f - cos_w0; + b[2] = (1.0f - cos_w0) / 2.0f; + a[0] = 1.0f + alpha; + a[1] = -2.0f * cos_w0; + a[2] = 1.0f - alpha; break; case ALfilterType_HighPass: - 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; - filter->a[0] = 1.0f + alpha; - filter->a[1] = -2.0f * cos_w0; - filter->a[2] = 1.0f - alpha; + b[0] = (1.0f + cos_w0) / 2.0f; + b[1] = -(1.0f + cos_w0); + b[2] = (1.0f + cos_w0) / 2.0f; + a[0] = 1.0f + alpha; + a[1] = -2.0f * cos_w0; + a[2] = 1.0f - alpha; break; case ALfilterType_BandPass: - filter->b[0] = alpha; - filter->b[1] = 0; - filter->b[2] = -alpha; - filter->a[0] = 1.0f + alpha; - filter->a[1] = -2.0f * cos_w0; - filter->a[2] = 1.0f - alpha; + b[0] = alpha; + b[1] = 0; + b[2] = -alpha; + a[0] = 1.0f + alpha; + a[1] = -2.0f * cos_w0; + a[2] = 1.0f - alpha; break; } - filter->b[2] /= filter->a[0]; - filter->b[1] /= filter->a[0]; - filter->b[0] /= filter->a[0]; - filter->a[2] /= filter->a[0]; - filter->a[1] /= filter->a[0]; - filter->a[0] /= filter->a[0]; + filter->a1 = a[1] / a[0]; + filter->a2 = a[2] / a[0]; + filter->b1 = b[1] / a[0]; + filter->b2 = b[2] / a[0]; + filter->input_gain = b[0] / a[0]; filter->process = ALfilterState_processC; } |