BiquadFilter.h — Biquad Filters

The BiquadFilter module provides a biquad filter implementation. A biquad filter is a second-order linear Infinite Impulse Response (IIR) filter with two poles and two zeros. Biquad filters are often cascaded together and used in place of individual higher-order filters because they are much less sensitive to quantization of their coefficients.

The basic biquad filter implementation is known as Direct-Form I (or DF-I):

\[y_{[n]} = b_0x_{[n]} + b_1x_{[n - 1]} + b_2x_{[n - 2]} - a_1y_{[n - 1]} - a_2y_{[n - 2]}\]

FxDSP uses the canonical, or Direct-Form II (DF-II) implementation:

\[w_{[n]} = x_{[n]} - a_1w_{[n - 1]} - a_2w_{[n - 2]}\]
\[y_{[n]} = b_0w_{[n]} + b_1w_{[n - 1]} + b_2w_{[n - 2]}\]

which uses fewer multiplies, adds and delays to implement an identical filter.

Initialization and Deletion

BiquadFilter *BiquadFilterInit(const float *bCoeff, const float *aCoeff)

Create a new BiquadFilter.

Allocates memory and returns an initialized BiquadFilter. Play nice and call BiquadFilterFree on the filter when you’re done with it.

Return
An initialized BiquadFilter
Parameters
  • bCoeff -

    Numerator coefficients [b0, b1, b2]

  • aCoeff -

    Denominator coefficients [a1, a2]

Error_t BiquadFilterFree(BiquadFilter *filter)

Free memory associated with a BiquadFilter.

release all memory allocated by BiquadFilterInit for the supplied filter.

Return
Error code, 0 on success
Parameters
  • filter -

    BiquadFilter to free.

Resetting

Error_t BiquadFilterFlush(BiquadFilter *filter)

Flush filter state buffers.

Return
Error code, 0 on success
Parameters
  • filter -

    BiquadFilter to flush.

Setting Parameters

Error_t BiquadFilterUpdateKernel(BiquadFilter *filter, const float *bCoeff, const float *aCoeff)

Update the filter kernel for a given filter.

Parameters
  • filter -

    The filter to update

  • bCoeff -

    Numerator coefficients [b0, b1, b2]

  • aCoeff -

    Denominator coefficients [a1, a2]

Processing Audio

Error_t BiquadFilterProcess(BiquadFilter *filter, float *outBuffer, const float *inBuffer, unsigned n_samples)

Filter a buffer of samples.

Uses a DF-II biquad implementation to filter input samples

Return
Error code, 0 on success
Parameters
  • filter -

    The BiquadFilter to use.

  • outBuffer -

    The buffer to write the output to.

  • inBuffer -

    The buffer to filter.

  • n_samples -

    The number of samples to filter.

float BiquadFilterTick(BiquadFilter *filter, float in_sample)

Filter a single samples.

Uses a DF-II biquad implementation to filter input sample

Return
Filtered sample.
Parameters
  • filter -

    The BiquadFilter to use.

  • in_sample -

    The sample to process.