Sound Byte Libs 0.5.1-121-g3358a44
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
smoothed_port.hpp
Go to the documentation of this file.
1// sbl/dsp/primitives/smoothed_port.hpp — A port's target, its smoother and its last value
2//
3// The pattern every widget hand-expanded (RPT-035 F2): a setter stores a
4// target, process() advances a smoother toward it by the block length, and
5// the smoothed value is what the widget applies. Setters only store, so a
6// setter and process() can run in different contexts.
7
8#ifndef SBL_DSP_PRIMITIVES_SMOOTHED_PORT_HPP_
9#define SBL_DSP_PRIMITIVES_SMOOTHED_PORT_HPP_
10
11#include <cstdint>
12
14
15namespace sbl::dsp::primitives {
16
18public:
19 /// @note All public methods are ISR-safe — bounded computation, no I/O.
20
21 /// Settling time, at the rate the smoother is advanced at (per sample here).
22 void set_time_ms(float ms, float rate_hz) { smoother_.set_time_ms(ms, rate_hz); }
23
24 /// The port's setter stores here; nothing moves until advance().
25 void set(float target) { target_ = target; }
26 float target() const { return target_; }
27
28 /// Advance by a block: the smoothed value to apply for this block.
29 float advance(uint16_t n) {
30 value_ = smoother_.process_steps(target_, n);
31 return value_;
32 }
33
34 float value() const { return value_; }
35
36 /// Snap to the target: what reset() does, so ports start where they were set.
37 void reset() {
38 smoother_.reset(target_);
39 value_ = target_;
40 }
41
42private:
43 ParameterSmoother smoother_;
44 float target_ = 0.0f;
45 float value_ = 0.0f;
46};
47
48} // namespace sbl::dsp::primitives
49
50#endif // SBL_DSP_PRIMITIVES_SMOOTHED_PORT_HPP_
void set_time_ms(float ms, float rate_hz)
Compute coefficient from settling time in milliseconds.
float process_steps(float target, uint32_t n)
Advance n steps toward target in one call.
void set(float target)
The port's setter stores here; nothing moves until advance().
void set_time_ms(float ms, float rate_hz)
Settling time, at the rate the smoother is advanced at (per sample here).
void reset()
Snap to the target: what reset() does, so ports start where they were set.
float advance(uint16_t n)
Advance by a block: the smoothed value to apply for this block.
Stateful, single-concern building blocks.
One-pole parameter smoother.