42template <
typename SampleType =
float>
51 sample_rate_ = sr > 0.0 ? sr : sample_rate_;
52 vactrol_.prepare(sample_rate_);
65 void set_colour(
double amount) { colour_ = std::clamp(amount, 0.0, 1.0); }
69 closed_hz_ = std::clamp(hz, 10.0, 20000.0);
75 open_hz_ = std::clamp(hz, 10.0, 20000.0);
91 double control()
const {
return vactrol_.control(); }
96 SampleType
process(SampleType input,
double target) {
97 const double control_ = vactrol_.process(target);
99 const double vca = std::pow(control_, gain_exponent_);
103 double x =
static_cast<double>(input) * (1.0 - (1.0 - colour_) * (1.0 - vca));
108 gate_filter_.set_cutoff(
static_cast<SampleType
>(
109 closed_limit_ * std::pow(open_limit_ / closed_limit_, control_)));
110 const double filtered = gate_filter_.process_lowpass(
static_cast<SampleType
>(x));
113 x = x + colour_ * (filtered - x);
114 return static_cast<SampleType
>(x);
119 gate_filter_.prepare(
static_cast<SampleType
>(sample_rate_));
120 const double nyquist = 0.49 * sample_rate_;
121 open_limit_ = std::min(open_hz_, nyquist);
122 closed_limit_ = std::min(closed_hz_, nyquist);
125 double sample_rate_ = 44100.0;
126 double colour_ = 0.5;
127 double closed_hz_ = 60.0;
128 double open_hz_ = 12000.0;
129 double gain_exponent_ = 1.5;
131 double open_limit_ = 12000.0;
132 double closed_limit_ = 60.0;
134 VactrolConditionerT<SampleType> vactrol_{};
135 TptFilterT<SampleType> gate_filter_;
A lowpass gate: an amplitude gate and a lowpass filter driven by one control signal with deliberately...
Definition lowpass_gate.hpp:43
SampleType process(SampleType input, double target)
Advances the vactrol by one sample toward target and applies the resulting gate to input.
Definition lowpass_gate.hpp:96
void set_open_cutoff_hz(double hz)
Filter corner when the gate is fully open, in Hz.
Definition lowpass_gate.hpp:74
double control() const
Current smoothed control value in [0, 1].
Definition lowpass_gate.hpp:91
void set_rise_ms(double ms)
Time constant of the vactrol turning on, in milliseconds.
Definition lowpass_gate.hpp:58
void set_gain_exponent(double e)
Exponent of the control-to-gain law.
Definition lowpass_gate.hpp:82
void set_colour(double amount)
Blend between amplitude gating (0) and filtering (1).
Definition lowpass_gate.hpp:65
void reset()
Definition lowpass_gate.hpp:84
void set_sample_rate(double sr)
Definition lowpass_gate.hpp:50
LowpassGateT()
A default-constructed gate is usable at 44.1 kHz without a setup call, so a caller that only override...
Definition lowpass_gate.hpp:48
void set_closed_cutoff_hz(double hz)
Filter corner when the gate is fully closed, in Hz.
Definition lowpass_gate.hpp:68
void set_fall_ms(double ms)
Time constant of the vactrol turning off, in milliseconds.
Definition lowpass_gate.hpp:62
Definition additive_bank.hpp:218
LowpassGateT< double > LowpassGate64
Definition lowpass_gate.hpp:139
@ e
Definition formant_filter_bank.hpp:20
LowpassGateT< float > LowpassGate
Definition lowpass_gate.hpp:138
First-order topology-preserving transform (TPT) filter.
The vactrol control-conditioning law: an asymmetric one-pole whose rise and fall are deliberately dif...