General Purpose Filter

The General Purpose filter blocks each comprise of two cascade biquad filters permitting configuration as bandpass, notch, low-pass, high-pass filters etc. By default, all filters are disabled (bypassed).

NOTE: A maximum of two output filters may be enabled simultaneously. Eg. Two channels of USB filtering or one I2S and one USB output. Exceeding this may cause audio glitching.

There is no restriction on input filters (mic and reference filters).

The filter coefficients are accepted in a floating-point format in a1, a2, b0, b1, b2 order directly from filter design tools such as https://arachnoid.com/BiQuadDesigner/index.html.

Support for the raw 32bit integer write/read is offered which directly accesses the internal representation. When using the raw control method, coefficients should be converted to Q28.4 format first and a1 and a2 need to be negated. See configuration parameters for more information.

The sample rate for filters on the input to the pipeline are always 16kHz whereas the output filters match the selected rate which may be either 16kHz or 48kHz, depending on system configuration. Ensure that the filter coefficients have been designed with the correct rate.

Note that, although potential numerical overflows are handled as a saturation, it is up to the designer to ensure no saturation occurs from the coefficients chosen to avoid non-linear behaviour of the filter. The implementation offers three bits of headroom (Q28.4) which is more than sufficient for most filters.

The coefficients are cleared to zero on boot.

The following table describes the commands for the configuration of the filters.

Table 10 Filter configuration parameters

Command

Type

Arguments

Definition

SET _FILTER_INDEX

uint8

1

Used as an index to point to which filter block that will be manipulated. output_filter_map_t below defines the filter block IDs.

GET _FILTER_INDEX

uint8

1

Retrieve the current filter index.

SET_FITER _BYPASS

uint8

1

Bypass (1) means filter pointed to by the index is not enabled (default), 0 means enable the filter.

GET_FILTER _BYPASS

uint8

1

Retrieve the bypass status.

SET _FILTER_COEFF

float

10 (5x2)

Set 5 x 2 biquad coefficients in a floating-point format in the order a1, a2, b0, b1, b2. Coefficient a0 is assumed to be 1.0. If it is not, divide all coefficients by a0.

GET _FILTER_COEFF

float

10 (5x2)

Retrieve the floating-point representation of the coefficients in the order a1, a2, b0, b1, b2.

SET_FILTER _COEFF_RAW

int32

10 (5x2)

Set 5 x 2 biquad coefficients in Q28.4 format for the filter pointed to by the index. See note above in Filter Blocks section about the format.

GET_FILTER _COEFF_RAW

int32

10 (5x2)

Retrieve the Q28.4 representation of the coefficients. See note above in Filter Blocks section about the format.

Filter output indexes available to be used with filter setting commands (output_filter_map_t):

Table 11 Output Indexes

Channel

Value

Definition

FILTER_USB _FROM_DEVICE_0

0

USB channel 0 from device to host (Left)

FILTER_USB _FROM_DEVICE_1

1

USB channel 1 from device to host (Right)

FILTER_I2S _I2S_FROM_DEVICE_0

2

I2S channel 0 from device (Left)

FILTER_I2S _I2S_FROM_DEVICE_1

3

I2S channel 1 output from device (Right)

FILTER_MIC _TO_PIPELINE_0

4

16kHz mic channel 0 going into the pipeline

FILTER_MIC _TO_PIPELINE_1

5

16kHz mic channel 1 going into the pipeline

FILTER_REF _TO_PIPELINE_1

6

16kHz reference channel 0 going into the pipeline (Left)

FILTER_REF _TO_PIPELINE_1

7

16kHz reference channel 1 going into the pipeline (Right)

While setting the index or bypass control will always be safe, there is a small chance that the coefficients may be partially updated halfway through a filter operation. For this reason, the filter state is also cleared following updating to ensure that any possibility of instability is reduced. It is up to the user to ensure that the coefficients provided result in a stable filter configuration.