Generic nonlinear model of 4-pole OTA-based ladder filters with separated outputs.
This algorithm can approximate, e.g., SSM2040- and CEM3320-based VCF circuits.
The feedforward branch consists of 4 nonlinear 1-pole lowpass filters with unitary dc gain in series, where the input to the first one is the difference between the algorithm input and the feedback signals, followed by a linear 1-pole highpass filter. The nonlinearity in each lowpass stage effectively limits the slew rate of its output signal.
The feedback branch contains a feedforward/input signal mixer, a linear gain stage, a saturation stage with compensated input bias, and finally another linear gain stage.
The cutoff and feedback gains implement parameter modulation as detailed in bwp_mod_func. Cutoff modulation is however internally limited to avoid instability.
Version: 1.0.0
License: proprietary license
We can privately hand you one or more example plugins if you are interested.
Module type: DSP
typedef struct bwp_ladder4_ota_coeffs bwp_ladder4_ota_coeffs;
Coefficients and related.
typedef struct bwp_ladder4_ota_state bwp_ladder4_ota_state;
Internal state and related.
static inline void bwp_ladder4_ota_init(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs);
Initializes input parameter values in coeffs.
static inline void bwp_ladder4_ota_set_sample_rate(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
float sample_rate);
Sets the sample_rate (Hz) value in coeffs.
static inline void bwp_ladder4_ota_reset_coeffs(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs);
Resets coefficients in coeffs to assume their target values.
static inline void bwp_ladder4_ota_reset_state(
const bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
bwp_ladder4_ota_state * BW_RESTRICT state,
char self_osc,
float x_0,
float * BW_RESTRICT y_lp1_0,
float * BW_RESTRICT y_lp2_0,
float * BW_RESTRICT y_lp3_0,
float * BW_RESTRICT y_lp4_0,
float * BW_RESTRICT y_hp_0);
Resets the given state to its initial values using the given coeffs, the initial input value x_0.
The corresponding initial 1st-, 2nd-, 3rd-, and 4th-order lowpass output values are put into y_lp1_0, y_lp2_0, y_lp3_0, and y_lp4_0 respectively, while the corresponding initial highpass output value is put into y_hp_0.
If self_osc is 1, initial states are computed taking eventual self-oscillation into account. Please note that this calculation is approximate and relatively computationally expensive. Otherwise, set it to 0 to not take self-oscillation into account. Other values for this argument are reserved.
static inline void bwp_ladder4_ota_reset_state_multi(
const bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
bwp_ladder4_ota_state * BW_RESTRICT const * BW_RESTRICT state,
char self_osc,
const float * x_0,
float * y_lp1_0,
float * y_lp2_0,
float * y_lp3_0,
float * y_lp4_0,
float * y_hp_0,
size_t n_channels);
Resets each of the n_channels states to its initial values using the given coeffs and the corresponding initial input value in the x_0 array.
The corresponding initial 1st-, 2nd-, 3rd-, and 4th-order lowpass output values are put into the y_lp1_0, y_lp2_0, y_lp3_0, and y_lp4_0 arrays, respectively, if they are not BW_NULL. Similarly, the corresponding initial highpass output values are put into the y_hp_0 array if it is not BW_NULL.
If self_osc is 1, initial states are computed taking eventual self-oscillation into account. Please note that this calculation is approximate and relatively computationally expensive. Otherwise, set it to 0 to not take self-oscillation into account. Other values for this argument are reserved.
static inline void bwp_ladder4_ota_update_coeffs_ctrl(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs);
Triggers control-rate update of coefficients in coeffs.
static inline void bwp_ladder4_ota_update_coeffs_audio(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs);
Triggers audio-rate update of coefficients in coeffs.
static inline void bwp_ladder4_ota_process1(
const bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
bwp_ladder4_ota_state * BW_RESTRICT state,
float x,
float * BW_RESTRICT y_lp1,
float * BW_RESTRICT y_lp2,
float * BW_RESTRICT y_lp3,
float * BW_RESTRICT y_lp4,
float * BW_RESTRICT y_hp);
static inline void bwp_ladder4_ota_process1_mod_cutoff(
const bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
bwp_ladder4_ota_state * BW_RESTRICT state,
float x,
float x_mod_cutoff,
float * BW_RESTRICT y_lp1,
float * BW_RESTRICT y_lp2,
float * BW_RESTRICT y_lp3,
float * BW_RESTRICT y_lp4,
float * BW_RESTRICT y_hp);
static inline void bwp_ladder4_ota_process1_mod_feedback_pre_gain(
const bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
bwp_ladder4_ota_state * BW_RESTRICT state,
float x,
float x_mod_feedback_pre_gain,
float * BW_RESTRICT y_lp1,
float * BW_RESTRICT y_lp2,
float * BW_RESTRICT y_lp3,
float * BW_RESTRICT y_lp4,
float * BW_RESTRICT y_hp);
static inline void bwp_ladder4_ota_process1_mod_feedback_post_gain(
const bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
bwp_ladder4_ota_state * BW_RESTRICT state,
float x,
float x_mod_feedback_post_gain,
float * BW_RESTRICT y_lp1,
float * BW_RESTRICT y_lp2,
float * BW_RESTRICT y_lp3,
float * BW_RESTRICT y_lp4,
float * BW_RESTRICT y_hp);
static inline void bwp_ladder4_ota_process1_mod_cutoff_feedback_pre_gain(
const bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
bwp_ladder4_ota_state * BW_RESTRICT state,
float x,
float x_mod_cutoff,
float x_mod_feedback_pre_gain,
float * BW_RESTRICT y_lp1,
float * BW_RESTRICT y_lp2,
float * BW_RESTRICT y_lp3,
float * BW_RESTRICT y_lp4,
float * BW_RESTRICT y_hp);
static inline void bwp_ladder4_ota_process1_mod_cutoff_feedback_post_gain(
const bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
bwp_ladder4_ota_state * BW_RESTRICT state,
float x,
float x_mod_cutoff,
float x_mod_feedback_post_gain,
float * BW_RESTRICT y_lp1,
float * BW_RESTRICT y_lp2,
float * BW_RESTRICT y_lp3,
float * BW_RESTRICT y_lp4,
float * BW_RESTRICT y_hp);
static inline void bwp_ladder4_ota_process1_mod_feedback_pre_gain_feedback_post_gain(
const bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
bwp_ladder4_ota_state * BW_RESTRICT state,
float x,
float x_mod_feedback_pre_gain,
float x_mod_feedback_post_gain,
float * BW_RESTRICT y_lp1,
float * BW_RESTRICT y_lp2,
float * BW_RESTRICT y_lp3,
float * BW_RESTRICT y_lp4,
float * BW_RESTRICT y_hp);
static inline void bwp_ladder4_ota_process1_mod_cutoff_feedback_pre_gain_feedback_post_gain(
const bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
bwp_ladder4_ota_state * BW_RESTRICT state,
float x,
float x_mod_cutoff,
float x_mod_feedback_pre_gain,
float x_mod_feedback_post_gain,
float * BW_RESTRICT y_lp1,
float * BW_RESTRICT y_lp2,
float * BW_RESTRICT y_lp3,
float * BW_RESTRICT y_lp4,
float * BW_RESTRICT y_hp);
These function process one input sample x using coeffs, while using and updating state. The 1st-, 2nd-, 3rd-, and 4th-order lowpass output samples are put into y_lp1, y_lp2, y_lp3, and y_lp4 respectively. Highpass output samples are put into y_hp.
They take various combinations of audio-rate modulation signals as input, namely x_mod_cutoff, x_mod_feedback_pre_gain, and x_mod_feedback_post_gain.
static inline void bwp_ladder4_ota_process(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
bwp_ladder4_ota_state * BW_RESTRICT state,
const float * x,
const float * x_mod_cutoff,
const float * x_mod_feedback_pre_gain,
const float * x_mod_feedback_post_gain,
float * y_lp1,
float * y_lp2,
float * y_lp3,
float * y_lp4,
float * y_hp,
size_t n_samples);
Processes the first n_samples of the input buffer x and fills the first n_samples of the output buffers y_lp1, y_lp2, y_lp3, y_lp4, and y_hp (1st-, 2nd-, 3rd-, 4th-order lowpass, and highpass, respectively), if they are not BW_NULL, while using and updating both coeffs and state (control and audio rate).
If x_mod_cutoff is not BW_NULL, it is used as a source of cutoff frequency modulation. The same holds for x_mod_feedback_pre_gain w.r.t. pre-saturation feedback gain modulation and for x_mod_feedback_post_gain w.r.t. post-saturation feedback gain modulation.
static inline void bwp_ladder4_ota_process_multi(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
bwp_ladder4_ota_state * BW_RESTRICT const * BW_RESTRICT state,
const float * const * x,
const float * const * x_mod_cutoff,
const float * const * x_mod_feedback_pre_gain,
const float * const * x_mod_feedback_post_gain,
float * const * y_lp1,
float * const * y_lp2,
float * const * y_lp3,
float * const * y_lp4,
float * const * y_hp,
size_t n_channels,
size_t n_samples);
Processes the first n_samples of the n_channels input buffers x and fills the first n_samples of the n_channels output buffers y_lp1, y_lp2, y_lp3, y_lp4, and y_hp (1st-, 2nd-, 3rd-, 4th-order lowpass, and highpass, respectively), while using and updating both the common coeffs and each of the n_channels states (control and audio rate).
If x_mod_cutoff and the channel-specific element are not BW_NULL, this is used as a source of cutoff frequency modulation for that channel. The same hold for x_mod_feedback_pre_gain w.r.t. pre-saturation feedback gain modulation and for x_mod_feedback_post_gain w.r.t. post-saturation feedback gain modulation.
y_lp1, y_lp2, y_lp3, y_lp4, and y_hp or any of their elements may be BW_NULL.
static inline void bwp_ladder4_ota_set_cutoff(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
float value);
Sets the cutoff frequency to the given value (Hz) in coeffs.
Valid range: [1e-6f, 1e12f].
Default value: 1e3f.
static inline void bwp_ladder4_ota_set_cutoff_mod(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
float value);
Sets the non-smoothed cutoff frequency modulation component to the given value in coeffs.
value must be finite.
Default value: 0.f.
static inline void bwp_ladder4_ota_set_hp_cutoff(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
float value);
Sets the cutoff frequency of the 1-pole highpass filter to the given value (Hz) in coeffs.
Valid range: [1e-6f, 1e12f].
Default value: 1.f.
static inline void bwp_ladder4_ota_set_feedback_x_gain(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
float value);
Sets the input gain in the feedback mix to value (linear gain) in coeffs.
value must be finite.
Default value: 0.f.
static inline void bwp_ladder4_ota_set_feedback_pre_gain(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
float value);
Sets the pre-saturation feedback gain to the value in coeffs.
value must be finite.
Default value: 1.f.
static inline void bwp_ladder4_ota_set_feedback_pre_gain_mod(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
float value);
Sets the non-smoothed cutoff pre-saturation feedback gain modulation component to the given value in coeffs.
value must be finite.
Default value: 0.f.
static inline void bwp_ladder4_ota_set_feedback_post_gain(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
float value);
Sets the post-saturation feedback gain to the value in coeffs.
value must be finite.
Default value: 0.f.
static inline void bwp_ladder4_ota_set_feedback_post_gain_mod(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
float value);
Sets the non-smoothed cutoff post-saturation feedback gain modulation component to the given value in coeffs.
value must be finite.
Default value: 0.f.
static inline void bwp_ladder4_ota_set_stage_max_rate(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
float value);
Sets the maximum slew rate in feedforward lowpass stages to the given value (1/s) in coeffs.
Valid range: [1e-12f, 1e12f].
Default value: 1e6f.
static inline void bwp_ladder4_ota_set_feedback_clip(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
float value);
Sets the feedback clipping level to the given value in coeffs.
Valid range: [1e-12f, 1e12f].
Default value: 1.f.
static inline void bwp_ladder4_ota_set_feedback_bias(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
float value);
Sets the feedback satuation bias to the given value in coeffs.
This value is relative to the saturation curve, that is, changing feedback_clip affects the absolute bias level too. In other words still, the saturation function will typically have the form
y = a * f(b * (x + bias))
where a and b depend on feedback_clip.
Valid range: [-1e12f, 1e12f].
Default value: 0.f.
static inline void bwp_ladder4_ota_set_mod_func_cutoff(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
bwp_mod_func value);
Sets the cutoff frequency modulation function.
Default value: bwp_mod_func_pow2.
static inline void bwp_ladder4_ota_set_mod_func_feedback_pre_gain(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
bwp_mod_func value);
Sets the pre-saturation feedback gain modulation function.
Default value: bwp_mod_func_sum.
static inline void bwp_ladder4_ota_set_mod_func_feedback_post_gain(
bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
bwp_mod_func value);
Sets the post-saturation feedback gain modulation function.
Default value: bwp_mod_func_sum.
static inline char bwp_ladder4_ota_coeffs_is_valid(
const bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs);
Tries to determine whether coeffs is valid and returns non-0 if it seems to be the case and 0 if it is certainly not. False positives are possible, false negatives are not.
coeffs must at least point to a readable memory block of size greater than or equal to that of bwp_ladder4_ota_coeffs.
static inline char bwp_ladder4_ota_state_is_valid(
const bwp_ladder4_ota_coeffs * BW_RESTRICT coeffs,
const bwp_ladder4_ota_state * BW_RESTRICT state);
Tries to determine whether state is valid and returns non-0 if it seems to be the case and 0 if it is certainly not. False positives are possible, false negatives are not.
If coeffs is not BW_NULL extra cross-checks might be performed (state is supposed to be associated to coeffs).
state must at least point to a readable memory block of size greater than or equal to that of bwp_ladder4_ota_state.
template<size_t N_CHANNELS = 1>
class Ladder4OTA {
public:
Ladder4OTA();
void setSampleRate(
float sampleRate);
void reset(
char selfOsc = 0,
float x0 = 0.f,
float * BW_RESTRICT yLp10 = BW_NULL,
float * BW_RESTRICT yLp20 = BW_NULL,
float * BW_RESTRICT yLp30 = BW_NULL,
float * BW_RESTRICT yLp40 = BW_NULL,
float * BW_RESTRICT yHp0 = BW_NULL);
# ifndef BW_CXX_NO_ARRAY
void reset(
char selfOsc,
float x0,
std::array<float, N_CHANNELS> * BW_RESTRICT yLp10,
std::array<float, N_CHANNELS> * BW_RESTRICT yLp20,
std::array<float, N_CHANNELS> * BW_RESTRICT yLp30,
std::array<float, N_CHANNELS> * BW_RESTRICT yLp40,
std::array<float, N_CHANNELS> * BW_RESTRICT yHp0);
# endif
void reset(
char selfOsc,
const float * x0,
float * yLp10 = BW_NULL,
float * yLp20 = BW_NULL,
float * yLp30 = BW_NULL,
float * yLp40 = BW_NULL,
float * yHp0 = BW_NULL);
# ifndef BW_CXX_NO_ARRAY
void reset(
char selfOsc,
std::array<float, N_CHANNELS> x0,
std::array<float, N_CHANNELS> * BW_RESTRICT yLp10 = BW_NULL,
std::array<float, N_CHANNELS> * BW_RESTRICT yLp20 = BW_NULL,
std::array<float, N_CHANNELS> * BW_RESTRICT yLp30 = BW_NULL,
std::array<float, N_CHANNELS> * BW_RESTRICT yLp40 = BW_NULL,
std::array<float, N_CHANNELS> * BW_RESTRICT yHp0 = BW_NULL);
# endif
void process(
const float * const * x,
const float * const * xModCutoff,
const float * const * xModFeedbackPreGain,
const float * const * xModFeedbackPostGain,
float * const * yLp1,
float * const * yLp2,
float * const * yLp3,
float * const * yLp4,
float * const * yHp,
size_t nSamples);
# ifndef BW_CXX_NO_ARRAY
void process(
std::array<const float *, N_CHANNELS> x,
std::array<const float *, N_CHANNELS> xModCutoff,
std::array<const float *, N_CHANNELS> xModFeedbackPreGain,
std::array<const float *, N_CHANNELS> xModFeedbackPostGain,
std::array<float *, N_CHANNELS> yLp1,
std::array<float *, N_CHANNELS> yLp2,
std::array<float *, N_CHANNELS> yLp3,
std::array<float *, N_CHANNELS> yLp4,
std::array<float *, N_CHANNELS> yHp,
size_t nSamples);
# endif
void setCutoff(
float value);
void setCutoffMod(
float value);
void setHpCutoff(
float value);
void setFeedbackXGain(
float value);
void setFeedbackPreGain(
float value);
void setFeedbackPreGainMod(
float value);
void setFeedbackPostGain(
float value);
void setFeedbackPostGainMod(
float value);
void setStageMaxRate(
float value);
void setFeedbackClip(
float value);
void setFeedbackBias(
float value);
void setModFuncCutoff(
bwp_mod_func value);
void setModFuncFeedbackPreGain(
bwp_mod_func value);
void setModFuncFeedbackPostGain(
bwp_mod_func value);
...
}