16#ifndef SBL_DSP_PRIMITIVES_SLEW_LIMITER_HPP_
17#define SBL_DSP_PRIMITIVES_SLEW_LIMITER_HPP_
34 void set_rate(
float rate) { rise_rate_ = rate; fall_rate_ = rate; }
42 float diff = target - state_;
45 if (diff > rise_rate_) {
50 }
else if (diff < 0.0f) {
51 if (-diff > fall_rate_) {
59 delta_ = (target >= state_) ? (target - state_) : (state_ - target);
65 float value()
const {
return state_; }
68 float delta()
const {
return delta_; }
71 void reset() { state_ = 0.0f; delta_ = 0.0f; }
74 void reset(
float initial) { state_ = initial; delta_ = 0.0f; }
77 float rise_rate_ = 0.0f;
78 float fall_rate_ = 0.0f;
void set_rate(float rate)
Set both rise and fall rates to the same value.
void set_fall_rate(float rate)
Set maximum decrease per sample.
float value() const
Current output value.
void set_rise_rate(float rate)
Set maximum increase per sample.
float process(float target)
Process one sample toward target with rate limiting.
void reset()
Reset to zero.
float delta() const
Distance from current state to last processed target (absolute)
void reset(float initial)
Reset to a specific value.
Stateful, single-concern building blocks.