Class BiQuadFilter
BiQuad filter
public class BiQuadFilter
- Inheritance
-
BiQuadFilter
- Inherited Members
Methods
AllPassFilter(float, float, float)
Creates an all pass filter
public static BiQuadFilter AllPassFilter(float sampleRate, float centreFrequency, float q)
Parameters
sampleRatefloatSample Rate
centreFrequencyfloatCentre Frequency
qfloatQ (quality factor). Controls how sharply the phase transitions around the centre frequency.
Returns
BandPassFilterConstantPeakGain(float, float, float)
Create a bandpass filter with constant peak gain
public static BiQuadFilter BandPassFilterConstantPeakGain(float sampleRate, float centreFrequency, float q)
Parameters
sampleRatefloatSample Rate
centreFrequencyfloatCentre Frequency
qfloatQ (quality factor). Higher Q gives a narrower band; lower Q gives a wider band. Peak gain at the centre frequency is 0 dB regardless of Q.
Returns
BandPassFilterConstantSkirtGain(float, float, float)
Create a bandpass filter with constant skirt gain
public static BiQuadFilter BandPassFilterConstantSkirtGain(float sampleRate, float centreFrequency, float q)
Parameters
sampleRatefloatSample Rate
centreFrequencyfloatCentre Frequency
qfloatQ (quality factor). Higher Q gives a narrower band; lower Q gives a wider band. Peak gain at the centre frequency equals Q.
Returns
HighPassFilter(float, float, float)
Create a High pass filter
public static BiQuadFilter HighPassFilter(float sampleRate, float cutoffFrequency, float q)
Parameters
sampleRatefloatSample Rate
cutoffFrequencyfloatCut-off Frequency
qfloatQ (quality factor). Use 1/sqrt(2) ≈ 0.707 for a Butterworth response (maximally flat passband, no peaking). The slope below the cutoff is ~12 dB/octave regardless of Q — cascade biquads in series for a steeper roll-off.
Returns
HighShelf(float, float, float, float)
H(s) = A * (A*s^2 + (sqrt(A)/Q)*s + 1)/(s^2 + (sqrt(A)/Q)*s + A)
public static BiQuadFilter HighShelf(float sampleRate, float cutoffFrequency, float shelfSlope, float dbGain)
Parameters
Returns
LowPassFilter(float, float, float)
Create a low pass filter
public static BiQuadFilter LowPassFilter(float sampleRate, float cutoffFrequency, float q)
Parameters
sampleRatefloatSample Rate
cutoffFrequencyfloatCut-off Frequency
qfloatQ (quality factor). Use 1/sqrt(2) ≈ 0.707 for a Butterworth response (maximally flat passband, no peaking). The slope above the cutoff is ~12 dB/octave regardless of Q — cascade biquads in series for a steeper roll-off.
Returns
LowShelf(float, float, float, float)
H(s) = A * (s^2 + (sqrt(A)/Q)s + A)/(As^2 + (sqrt(A)/Q)*s + 1)
public static BiQuadFilter LowShelf(float sampleRate, float cutoffFrequency, float shelfSlope, float dbGain)
Parameters
sampleRatefloatcutoffFrequencyfloatshelfSlopefloata "shelf slope" parameter (for shelving EQ only).
When S = 1, the shelf slope is as steep as it can be and remain monotonically increasing or decreasing gain with frequency. The shelf slope, in dB/octave, remains proportional to S for all other values for a fixed f0/Fs and dBgain.dbGainfloatGain in decibels
Returns
NotchFilter(float, float, float)
Creates a notch filter
public static BiQuadFilter NotchFilter(float sampleRate, float centreFrequency, float q)
Parameters
sampleRatefloatSample Rate
centreFrequencyfloatCentre Frequency
qfloatQ (quality factor). Higher Q gives a narrower notch; lower Q gives a wider notch.
Returns
PeakingEQ(float, float, float, float)
Create a Peaking EQ
public static BiQuadFilter PeakingEQ(float sampleRate, float centreFrequency, float q, float dbGain)
Parameters
sampleRatefloatSample Rate
centreFrequencyfloatCentre Frequency
qfloatQ (quality factor). Higher Q gives a narrower peak around the centre frequency; lower Q gives a wider, gentler bell.
dbGainfloatGain in decibels
Returns
ResetState()
Clears the filter's sample history (the x/y delay elements) without
changing its coefficients, so the next input is filtered as if from
silence. Use when reusing a filter on a new, unrelated signal (e.g. an
effect's Reset()).
public void ResetState()
SetHighPassFilter(float, float, float)
Set this as a high pass filter
public void SetHighPassFilter(float sampleRate, float cutoffFrequency, float q)
Parameters
sampleRatefloatSample Rate
cutoffFrequencyfloatCut-off Frequency
qfloatQ (quality factor). Use 1/sqrt(2) ≈ 0.707 for a Butterworth response (maximally flat passband, no peaking) — the recommended default for a clean high-pass. Larger values produce a resonant peak at the cutoff; smaller values give a more gradual roll-off into the cutoff. The slope below the cutoff is ~12 dB/octave regardless of Q — cascade biquads in series for a steeper roll-off.
SetLowPassFilter(float, float, float)
Set this up as a low pass filter
public void SetLowPassFilter(float sampleRate, float cutoffFrequency, float q)
Parameters
sampleRatefloatSample Rate
cutoffFrequencyfloatCut-off Frequency
qfloatQ (quality factor). Use 1/sqrt(2) ≈ 0.707 for a Butterworth response (maximally flat passband, no peaking) — the recommended default for a clean low-pass. Larger values produce a resonant peak at the cutoff; smaller values give a more gradual roll-off into the cutoff. The slope above the cutoff is ~12 dB/octave regardless of Q — cascade biquads in series for a steeper roll-off.
SetPeakingEq(float, float, float, float)
Set this up as a peaking EQ
public void SetPeakingEq(float sampleRate, float centreFrequency, float q, float dbGain)
Parameters
sampleRatefloatSample Rate
centreFrequencyfloatCentre Frequency
qfloatQ (quality factor). Higher Q gives a narrower peak around the centre frequency; lower Q gives a wider, gentler bell.
dbGainfloatGain in decibels
Transform(ReadOnlySpan<float>, Span<float>)
Passes a block of samples through the filter. Equivalent to — and produces byte-identical
output to — calling Transform(float) on each element of
source in order, but keeps the coefficients and state variables in
locals so the JIT can hold them in registers across the loop.
public void Transform(ReadOnlySpan<float> source, Span<float> destination)
Parameters
sourceReadOnlySpan<float>Input samples.
destinationSpan<float>Output samples. May be the same span as
source(in-place filtering) or a separate buffer at least as long assource.
Remarks
A biquad has a forward-only dependency (the next output depends on previous inputs AND outputs), so the inner loop can't be vectorised; the speedup over the single-sample form comes entirely from not having to reload field values each iteration.
Transform(float)
Passes a single sample through the filter
public float Transform(float inSample)
Parameters
inSamplefloatInput sample
Returns
- float
Output sample
UpdateBandPassFilter(float, float, float)
Retunes this filter as a band-pass (constant 0 dB peak gain) without clearing its delay state, so it can be modulated per block/sample without a click.
public void UpdateBandPassFilter(float sampleRate, float centreFrequency, float q)
Parameters
sampleRatefloatSample rate.
centreFrequencyfloatNew centre frequency.
qfloatNew Q (quality factor).
UpdateHighPassFilter(float, float, float)
Retunes this filter as a high-pass without clearing its delay state, so it can be modulated per block/sample without the click SetHighPassFilter(float, float, float) causes.
public void UpdateHighPassFilter(float sampleRate, float cutoffFrequency, float q)
Parameters
sampleRatefloatSample rate.
cutoffFrequencyfloatNew cut-off frequency.
qfloatNew Q (quality factor).
UpdateLowPassFilter(float, float, float)
Retunes this filter to a new low-pass cutoff and Q without clearing its sample history, so a running filter can be modulated every sample/block (e.g. a synth filter envelope or LFO, an auto-wah) without the click that SetLowPassFilter(float, float, float) causes by resetting state. Use only on an already-running, non-divergent filter; for a fresh filter or after a seek use SetLowPassFilter(float, float, float) (or ResetState()) so latched NaN/Infinity can't survive.
public void UpdateLowPassFilter(float sampleRate, float cutoffFrequency, float q)
Parameters
sampleRatefloatSample rate.
cutoffFrequencyfloatNew cut-off frequency.
qfloatNew Q (quality factor).
UpdateNotchFilter(float, float, float)
Retunes this filter as a notch (band-reject) without clearing its delay state, so it can be modulated per block/sample without a click.
public void UpdateNotchFilter(float sampleRate, float centreFrequency, float q)