diff options
author | Chris Robinson <[email protected]> | 2018-04-03 10:15:35 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-04-03 10:15:35 -0700 |
commit | 869637af2ee5882dbe5b0016d1091e9e0bc2a69a (patch) | |
tree | 90f1061052599ad7138a3382f4580cb556bda75d /Alc/effects | |
parent | 414b56edec5441211dc924fef365c54267c04f1c (diff) |
Apply biquad and T60 filters using transposed direct form II
Diffstat (limited to 'Alc/effects')
-rw-r--r-- | Alc/effects/echo.c | 22 | ||||
-rw-r--r-- | Alc/effects/reverb.c | 23 |
2 files changed, 17 insertions, 28 deletions
diff --git a/Alc/effects/echo.c b/Alc/effects/echo.c index a3a4e120..282aa1d7 100644 --- a/Alc/effects/echo.c +++ b/Alc/effects/echo.c @@ -155,14 +155,12 @@ static ALvoid ALechoState_process(ALechoState *state, ALsizei SamplesToDo, const const ALsizei tap2 = state->Tap[1].delay; ALfloat *restrict delaybuf = state->SampleBuffer; ALsizei offset = state->Offset; - ALfloat x[2], y[2], in, out; + ALfloat z1, z2, in, out; ALsizei base; ALsizei c, i; - x[0] = state->Filter.x[0]; - x[1] = state->Filter.x[1]; - y[0] = state->Filter.y[0]; - y[1] = state->Filter.y[1]; + z1 = state->Filter.z1; + z2 = state->Filter.z2; for(base = 0;base < SamplesToDo;) { alignas(16) ALfloat temps[2][128]; @@ -182,11 +180,9 @@ static ALvoid ALechoState_process(ALechoState *state, ALsizei SamplesToDo, const * feedback attenuation. */ in = temps[1][i]; - out = in*state->Filter.b0 + - x[0]*state->Filter.b1 + x[1]*state->Filter.b2 - - y[0]*state->Filter.a1 - y[1]*state->Filter.a2; - x[1] = x[0]; x[0] = in; - y[1] = y[0]; y[0] = out; + out = in*state->Filter.b0 + z1; + z1 = in*state->Filter.b1 - out*state->Filter.a1 + z2; + z2 = in*state->Filter.b2 - out*state->Filter.a2; delaybuf[offset&mask] += out * state->FeedGain; offset++; @@ -198,10 +194,8 @@ static ALvoid ALechoState_process(ALechoState *state, ALsizei SamplesToDo, const base += td; } - state->Filter.x[0] = x[0]; - state->Filter.x[1] = x[1]; - state->Filter.y[0] = y[0]; - state->Filter.y[1] = y[1]; + state->Filter.z1 = z1; + state->Filter.z2 = z2; state->Offset = offset; } diff --git a/Alc/effects/reverb.c b/Alc/effects/reverb.c index 0d486e63..831e4a3a 100644 --- a/Alc/effects/reverb.c +++ b/Alc/effects/reverb.c @@ -234,11 +234,9 @@ typedef struct T60Filter { ALfloat HFCoeffs[3]; ALfloat LFCoeffs[3]; - /* The HF and LF filters each keep a state of the last input and last - * output sample. - */ - ALfloat HFState[2]; - ALfloat LFState[2]; + /* The HF and LF filters each keep a delay component. */ + ALfloat HFState; + ALfloat LFState; } T60Filter; typedef struct EarlyReflections { @@ -407,10 +405,8 @@ static void ALreverbState_Construct(ALreverbState *state) state->Late.T60[i].HFCoeffs[j] = 0.0f; state->Late.T60[i].LFCoeffs[j] = 0.0f; } - state->Late.T60[i].HFState[0] = 0.0f; - state->Late.T60[i].HFState[1] = 0.0f; - state->Late.T60[i].LFState[0] = 0.0f; - state->Late.T60[i].LFState[1] = 0.0f; + state->Late.T60[i].HFState = 0.0f; + state->Late.T60[i].LFState = 0.0f; } for(i = 0;i < NUM_LINES;i++) @@ -1443,9 +1439,8 @@ DECL_TEMPLATE(Faded) static inline ALfloat FirstOrderFilter(const ALfloat in, const ALfloat *restrict coeffs, ALfloat *restrict state) { - ALfloat out = coeffs[0]*in + coeffs[1]*state[0] + coeffs[2]*state[1]; - state[0] = in; - state[1] = out; + ALfloat out = coeffs[0]*in + *state; + *state = coeffs[1]*in + coeffs[2]*out; return out; } @@ -1456,8 +1451,8 @@ static inline void LateT60Filter(ALfloat *restrict out, const ALfloat *restrict ALsizei i; for(i = 0;i < NUM_LINES;i++) out[i] = FirstOrderFilter( - FirstOrderFilter(in[i], filter[i].HFCoeffs, filter[i].HFState), - filter[i].LFCoeffs, filter[i].LFState + FirstOrderFilter(in[i], filter[i].HFCoeffs, &filter[i].HFState), + filter[i].LFCoeffs, &filter[i].LFState ); } |