aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/effects/autowah.c26
-rw-r--r--Alc/effects/modulator.c11
-rw-r--r--OpenAL32/Include/alFilter.h15
-rw-r--r--OpenAL32/alFilter.c85
4 files changed, 69 insertions, 68 deletions
diff --git a/Alc/effects/autowah.c b/Alc/effects/autowah.c
index 6770f719..e97083e0 100644
--- a/Alc/effects/autowah.c
+++ b/Alc/effects/autowah.c
@@ -92,6 +92,7 @@ static ALvoid ALautowahState_process(ALautowahState *state, ALuint SamplesToDo,
for(it = 0;it < td;it++)
{
ALfloat smp = SamplesIn[it+base];
+ ALfloat a[3], b[3];
ALfloat alpha, w0;
ALfloat amplitude;
ALfloat cutoff;
@@ -117,19 +118,18 @@ static ALvoid ALautowahState_process(ALautowahState *state, ALuint SamplesToDo,
/* FIXME: Resonance controls the resonant peak, or Q. How? Not sure
* that Q = resonance*0.1. */
alpha = sinf(w0) / (2.0f * state->Resonance*0.1f);
- state->LowPass.b[0] = (1.0f - cosf(w0)) / 2.0f;
- state->LowPass.b[1] = 1.0f - cosf(w0);
- state->LowPass.b[2] = (1.0f - cosf(w0)) / 2.0f;
- state->LowPass.a[0] = 1.0f + alpha;
- state->LowPass.a[1] = -2.0f * cosf(w0);
- state->LowPass.a[2] = 1.0f - alpha;
-
- state->LowPass.b[2] /= state->LowPass.a[0];
- state->LowPass.b[1] /= state->LowPass.a[0];
- state->LowPass.b[0] /= state->LowPass.a[0];
- state->LowPass.a[2] /= state->LowPass.a[0];
- state->LowPass.a[1] /= state->LowPass.a[0];
- state->LowPass.a[0] /= state->LowPass.a[0];
+ b[0] = (1.0f - cosf(w0)) / 2.0f;
+ b[1] = 1.0f - cosf(w0);
+ b[2] = (1.0f - cosf(w0)) / 2.0f;
+ a[0] = 1.0f + alpha;
+ a[1] = -2.0f * cosf(w0);
+ a[2] = 1.0f - alpha;
+
+ state->LowPass.a1 = a[1] / a[0];
+ state->LowPass.a2 = a[2] / a[0];
+ state->LowPass.b1 = b[1] / a[0];
+ state->LowPass.b2 = b[2] / a[0];
+ state->LowPass.input_gain = b[0] / a[0];
temps[it] = ALfilterState_processSingle(&state->LowPass, smp);
}
diff --git a/Alc/effects/modulator.c b/Alc/effects/modulator.c
index dceb408e..32d25c76 100644
--- a/Alc/effects/modulator.c
+++ b/Alc/effects/modulator.c
@@ -142,12 +142,11 @@ static ALvoid ALmodulatorState_update(ALmodulatorState *state, ALCdevice *Device
cw = cosf(F_TAU * Slot->EffectProps.Modulator.HighPassCutoff / Device->Frequency);
a = (2.0f-cw) - sqrtf(powf(2.0f-cw, 2.0f) - 1.0f);
- state->Filter.b[0] = a;
- state->Filter.b[1] = -a;
- state->Filter.b[2] = 0.0f;
- state->Filter.a[0] = 1.0f;
- state->Filter.a[1] = -a;
- state->Filter.a[2] = 0.0f;
+ state->Filter.a1 = -a;
+ state->Filter.a2 = 0.0f;
+ state->Filter.b1 = -a;
+ state->Filter.b2 = 0.0f;
+ state->Filter.input_gain = a;
ComputeAmbientGains(Device, Slot->Gain, state->Gain);
}
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;
}