52template <
typename SampleType =
float>
67 sample_rate_ = std::isfinite(
static_cast<double>(sample_rate)) &&
68 sample_rate > SampleType{0}
79 if (!std::isfinite(db))
return;
86 if (!std::isfinite(ms))
return;
87 lag_ms_ = std::max(0.0, ms);
99 if (!std::isfinite(
static_cast<double>(
control)))
return SampleType{0};
100 const SampleType
c = std::clamp(
control, SampleType{0}, SampleType{1});
101 if (response_ == Response::linear)
return c;
102 if (
c <= SampleType{0})
return SampleType{0};
105 if (
c >= SampleType{1})
return SampleType{1};
106 return static_cast<SampleType
>(
107 std::pow(10.0, (-range_db_ / 20.0) *
108 (1.0 -
static_cast<double>(
c))));
113 if (!std::isfinite(
static_cast<double>(
control)))
control = SampleType{0};
114 const SampleType target = std::clamp(
control, SampleType{0}, SampleType{1});
118 if (target != last_control_) {
119 lag_.set_target(target);
120 last_control_ = target;
131 SampleType
control()
const {
return lag_.current(); }
135 lag_.set_ramp_time(
static_cast<SampleType
>(lag_ms_ * 0.001), sample_rate_);
138 SmoothedValue<SampleType> lag_{};
139 SampleType sample_rate_ = SampleType{48000};
140 SampleType last_control_ = SampleType{0};
143 Response response_ = Response::linear;
Voltage-controlled amplifier.
Definition vca.hpp:53
float control() const
Definition vca.hpp:131
static constexpr double kMaxRangeDb
Definition vca.hpp:59
static constexpr double kDefaultLagMs
Definition vca.hpp:64
void set_range_db(double db)
Definition vca.hpp:78
void set_response(Response r)
Definition vca.hpp:75
SampleType gain_for(SampleType control) const
Static response curve, without the lag.
Definition vca.hpp:98
void set_lag_ms(double ms)
Definition vca.hpp:85
static constexpr double kDefaultRangeDb
Definition vca.hpp:60
void prepare(SampleType sample_rate)
Definition vca.hpp:66
static constexpr double kMinRangeDb
Definition vca.hpp:58
double range_db() const
Definition vca.hpp:83
VcaResponse Response
Definition vca.hpp:55
void reset(SampleType control=SampleType{0})
Definition vca.hpp:91
SampleType next_gain(SampleType control)
Advance the lag by one sample and return the gain that would be applied.
Definition vca.hpp:112
Response response() const
Definition vca.hpp:76
SampleType process(SampleType input, SampleType control)
Definition vca.hpp:125
Definition additive_bank.hpp:218
VcaResponse
Definition vca.hpp:42
@ exponential
Definition mod_tools.hpp:106
@ c
Definition spectrum_trace.hpp:35
@ linear
2-point. Cheapest; audible imaging when pitching up.
Definition granular.hpp:133
VcaT< float > Vca
Definition vca.hpp:146
VcaT< double > Vca64
Definition vca.hpp:147