Document toolboxDocument toolbox

(8.D.2.1) SOFControlV3

Overview

2nd order filter with coefficients derived from input pins

Discussion

This module implements a general purpose second order filter that is capable of realizing many different filter types. The module performs internal smoothing allowing the filters to be updated without introducing clicks. In all cases, the module implements an underlying second order filter. First order filters are realized by setting some of the second order coefficients to zero.

The behavior of the cascade filters are controlled by the filterType arrary. The variable, filterType is an integer in the range from 0 to 22 inclusive.

After specifying filterType, adjust the filter parameters by setting the fields, gain, freq, and Q. Freq, gain and Q can be controlled either through respective input control pin or from the module inspector. Some filter parameters are not applicable to all filter types. The variable, freq controls the center frequency of the filter, gain determines the boost or cut in dB, and Q determines how sharp the filter is. Low Q values lead to broad filters and high Q values lead to narrow filters.

The following table discusses the various filter types and which variables are active in each case.

filterType=0, Simple pass through with unity gain.

filterType=1, Linear gain. [gain].

filterType=2, 1st order Butterworth low pass filter. [freq].

filterType=3, 2nd order Butterworth low pass filter. [freq].

filterType=4, 1st order Butterworth high pass filter. [freq].

filterType=5, 2nd order Butterworth high pass filter. [freq].

filterType=6, 1st order allpass filter. [freq].

filterType=7, 2nd order allpass filter. [freq, Q].

filterType=8, 2nd order low shelf. It allows you to vary the gain of the low frequencies. The high frequencies have a gain of 1.0. [freq, gain].

filterType=9, 2nd order low shelf with Q. It allows you to vary the gain of the low frequencies. The high frequencies have a gain of 1.0. [freq, gain, Q].

filterType=10, 2nd order high shelf. It allows you to vary the gain of the high frequencies. The low frequencies have a gain of 1.0. [freq, gain].

filterType=11, 2nd order high shelf with Q. It allows you to vary the gain of the high frequencies. The low frequencies have a gain of 1.0. [freq, gain, Q].

filterType=12, 2nd order peaking filter. It has unity gain except around the specified frequency. By varying gain, you can get a peak or a notch in the frequency band. [freq, gain, Q].

filterType=13, 2nd order notch filter. It has unity gain except around the specified frequency. At the specified frequency, the filter has a true notch with -inf dB gain. [freq, Q].

filterType=14, 2nd order bandpass filter. It has unity gain at the specified frequency and falls off in both directions. The bandwidth of the filter is determined by Q. [freq, Q].

filterType=15, 1st order Bessel low pass filter. [freq].

filterType=16, 1st order Bessel high pass filter. [freq].

filterType=17, 1st order asymmetrical low shelf. [freq, gain].

filterType=18, 1st order asymmetrical high shelf. [freq, gain].

filterType=19, 1st order symmetrical low shelf. [freq, gain].

filterType=20, 1st order symmetrical high shelf. [freq, gain].

filterType=21, 2nd order Butterworth low pass filter with variable Q. [freq, Q].

filterType=22, 2nd order Butterworth high pass filter with variable Q. [freq, Q].

filterType=23, 2nd order Resonant bandpass filter. [freq, Q].

When the parameters freq, gain or Q are controlled through the input pin, then the default behaviour of the module is to calculate coefficients in the Set function. User can change the behaviour through the parameter setBehavior, to calculate coefficients in the Process function itself.

If the set behavior is OnChangeDeferred and any of the filter parameters of Freq, Gain or Q is from control pin then the filter coefficients are calculated in the process function itself for the first pump to start filter with know state and to avoid any glitches on the system start.

The only difference from V2 is an optional argument, BIQUADFORM to select underlying biquad implementation either Direct Form 2 or Direct Form 1. Based on this selection the state buffer is allocated accordingly. Default to use DF-2.

Type Definition

typedef struct _ModuleSOFControlV3 { ModuleInstanceDescriptor instance; // Common Audio Weaver module instance structure INT32 filterType; // Selects the type of filter that is implemented by the module: Bypass=0, Gain=1, Butter1stLPF=2, Butter2ndLPF=3, Butter1stHPF=4, Butter2ndHPF=5, Allpass1st=6, Allpass2nd=7, Shelf2ndLow=8, Shelf2ndLowQ=9, Shelf2ndHigh=10, Shelf2ndHighQ=11, PeakEQ=12, Notch=13, Bandpass=14, Bessel1stLPF=15, Bessel1stHPF=16, AsymShelf1stLow=17, AsymShelf1stHigh=18, SymShelf1stLow=19, SymShelf1stHigh=20, VariableQLPF=21, VariableQHPF=22, Resonant=23. INT32 setBehavior; // Controls the Set function calling behavior of the module FLOAT32 freq; // Cutoff frequency of the filter, in Hz. FLOAT32 gain; // Amount of boost or cut to apply, in dB if applicable. FLOAT32 Q; // Specifies the Q of the filter, if applicable. FLOAT32 smoothingTime; // Time constant of the smoothing process. INT32 updateActive; // Specifies whether the filter coefficients are updating (=1) or fixed (=0). FLOAT32 b0; // Desired first numerator coefficient. FLOAT32 b1; // Desired second numerator coefficient. FLOAT32 b2; // Desired third numerator coefficient. FLOAT32 a1; // Desired second denominator coefficient. FLOAT32 a2; // Desired third denominator coefficient. FLOAT32 current_b0; // Instantaneous first numerator coefficient. FLOAT32 current_b1; // Instantaneous second numerator coefficient. FLOAT32 current_b2; // Instantaneous third numerator coefficient. FLOAT32 current_a1; // Instantaneous second denominator coefficient. FLOAT32 current_a2; // Instantaneous third denominator coefficient. FLOAT32 smoothingCoeff; // Smoothing coefficient. This is computed based on the smoothingTime, sample rate, and block size of the module. UINT32 pinID; // Specifies which control pins are available. INT32 biquadForm; // Flag indicates which direct form implementation to use, DF-2 or DF-1. Default is DF-2. INT32 stateSize; // State size per channel. 2 in DF-2 and 4 in DF-1 FLOAT32* state; // State variables. 2 per channel in DF-2 and 4 per channel in DF-1. INT32 initDone; // For internal use only } ModuleSOFControlV3Class;

Variables

Properties

Name

Type

Usage

isHidden

Default value

Range

Units

filterType

int

parameter

0

0

0:23

 

setBehavior

int

parameter

0

0

0:1

 

freq

float

state

0

250

10:23990

Hz

gain

float

state

0

0

-24:24

dB

Q

float

state

0

1

-20:20

 

smoothingTime

float

parameter

0

10

0:1000

msec

updateActive

int

parameter

1

1

0:1

 

b0

float

derived

1

1

Unrestricted

 

b1

float

derived

1

0

Unrestricted

 

b2

float

derived

1

0

Unrestricted

 

a1

float

derived

1

0

Unrestricted

 

a2

float

derived

1

0

Unrestricted

 

current_b0

float

state

1

1

Unrestricted

 

current_b1

float

state

1

0

Unrestricted

 

current_b2

float

state

1

0

Unrestricted

 

current_a1

float

state

1

0

Unrestricted

 

current_a2

float

state

1

0

Unrestricted

 

smoothingCoeff

float

derived

1

0.06449

Unrestricted

 

pinID

uint

const

1

7

Unrestricted

 

biquadForm

int

const

1

0

Unrestricted

 

stateSize

int

const

1

2

Unrestricted

 

state

float*

state

1

[2 x 1]

Unrestricted

 

initDone

int

state

1

 

Unrestricted

 

Pins

Input Pins

Name: freqPin

Description: Cutoff frequency of the filter

Data type: float

Channel range: 1

Block size range: Unrestricted

Sample rate range: Unrestricted

Complex support: Real

 

Name: gainPin

Description: Gain of the filter

Data type: float

Channel range: 1

Block size range: Unrestricted

Sample rate range: Unrestricted

Complex support: Real

 

Name: qPin

Description: Q of the filter

Data type: float

Channel range: 1

Block size range: Unrestricted

Sample rate range: Unrestricted

Complex support: Real

 

Name: in

Description: audio input

Data type: float

Channel range: Unrestricted

Block size range: Unrestricted

Sample rate range: Unrestricted

Complex support: Real

Output Pins

Name: out

Description: audio output

Data type: float

MATLAB Usage

File Name: sof_control_v3_module.m

M=sof_control_v3_module(NAME, FREQPIN, GAINPIN, QPIN, BIQUADFORM) Creates a general purpose second order filter that implements a number of standard filter types. The filter operates on multiple interleaved channels, with all channels being processed by the same set of coefficients. Arguments: NAME - name of the module. FREQPIN - Boolean that determines whether the module exposes an input pin that allows the frequency of the filter to be adjusted. GAINPIN - Boolean that determines whether the module exposes an input pin that allows the gain of the filter to be adjusted. QPIN - Boolean that determines whether the module exposes an input pin that allows the Q of the filter to be adjusted. BIQUADFORM - Flag to select which Biquad form to use, DF-I, DF-II or TDF-II. Default to use DF-II.

Â