DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
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
 Peaking filter with prescribed Nyquist gain (Orfanidis 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.
 

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

Definition at line 90 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 479 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 511 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 366 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 156 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 418 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 395 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 127 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 313 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 103 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 283 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 342 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 185 of file Biquad.h.

◆ makePeakMatched()

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

Peaking filter with prescribed Nyquist gain (Orfanidis design).

The bilinear (cookbook) peaking filter cramps near Nyquist: high- frequency bells get narrower and their response is pinned at fs/2, deviating audibly from the analog prototype above ~fs/6. This design (Orfanidis, JAES 45(6), 1997) prescribes the digital gain at Nyquist to equal the ANALOG prototype's gain there, matching the analog bell shape across the band: the standard "de-cramped" EQ used by state-of-the-art digital equalizers.

Falls back to identity for |gain| < 0.01 dB. At low frequencies it converges to the cookbook response (as it should).

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

Definition at line 223 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 444 of file Biquad.h.

Member Data Documentation

◆ a1

double dspark::BiquadCoeffs::a1 = 0.0

Definition at line 93 of file Biquad.h.

◆ a2

double dspark::BiquadCoeffs::a2 = 0.0

Definition at line 93 of file Biquad.h.

◆ b0

double dspark::BiquadCoeffs::b0 = 1.0

Definition at line 92 of file Biquad.h.

◆ b1

double dspark::BiquadCoeffs::b1 = 0.0

Definition at line 92 of file Biquad.h.

◆ b2

double dspark::BiquadCoeffs::b2 = 0.0

Definition at line 92 of file Biquad.h.


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