23template<
typename T =
float>
27 explicit SmoothedValue(T initial) : current_(initial), target_(initial) {}
37 constexpr int kMaxRampSamples = (std::numeric_limits<int>::max)();
38 if (!std::isfinite(seconds) || !std::isfinite(sample_rate) || seconds <= T(0) ||
39 sample_rate <= T(0)) {
46 const long double sample_count_wide =
47 static_cast<long double>(seconds) *
static_cast<long double>(sample_rate);
48 if (!std::isfinite(sample_count_wide) ||
49 sample_count_wide >
static_cast<long double>(kMaxRampSamples)) {
50 ramp_samples_ = kMaxRampSamples;
53 ramp_samples_ =
static_cast<int>(seconds * sample_rate);
54 if (ramp_samples_ < 1) ramp_samples_ = 1;
60 if (ramp_samples_ <= 1) {
65 increment_ = (target_ - current_) /
static_cast<T
>(ramp_samples_);
66 steps_remaining_ = ramp_samples_;
80 if (steps_remaining_ > 0) {
81 current_ += increment_;
83 if (steps_remaining_ == 0) current_ = target_;
91 if (steps_remaining_ <= 0)
return;
92 if (n >= steps_remaining_) {
96 current_ += increment_ *
static_cast<T
>(n);
97 steps_remaining_ -= n;
112 int ramp_samples_ = 1;
113 int steps_remaining_ = 0;
Linear smoothing for control-rate parameters.
Definition smoothed_value.hpp:24
void set_target(T value)
Definition smoothed_value.hpp:58
T next()
Definition smoothed_value.hpp:79
void skip(int n)
Definition smoothed_value.hpp:89
void set_immediate(T value)
Definition smoothed_value.hpp:71
SmoothedValue(T initial)
Definition smoothed_value.hpp:27
T target() const
Definition smoothed_value.hpp:106
void set_ramp_time(T seconds, T sample_rate)
RT contract: this helper stores only scalar state and allocates no memory.
Definition smoothed_value.hpp:34
bool is_smoothing() const
Definition smoothed_value.hpp:102
T current() const
Definition smoothed_value.hpp:105
Definition additive_bank.hpp:218
SmoothedValue< double > SmoothedValue64
Definition smoothed_value.hpp:116