DSPark 1.8.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
dspark::BiquadCoeffs Struct Reference

Stores normalised biquad coefficients (b0, b1, b2, a1, a2), always double. More...

#include <Biquad.h>

Public Member Functions

double getMagnitude (double frequency, double sampleRate) const noexcept
 Evaluates magnitude response |H(f)| at a single frequency.
 
template<typename U >
void getMagnitudeForFrequencyArray (std::span< const U > frequencies, std::span< U > magnitudes, double sampleRate) const noexcept
 Computes magnitude responses for a batch of frequencies.
 

Static Public Member Functions

static BiquadCoeffs makeLowPass (double sampleRate, double freq, double Q=0.7071067811865476) noexcept
 Low-pass filter.
 
static BiquadCoeffs makeHighPass (double sampleRate, double freq, double Q=0.7071067811865476) noexcept
 High-pass filter.
 
static BiquadCoeffs makeBandPass (double sampleRate, double freq, double Q=0.7071067811865476) noexcept
 Band-pass filter (constant 0 dB peak gain).
 
static BiquadCoeffs makePeak (double sampleRate, double freq, double Q, double gainDb) noexcept
 Peak (parametric EQ) filter.
 
static BiquadCoeffs makePeakMatched (double sampleRate, double freq, double Q, double gainDb) noexcept
 Analog-matched ("de-cramped") peaking filter (Vicanek design).
 
static BiquadCoeffs makeLowShelf (double sampleRate, double freq, double gainDb, double slope=1.0) noexcept
 Low-shelf filter.
 
static BiquadCoeffs makeHighShelf (double sampleRate, double freq, double gainDb, double slope=1.0) noexcept
 High-shelf filter.
 
static BiquadCoeffs makeNotch (double sampleRate, double freq, double Q=0.7071067811865476) noexcept
 Notch (band-reject) filter.
 
static BiquadCoeffs makeAllPass (double sampleRate, double freq, double Q=0.7071067811865476) noexcept
 All-pass filter.
 
static BiquadCoeffs makeFirstOrderLowPass (double sampleRate, double frequency) noexcept
 First-order (6 dB/oct) low-pass filter.
 
static BiquadCoeffs makeFirstOrderHighPass (double sampleRate, double frequency) noexcept
 First-order (6 dB/oct) high-pass filter.
 
static BiquadCoeffs makeTilt (double sampleRate, double pivotFreq, double gainDb) noexcept
 Creates a first-order tilt filter.
 
static BiquadCoeffs makeKWeightingShelf (double sampleRate) noexcept
 ITU-R BS.1770 K-weighting, stage 1: the head-related high shelf.
 
static BiquadCoeffs makeKWeightingHighPass (double sampleRate) noexcept
 ITU-R BS.1770 K-weighting, stage 2: the RLB high-pass.
 

Public Attributes

double b0 = 1.0
 
double b1 = 0.0
 
double b2 = 0.0
 
double a1 = 0.0
 
double a2 = 0.0
 

Detailed Description

Stores normalised biquad coefficients (b0, b1, b2, a1, a2), always double.

Coefficients are pre-normalised by a0 in every factory method, so the filter processing loop never needs to divide by a0. Memory is aligned to 32 bytes to facilitate explicit SIMD vectorisation and CPU cache optimal loads.

All factory methods clamp frequency, Q and slope to safe ranges, so any finite parameter combination yields a stable filter. NaN parameters are not sanitised (they propagate into the coefficients), and the sample rate is trusted as-is: the framework contract is a valid AudioSpec upstream.

There is no float instantiation and no coefficient type parameter: a corner far below the sample rate is exact as a DESIGN but cannot be REALISED in float (see the file-level documentation for the measurements), and a coefficient set that cannot be realised is not a coefficient set. One precision, one rule, and the magnitude response drawn from these numbers is the response the audio path actually applies. For DC removal specifically, use DCBlocker, which is built for it.

Definition at line 105 of file Biquad.h.

Member Function Documentation

◆ getMagnitude()

double dspark::BiquadCoeffs::getMagnitude ( double  frequency,
double  sampleRate 
) const
inlinenoexcept

Evaluates magnitude response |H(f)| at a single frequency.

Evaluates the transfer function H(z) = B(z)/A(z) at z = e^(j*2*pi*f/fs). Essential for drawing EQ curves and filter response plots. These are the same numbers the recursion runs on, so the drawn curve is the realised response, not a re-derivation of it.

Parameters
frequencyFrequency to evaluate in Hz.
sampleRateSample rate in Hz.
Returns
Magnitude (linear scale, 1.0 = unity gain).

Definition at line 558 of file Biquad.h.

◆ getMagnitudeForFrequencyArray()

template<typename U >
void dspark::BiquadCoeffs::getMagnitudeForFrequencyArray ( std::span< const U >  frequencies,
std::span< U >  magnitudes,
double  sampleRate 
) const
inlinenoexcept

Computes magnitude responses for a batch of frequencies.

Uses C++20 std::span for bounds-safe array access. Efficient batch evaluation for drawing frequency response curves. Templated on the array element type so a UI can keep its curve buffers in float.

Parameters
frequenciesSpan of input frequencies in Hz.
magnitudesSpan where the evaluated magnitudes will be stored. Must be at least as large as the frequencies span.
sampleRateSample rate in Hz.

Definition at line 590 of file Biquad.h.

◆ makeAllPass()

static BiquadCoeffs dspark::BiquadCoeffs::makeAllPass ( double  sampleRate,
double  freq,
double  Q = 0.7071067811865476 
)
inlinestaticnoexcept

All-pass filter.

Parameters
sampleRateSample rate in Hz.
freqCentre frequency in Hz.
QQuality factor (default: Butterworth).

Definition at line 397 of file Biquad.h.

◆ makeBandPass()

static BiquadCoeffs dspark::BiquadCoeffs::makeBandPass ( double  sampleRate,
double  freq,
double  Q = 0.7071067811865476 
)
inlinestaticnoexcept

Band-pass filter (constant 0 dB peak gain).

Implements the Audio EQ Cookbook BPF variant with b0 = alpha, whose peak gain at the centre frequency is exactly 0 dB regardless of Q, the most useful variant for mixing and crossover work.

Parameters
sampleRateSample rate in Hz.
freqCentre frequency in Hz.
QQuality factor (default: Butterworth).

Definition at line 171 of file Biquad.h.

◆ makeFirstOrderHighPass()

static BiquadCoeffs dspark::BiquadCoeffs::makeFirstOrderHighPass ( double  sampleRate,
double  frequency 
)
inlinestaticnoexcept

First-order (6 dB/oct) high-pass filter.

Uses bilinear-transformed CR filter. Coefficients are already normalised (a0 = 1 implicit), so no normalise() call is needed.

Parameters
sampleRateSample rate in Hz.
frequencyCut-off frequency in Hz.

Definition at line 449 of file Biquad.h.

◆ makeFirstOrderLowPass()

static BiquadCoeffs dspark::BiquadCoeffs::makeFirstOrderLowPass ( double  sampleRate,
double  frequency 
)
inlinestaticnoexcept

First-order (6 dB/oct) low-pass filter.

Uses bilinear-transformed RC filter. Coefficients are already normalised (a0 = 1 implicit), so no normalise() call is needed.

Parameters
sampleRateSample rate in Hz.
frequencyCut-off frequency in Hz.

Definition at line 426 of file Biquad.h.

◆ makeHighPass()

static BiquadCoeffs dspark::BiquadCoeffs::makeHighPass ( double  sampleRate,
double  freq,
double  Q = 0.7071067811865476 
)
inlinestaticnoexcept

High-pass filter.

Parameters
sampleRateSample rate in Hz.
freqCentre frequency in Hz.
QQuality factor (default: Butterworth).

Definition at line 142 of file Biquad.h.

◆ makeHighShelf()

static BiquadCoeffs dspark::BiquadCoeffs::makeHighShelf ( double  sampleRate,
double  freq,
double  gainDb,
double  slope = 1.0 
)
inlinestaticnoexcept

High-shelf filter.

Parameters
sampleRateSample rate in Hz.
freqTransition frequency in Hz.
gainDbShelf gain in decibels.
slopeShelf slope (default: 1.0).

Definition at line 344 of file Biquad.h.

◆ makeKWeightingHighPass()

static BiquadCoeffs dspark::BiquadCoeffs::makeKWeightingHighPass ( double  sampleRate)
inlinestaticnoexcept

ITU-R BS.1770 K-weighting, stage 2: the RLB high-pass.

The official table 2 numerator is exactly [1, -2, 1], NOT normalized to unity passband gain (it passes about +0.04 dB); the -0.691 dB constant of the LUFS formula is tied to this exact cascade.

Definition at line 529 of file Biquad.h.

◆ makeKWeightingShelf()

static BiquadCoeffs dspark::BiquadCoeffs::makeKWeightingShelf ( double  sampleRate)
inlinestaticnoexcept

ITU-R BS.1770 K-weighting, stage 1: the head-related high shelf.

Pre-warped analog parameterization that reproduces the official table 1 coefficients at 48 kHz to machine precision (max error 8.9e-16) and stays within the standard's tolerance at every other rate. Cascade with makeKWeightingHighPass() for the full K filter (LoudnessMeter's).

Definition at line 504 of file Biquad.h.

◆ makeLowPass()

static BiquadCoeffs dspark::BiquadCoeffs::makeLowPass ( double  sampleRate,
double  freq,
double  Q = 0.7071067811865476 
)
inlinestaticnoexcept

Low-pass filter.

Parameters
sampleRateSample rate in Hz.
freqCentre frequency in Hz.
QQuality factor (default: 1/sqrt(2) = Butterworth).

Definition at line 118 of file Biquad.h.

◆ makeLowShelf()

static BiquadCoeffs dspark::BiquadCoeffs::makeLowShelf ( double  sampleRate,
double  freq,
double  gainDb,
double  slope = 1.0 
)
inlinestaticnoexcept

Low-shelf filter.

Parameters
sampleRateSample rate in Hz.
freqTransition frequency in Hz.
gainDbShelf gain in decibels.
slopeShelf slope (default: 1.0 for standard 6 dB/oct transition).

Definition at line 314 of file Biquad.h.

◆ makeNotch()

static BiquadCoeffs dspark::BiquadCoeffs::makeNotch ( double  sampleRate,
double  freq,
double  Q = 0.7071067811865476 
)
inlinestaticnoexcept

Notch (band-reject) filter.

Parameters
sampleRateSample rate in Hz.
freqCentre frequency in Hz.
QQuality factor (default: Butterworth).

Definition at line 373 of file Biquad.h.

◆ makePeak()

static BiquadCoeffs dspark::BiquadCoeffs::makePeak ( double  sampleRate,
double  freq,
double  Q,
double  gainDb 
)
inlinestaticnoexcept

Peak (parametric EQ) filter.

Uses the correct Audio EQ Cookbook formula where A = 10^(dBgain/40), giving the expected gain in dB at the centre frequency.

Parameters
sampleRateSample rate in Hz.
freqCentre frequency in Hz.
QQuality factor.
gainDbGain in decibels (positive = boost, negative = cut).

Definition at line 200 of file Biquad.h.

◆ makePeakMatched()

static BiquadCoeffs dspark::BiquadCoeffs::makePeakMatched ( double  sampleRate,
double  freq,
double  Q,
double  gainDb 
)
inlinestaticnoexcept

Analog-matched ("de-cramped") peaking filter (Vicanek design).

The bilinear (cookbook) peaking filter cramps near Nyquist: high- frequency bells get narrower and their response is pinned to 0 dB at fs/2, deviating from the analog prototype above ~fs/6 (up to 11 dB in the audible band at 48 kHz). This design follows M. Vicanek, "Matched Second Order Digital Filters" (2016): the poles are the analog prototype's poles mapped by impulse invariance (z = e^(sT), so the bell keeps its analog width at any frequency), and the minimum-phase numerator is solved in closed form for unity gain at DC, the exact peak gain at the centre frequency, and a response extremum there.

The prototype is the cookbook bell, H(s) = (s^2 + s*w0*sqrt(G)/Q + w0^2) / (s^2 + s*w0/(sqrt(G)*Q) + w0^2), so Q means the same as in makePeak() and both designs converge at low frequencies. Measured against that prototype over 20 Hz - 20 kHz (gains +/-3..24 dB, Q 0.5..4, centres up to 20 kHz): worst deviation 2.9 dB and mean 0.14 dB at 48 kHz (cookbook: 11 dB worst). Every finite parameter set yields a stable, minimum-phase filter, including centres close to Nyquist.

Falls back to identity for |gain| < 0.01 dB.

Parameters
sampleRateSample rate in Hz.
freqCenter frequency in Hz.
QQuality factor (bandwidth = freq / Q at the half-dB gain).
gainDbPeak gain in decibels.

Definition at line 247 of file Biquad.h.

◆ makeTilt()

static BiquadCoeffs dspark::BiquadCoeffs::makeTilt ( double  sampleRate,
double  pivotFreq,
double  gainDb 
)
inlinestaticnoexcept

Creates a first-order tilt filter.

Tilts the spectrum around a pivot frequency: -gainDb/2 at DC, unity at the pivot, +gainDb/2 at Nyquist (total span = gainDb). A single-knob tonal balance control found in mastering EQs and channel strips (SSL, Neve, Tonelux Tilt).

Parameters
sampleRateSample rate in Hz.
pivotFreqPivot frequency in Hz (typically 600-3000 Hz).
gainDbTilt amount in dB (positive = bright, negative = dark).

Definition at line 475 of file Biquad.h.

Member Data Documentation

◆ a1

double dspark::BiquadCoeffs::a1 = 0.0

Definition at line 108 of file Biquad.h.

◆ a2

double dspark::BiquadCoeffs::a2 = 0.0

Definition at line 108 of file Biquad.h.

◆ b0

double dspark::BiquadCoeffs::b0 = 1.0

Definition at line 107 of file Biquad.h.

◆ b1

double dspark::BiquadCoeffs::b1 = 0.0

Definition at line 107 of file Biquad.h.

◆ b2

double dspark::BiquadCoeffs::b2 = 0.0

Definition at line 107 of file Biquad.h.


The documentation for this struct was generated from the following file: