51template <
typename SampleType =
float>
70 sample_rate_ = sample_rate > 0.0 ? sample_rate : sample_rate_;
84 double rise_ms()
const {
return rise_ms_; }
85 double fall_ms()
const {
return fall_ms_; }
87 void reset() { control_ = 0.0; }
90 double control()
const {
return control_; }
99 if (!std::isfinite(target)) {
103 const double clamped = std::clamp(target, 0.0, 1.0);
104 const double coefficient = clamped > control_ ? rise_a_ : fall_a_;
105 control_ =
snap_to_zero(control_ + coefficient * (clamped - control_));
115 rise_a_ = 1.0 - std::exp(-1.0 / std::max(0.001 * rise_ms_ * sample_rate_, 1
e-9));
116 fall_a_ = 1.0 - std::exp(-1.0 / std::max(0.001 * fall_ms_ * sample_rate_, 1
e-9));
119 double sample_rate_ = 44100.0;
122 double rise_a_ = 0.0;
123 double fall_a_ = 0.0;
124 double control_ = 0.0;
The asymmetric one-pole that lags a control signal the way a photoresistor lags its LED.
Definition vactrol.hpp:52
static constexpr double kMinFallMs
Definition vactrol.hpp:63
double rise_ms() const
Definition vactrol.hpp:84
void reset()
Definition vactrol.hpp:87
static constexpr double kMaxFallMs
Definition vactrol.hpp:64
double fall_ms() const
Definition vactrol.hpp:85
void set_fall_ms(double ms)
Definition vactrol.hpp:79
void set_rise_ms(double ms)
Definition vactrol.hpp:74
double process(double target)
Advances one sample toward target (clamped to [0, 1]) and returns the conditioned control.
Definition vactrol.hpp:94
static constexpr double kMaxRiseMs
Definition vactrol.hpp:57
static constexpr double kDefaultRiseMs
Definition vactrol.hpp:58
static constexpr double kDefaultFallMs
Definition vactrol.hpp:65
double control() const
Current conditioned control in [0, 1] without advancing.
Definition vactrol.hpp:90
static constexpr double kMinRiseMs
Definition vactrol.hpp:56
void prepare(double sample_rate)
Definition vactrol.hpp:69
VactrolConditionerT()
Definition vactrol.hpp:67
Definition additive_bank.hpp:218
VactrolConditionerT< double > VactrolConditioner64
Definition vactrol.hpp:128
T snap_to_zero(T x)
Returns 0 if |x| < snap_threshold, else x.
Definition denormal.hpp:45
@ e
Definition formant_filter_bank.hpp:20
VactrolConditionerT< float > VactrolConditioner
Definition vactrol.hpp:127