diff options
author | Chris Robinson <[email protected]> | 2018-04-24 00:17:07 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-04-24 00:17:07 -0700 |
commit | 510efae0668181676902de345bd1f44edfa0adfa (patch) | |
tree | 5344aa7b0070413631656059fa685389ddc979a3 /Alc | |
parent | b3ba90f5fa533450e5335dc102c3f96fb7708d8f (diff) |
Don't specialize biquad processing for a single sample
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/filters/filter.c | 65 |
1 files changed, 28 insertions, 37 deletions
diff --git a/Alc/filters/filter.c b/Alc/filters/filter.c index 65fb08e7..2b370f89 100644 --- a/Alc/filters/filter.c +++ b/Alc/filters/filter.c @@ -96,43 +96,34 @@ void BiquadFilter_setParams(BiquadFilter *filter, BiquadType type, ALfloat gain, void BiquadFilter_processC(BiquadFilter *filter, ALfloat *restrict dst, const ALfloat *restrict src, ALsizei numsamples) { - if(LIKELY(numsamples > 1)) - { - const ALfloat a1 = filter->a1; - const ALfloat a2 = filter->a2; - const ALfloat b0 = filter->b0; - const ALfloat b1 = filter->b1; - const ALfloat b2 = filter->b2; - ALfloat z1 = filter->z1; - ALfloat z2 = filter->z2; - ALsizei i; - - /* Processing loop is transposed direct form II. This requires less - * storage versus direct form I (only two delay components, instead of - * a four-sample history; the last two inputs and outputs), and works - * better for floating-point which favors summing similarly-sized - * values while being less bothered by overflow. - * - * See: http://www.earlevel.com/main/2003/02/28/biquads/ - */ - for(i = 0;i < numsamples;i++) - { - ALfloat input = src[i]; - ALfloat output = input*b0 + z1; - z1 = input*b1 - output*a1 + z2; - z2 = input*b2 - output*a2; - dst[i] = output; - } - - filter->z1 = z1; - filter->z2 = z2; - } - else if(numsamples == 1) + const ALfloat a1 = filter->a1; + const ALfloat a2 = filter->a2; + const ALfloat b0 = filter->b0; + const ALfloat b1 = filter->b1; + const ALfloat b2 = filter->b2; + ALfloat z1 = filter->z1; + ALfloat z2 = filter->z2; + ALsizei i; + + ASSUME(numsamples > 0); + + /* Processing loop is Transposed Direct Form II. This requires less storage + * compared to Direct Form I (only two delay components, instead of a four- + * sample history; the last two inputs and outputs), and works better for + * floating-point which favors summing similarly-sized values while being + * less bothered by overflow. + * + * See: http://www.earlevel.com/main/2003/02/28/biquads/ + */ + for(i = 0;i < numsamples;i++) { - ALfloat input = *src; - ALfloat output = input*filter->b0 + filter->z1; - filter->z1 = input*filter->b1 - output*filter->a1 + filter->z2; - filter->z2 = input*filter->b2 - output*filter->a2; - *dst = output; + ALfloat input = src[i]; + ALfloat output = input*b0 + z1; + z1 = input*b1 - output*a1 + z2; + z2 = input*b2 - output*a2; + dst[i] = output; } + + filter->z1 = z1; + filter->z2 = z2; } |