|
Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
|
A trapezoidal state-variable filter with five responses from one section. More...
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,
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.
#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. | |
|
strong |
|
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().
|
inlinestatic |
The integrator gain g = tan(pi cutoff) for a center.
| cutoff_cycles_per_frame | The center in cycles per frame, kept in [CUTOFF_MIN, CUTOFF_MAX]; a NaN gives CUTOFF_MIN |
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().
|
inlinestatic |
|
inline |
One frame.
| x | The input sample |
| g | The integrator gain, from integrator_gain_for() |
| damping | 1 / Q, from damping_for() |
Definition at line 134 of file svf.hpp.
Referenced by process().
|
inlinestatic |
|
inlinestatic |
A response from a frame: its input, its taps and the damping it ran at.
| which | The response |
| x | The frame's input |
| taps | The frame's taps |
| damping | The damping the frame ran at |
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.
|
inline |
|
inline |
|
inline |
set_response() by number, for a tool's flag.
| index | 0 the low-pass to 4 the all-pass, in Response's order; clamped and rounded, a NaN gives 0 |
Definition at line 190 of file svf.hpp.
References AllPass, and sbl::math::clamp().
|
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.
| Ports | A block (a float pointer) or an arithmetic scalar for each of PORTS |
| in | Input buffer, frames long | |
| [out] | out | Output buffer, frames long |
| frames | Frame count | |
| ports | The center in cycles per frame, then Q |
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().
|
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().
|
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().
|
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().
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
The parameters, for tools.