Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
sbl::dsp::Svf Class Reference

A trapezoidal state-variable filter with five responses from one section. More...

Detailed Description

A trapezoidal state-variable filter with five responses from one section.

The trapezoidal (TPT) state-variable filter of Zavalishin, "The Art of VA Filter Design": two integrators and one divide per frame, giving the low-pass, band-pass and high-pass of one second-order section from one call. With the integrator gain g = tan(pi fc) and the damping k = 1 / Q,

hp = (x - (g + k) s1 - s2) / (1 + g (g + k))
bp = g hp + s1, s1 <- g hp + bp
lp = g bp + s2, s2 <- g bp + lp

which is the analog prototype under the bilinear transform with its center pre-warped: the response at fc is the prototype's at any fc below Nyquist, and the bandwidth is Q's in the audio EQ cookbook's sense. The band-pass peaks at Q; bp / Q peaks at 1.

The responses. The taps sum to the input as x = hp + k bp + lp, so the notch is x - k bp and the all-pass x - 2 k bp; response() gives any of the five from a frame's taps. The band-pass response is k bp, which peaks at 1 whatever the Q.

The all-pass mix. A mix m of the all-pass with the input, (1 - m) x + m AP(x), is one tap, y = x - 2 m k bp: allpass_mix(). Its gain at fc is 1 - 2 m, and 1 at DC and at Nyquist, for every m: 0 is the input, 1/2 a notch, 1 the all-pass, -1 a peak of 3 (+9.54 dB). It is the all-pass response through a dry/wet mix (dynamics/dry_wet.hpp), which is how the buffer form's users get it. On a pulse the phase shift raises the peak as well: a pulse between -1 and 1 stays under 4.1 at m = 1 and m = -1 (test_svf.hpp).

The frame call takes its coefficients, as OnePole's takes one: the owner works them with integrator_gain_for() and damping_for() at its own rate and decides how they move between. The filter is stable under any trajectory of g > 0 and k > 0, at audio rate too, and a constant input settles to the same output whatever the coefficients do (Wishnick, DAFx-14). Moving the center shifts the phase near fc as it goes: phase distortion whose sidebands are not band-limited.

The frame call is below the signal transport: the center is in cycles per frame, kept in [CUTOFF_MIN, CUTOFF_MAX], and Q in [Q_MIN, Q_MAX]; it holds no sample rate and ramps nothing. A value that is not a number counts as the low end of its range. integrator_gain_for() uses math::fast_tan_pif, which puts the center within CUTOFF_ERROR_CENTS of the one asked for. The audio input is not tested, as OnePole's and DcBlock's are not: a non-finite input stays in the state until reset(), and its owner keeps it out. The filter adds no latency.

The buffer form is on the transport: it renders the response chosen by set_response() with the center and Q as ports, each a block or a scalar. A block is used as given, its coefficient worked each frame. A scalar's coefficient is worked once a call and moves to it over RAMP_FRAMES, the first one at once, so a center set from a control does not step.

Definition at line 76 of file svf.hpp.

#include <svf.hpp>

Classes

struct  Taps
 One frame's taps. bp peaks at Q; damping * bp peaks at 1. More...
 

Public Types

enum class  Response : uint8_t {
  LowPass , BandPass , HighPass , Notch ,
  AllPass
}
 What the buffer form renders. More...
 

Public Member Functions

 Svf ()
 Integrators at rest; the buffer form renders the low-pass and ramps its scalar ports over RAMP_FRAMES.
 
Taps process (float x, float g, float damping)
 One frame.
 
void set_response (Response which)
 Parameter: the response the buffer form renders. The low-pass until set.
 
Response response () const
 The response the buffer form renders.
 
void set_response_index (float index)
 set_response() by number, for a tool's flag.
 
template<class... Ports>
void process (const float *in, float *out, uint16_t frames, Ports... ports)
 The chosen response over a buffer, the ports in PORTS' order, both given.
 
void reset ()
 Both integrators at rest, and the buffer form's coefficients at their targets.
 

Static Public Member Functions

static float integrator_gain_for (float cutoff_cycles_per_frame)
 The integrator gain g = tan(pi cutoff) for a center.
 
static float damping_for (float q)
 The damping k = 1 / Q.
 
static float allpass_mix (float x, float bp, float damping, float mix)
 The all-pass mix of a frame: x - 2 mix damping bp.
 
static float response (Response which, float x, const Taps &taps, float damping)
 A response from a frame: its input, its taps and the damping it ran at.
 

Static Public Attributes

static constexpr float CUTOFF_MIN = 1.0e-5f
 
static constexpr float CUTOFF_MAX = 0.45f
 
static constexpr float CUTOFF_ERROR_CENTS = 0.01f
 
static constexpr float Q_MIN = 0.5f
 
static constexpr float Q_MAX = 32.0f
 
static constexpr uint16_t RAMP_FRAMES = 64
 
static constexpr transport::Port PORTS []
 The ports of the buffer form, in the order it takes them.
 
static constexpr transport::Parameter< Svf > PARAMETERS []
 The parameters, for tools.
 

Member Enumeration Documentation

◆ Response

enum class sbl::dsp::Svf::Response : uint8_t
strong

What the buffer form renders.

Enumerator
LowPass 

lp

BandPass 

k bp: a peak of 1 at the center

HighPass 

hp

Notch 

x - k bp

AllPass 

x - 2 k bp

Definition at line 86 of file svf.hpp.

Constructor & Destructor Documentation

◆ Svf()

sbl::dsp::Svf::Svf ( )
inline

Integrators at rest; the buffer form renders the low-pass and ramps its scalar ports over RAMP_FRAMES.

Definition at line 95 of file svf.hpp.

References RAMP_FRAMES, and sbl::dsp::Ramp::set_length().

Referenced by process().

Member Function Documentation

◆ integrator_gain_for()

static float sbl::dsp::Svf::integrator_gain_for ( float  cutoff_cycles_per_frame)
inlinestatic

The integrator gain g = tan(pi cutoff) for a center.

Parameters
cutoff_cycles_per_frameThe center in cycles per frame, kept in [CUTOFF_MIN, CUTOFF_MAX]; a NaN gives CUTOFF_MIN
Returns
g, above 0

Definition at line 113 of file svf.hpp.

References sbl::math::clamp(), CUTOFF_MAX, CUTOFF_MIN, and sbl::dsp::math::fast_tan_pif().

Referenced by process().

◆ damping_for()

static float sbl::dsp::Svf::damping_for ( float  q)
inlinestatic

The damping k = 1 / Q.

Parameters
qQ, kept in [Q_MIN, Q_MAX]; a NaN gives Q_MIN
Returns
k, in [1 / Q_MAX, 1 / Q_MIN]

Definition at line 123 of file svf.hpp.

References sbl::math::clamp(), Q_MAX, and Q_MIN.

Referenced by process().

◆ process() [1/2]

Taps sbl::dsp::Svf::process ( float  x,
float  g,
float  damping 
)
inline

One frame.

Parameters
xThe input sample
gThe integrator gain, from integrator_gain_for()
damping1 / Q, from damping_for()
Returns
The frame's taps
Context
Audio thread; real-time safe.

Definition at line 134 of file svf.hpp.

Referenced by process().

◆ allpass_mix()

static float sbl::dsp::Svf::allpass_mix ( float  x,
float  bp,
float  damping,
float  mix 
)
inlinestatic

The all-pass mix of a frame: x - 2 mix damping bp.

Parameters
xThe frame's input
bpThe frame's band-pass tap
dampingThe damping the frame ran at
mix0 the input, 1/2 a notch, 1 the all-pass, -1 a peak; used as given
Returns
The mixed sample

Definition at line 152 of file svf.hpp.

◆ response() [1/2]

static float sbl::dsp::Svf::response ( Response  which,
float  x,
const Taps &  taps,
float  damping 
)
inlinestatic

A response from a frame: its input, its taps and the damping it ran at.

Parameters
whichThe response
xThe frame's input
tapsThe frame's taps
dampingThe damping the frame ran at
Returns
The response's sample

Definition at line 163 of file svf.hpp.

References AllPass, BandPass, sbl::dsp::Svf::Taps::bp, HighPass, sbl::dsp::Svf::Taps::hp, LowPass, sbl::dsp::Svf::Taps::lp, and Notch.

◆ set_response()

void sbl::dsp::Svf::set_response ( Response  which)
inline

Parameter: the response the buffer form renders. The low-pass until set.

Parameters
whichThe response
Context
Same thread as process(); real-time safe.

Definition at line 180 of file svf.hpp.

◆ response() [2/2]

Response sbl::dsp::Svf::response ( ) const
inline

The response the buffer form renders.

Definition at line 182 of file svf.hpp.

Referenced by process().

◆ set_response_index()

void sbl::dsp::Svf::set_response_index ( float  index)
inline

set_response() by number, for a tool's flag.

Parameters
index0 the low-pass to 4 the all-pass, in Response's order; clamped and rounded, a NaN gives 0
Context
Same thread as process(); real-time safe.

Definition at line 190 of file svf.hpp.

References AllPass, and sbl::math::clamp().

◆ process() [2/2]

template<class... Ports>
void sbl::dsp::Svf::process ( const float *  in,
float *  out,
uint16_t  frames,
Ports...  ports 
)
inline

The chosen response over a buffer, the ports in PORTS' order, both given.

Each port is a block, one value per frame, or a scalar. A scalar's coefficient moves to it over RAMP_FRAMES; the first scalar a port is given is arrived at at once, and after a block a later scalar moves from where the block ended. The center and Q are kept in their ranges. In place is fine: out may be in.

Template Parameters
PortsA block (a float pointer) or an arithmetic scalar for each of PORTS
Parameters
inInput buffer, frames long
[out]outOutput buffer, frames long
framesFrame count
portsThe center in cycles per frame, then Q
Context
Audio thread; real-time safe.

Definition at line 224 of file svf.hpp.

References damping_for(), sbl::transport::fits_v, sbl::dsp::Ramp::head(), integrator_gain_for(), sbl::dsp::Ramp::jump(), PORTS, process(), response(), sbl::dsp::Ramp::step(), and Svf().

◆ reset()

void sbl::dsp::Svf::reset ( )
inline

Both integrators at rest, and the buffer form's coefficients at their targets.

Definition at line 263 of file svf.hpp.

References sbl::dsp::Ramp::jump(), and sbl::dsp::Ramp::target().

Member Data Documentation

◆ CUTOFF_MIN

constexpr float sbl::dsp::Svf::CUTOFF_MIN = 1.0e-5f
staticconstexpr

the lowest center, in cycles per frame: 0.48 Hz at 48 kHz

Definition at line 78 of file svf.hpp.

Referenced by integrator_gain_for().

◆ CUTOFF_MAX

constexpr float sbl::dsp::Svf::CUTOFF_MAX = 0.45f
staticconstexpr

the highest center, in cycles per frame: 0.9 of Nyquist

Definition at line 79 of file svf.hpp.

Referenced by integrator_gain_for().

◆ CUTOFF_ERROR_CENTS

constexpr float sbl::dsp::Svf::CUTOFF_ERROR_CENTS = 0.01f
staticconstexpr

the most fast_tan_pif moves the center, at CUTOFF_MAX

Definition at line 80 of file svf.hpp.

◆ Q_MIN

constexpr float sbl::dsp::Svf::Q_MIN = 0.5f
staticconstexpr

two real poles at the center

Definition at line 81 of file svf.hpp.

Referenced by damping_for().

◆ Q_MAX

constexpr float sbl::dsp::Svf::Q_MAX = 32.0f
staticconstexpr

the highest Q

Definition at line 82 of file svf.hpp.

Referenced by damping_for().

◆ RAMP_FRAMES

constexpr uint16_t sbl::dsp::Svf::RAMP_FRAMES = 64
staticconstexpr

the buffer form's scalar ports arrive after this many frames

Definition at line 83 of file svf.hpp.

Referenced by Svf().

◆ PORTS

constexpr transport::Port sbl::dsp::Svf::PORTS[]
staticconstexpr
Initial value:

The ports of the buffer form, in the order it takes them.

Definition at line 197 of file svf.hpp.

Referenced by process().

◆ PARAMETERS

constexpr transport::Parameter<Svf> sbl::dsp::Svf::PARAMETERS[]
staticconstexpr
Initial value:
= {
}
void set_response_index(float index)
set_response() by number, for a tool's flag.
Definition svf.hpp:190

The parameters, for tools.

Definition at line 203 of file svf.hpp.


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