|
| | ~LadderFilter ()=default |
| |
| void | prepare (const AudioSpec &spec) noexcept |
| | Prepares the filter with the current audio environment.
|
| |
| void | processBlock (AudioBufferView< T > buffer) noexcept |
| | Processes an audio buffer in-place (thread-safe vs. setters).
|
| |
| T | processSample (T input, int channel) noexcept |
| | Processes a single sample on one channel.
|
| |
| void | reset () noexcept |
| | Clears the internal integrator state.
|
| |
| void | setCutoff (T hz) noexcept |
| | Sets the cutoff frequency (thread-safe, lock-free).
|
| |
| void | setResonance (T amount) noexcept |
| | Sets resonance amount (thread-safe, lock-free).
|
| |
| void | setDrive (T amount) noexcept |
| | Sets the nonlinear drive amount (thread-safe, lock-free).
|
| |
| void | setMode (Mode mode) noexcept |
| | Sets the filter output mode (thread-safe, lock-free).
|
| |
| void | setSaturation (Saturation model) noexcept |
| | Selects the saturation model (thread-safe, lock-free).
|
| |
| std::vector< uint8_t > | getState () const |
| | Serializes the parameters (setup/UI threads; allocates).
|
| |
| bool | setState (const uint8_t *data, size_t size) |
| | Restores parameters from a blob (tolerant; rejects foreign ids).
|
| |
| T | getCutoff () const noexcept |
| |
| T | getResonance () const noexcept |
| |
| T | getDrive () const noexcept |
| |
| Mode | getMode () const noexcept |
| |
| Saturation | getSaturation () const noexcept |
| |
template<FloatType T>
class dspark::LadderFilter< T >
4-pole resonant ladder filter (Moog topology, TPT discretization).
Four cascaded one-pole TPT lowpass stages with global feedback. The zero-delay feedback loop is resolved analytically each sample, and the multimode outputs are tap mixes of the cascade. processBlock() snapshots the parameters once per block and dispatches to a per-mode template instantiation, so the sample loop carries no branches.
Three saturation models (setSaturation()):
- Feedback (default): linear stages, with drive > 1 shaping only the resonance feedback through a bounded tanh. Cheapest (no iteration).
- Stages: the transistor-ladder model in which every stage saturates, dy_i/dt = wc [phi(y_{i-1}) - phi(y_i)], phi(v) = tanh(drive v) / drive, solved implicitly per sample (detail::ladderStepStages()). Against a 128x oversampled reference of the same equations (48 kHz, 110 Hz full-scale sine, drive 1 and 3, resonance 0 to 0.9) every harmonic above -80 dBc lands within 0.23 dB up to a 2 kHz cutoff and within 1.7 dB at 8 kHz (the frequency-warping limit of any trapezoidal solve at the base rate). It self-oscillates above resonance 1 at a level the stages set: at resonance 1.1 the pitch is within 0.1 cents of the reference up to a 1 kHz cutoff, 1.5 cents at 4 kHz and 7.9 cents at 10 kHz, and the level within 0.07 dB. It changes the character, so it is opt-in. It costs several times the Feedback model (see setSaturation()).
- Input: linear stages and one saturator on the loop input, y_0 = phi(x - k y_4), run in four sub-steps per sample with the loop closed without delay in each (detail::ladderStepInput()). The sub-steps put the frequency warping of the integrators and the aliasing of the saturator two octaves further up. At 48 kHz, against a 32x oversampled solve of the same equations (110 Hz full-scale sine, drive 1 and 3, resonance 0 to 0.9) every harmonic above -80 dBc lands within 0.05 dB at cutoffs from 250 Hz to 20 kHz. The resonance peak is within 0.25 cents of the analog one up to an 8 kHz cutoff, 0.9 cents at 16 kHz and 1.1 at 20 kHz (the other two models: 3.8, 13 and 18 cents sharp), and with the resonance at 0 the small-signal response is within 0.5 dB of the analog four-pole up to 15 kHz at any cutoff (-0.6 to -2.1 dB at 20 kHz). A full-scale 5 kHz tone at drive 3 and resonance 0.5 aliases at -45 to -61 dBc over cutoffs from 500 Hz to 20 kHz. It costs the same at every cutoff and resonance, below Stages at every setting measured (see setSaturation()). It is a third character, so it is opt-in as well.
Contract notes:
- Like the analog original, the passband gain drops by 1/(1 + 4*resonance) as resonance rises (about -14 dB at resonance 1). Compensate externally if loudness-matched sweeps are needed.
- Feedback model: drive saturates the resonance feedback path only: with resonance at 0 it has no effect on the signal. With drive > 1 the bounded tanh stage keeps self-oscillation (resonance = 1) at a finite level; at drive <= 1 the loop is exactly marginal at resonance = 1, so sustained input at the cutoff accumulates without decay - back off resonance slightly or engage drive for stable self-oscillation.
- Stages model: drive is the level at which the stages saturate (a full-scale signal at drive 1 sits at the tanh(1) knee), at any drive. Its cutoff is limited to 0.45 * fs (detail::kLadderStagesMaxGain).
- Input model: drive is the level at which the loop input (the input minus the resonance feedback) saturates, at any drive and resonance: with the resonance at 0, a full-scale signal at drive 1 sits at the tanh(1) knee. Above resonance 1 it self-oscillates at a level the saturator sets. Its cutoff reaches 0.499 * fs, like the Feedback model's. The HP24 output is taken from the saturated loop input. The input is interpolated across the sub-steps and the output is their mean, each with a one-pole level correction; the first sample after another model or a reset starts both histories.
- Channels beyond kMaxChannels (16) pass through unprocessed.
- Mode and saturation model can be switched while running; the integrator state is continuous.
- Template Parameters
-
| T | Sample type (float or double). Must satisfy FloatType concept. |
Definition at line 120 of file LadderFilter.h.
Selects the saturation model (thread-safe, lock-free).
Feedback (the default) keeps the stages linear. Stages saturates every stage and solves the loop implicitly: a clipped Newton iteration in double, 2.1 steps on average and at most 7 measured (cap 16). It costs 38 to 100 ns per sample (mono) against 10 to 19 ns for Feedback (MSVC x64, float), rising with cutoff, drive and the noisiness of the input: 54 ns at a 1 kHz cutoff with drive 3; at 15 kHz with drive 3, 54-58 ns for sines and a saw and 98 ns for white noise. Channel pairs are solved together, which lowers the cost per channel by 10-20 % in stereo.
Input saturates the loop input and runs four sub-steps per sample, the same work at every cutoff and resonance: 53 to 74 ns per sample in mono depending on the machine (float; GCC, Clang and MSVC on x64 and GCC on arm64) and 35 to 48 ns per channel for channel pairs, which advance together. A saturator driven past the limit of its tanh skips its division (at drive 10, from 16% less to 4% more). On the same machine and settings that is 1.5 to 4.0 times Feedback and 0.30 to 0.95 times Stages.
The integrator state carries over a switch. Out-of-range values (a wild cast or a corrupt state blob) select Feedback.
- Parameters
-
Definition at line 395 of file LadderFilter.h.