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
crossfade_ramp.hpp
Go to the documentation of this file.
1// sbl/dsp/primitives/crossfade_ramp.hpp — A gain ramped linearly across one block
2//
3// A mix or a gain that stepped at block rate would click; this carries it
4// from last block's value to this block's, one equal step per sample.
5
6#ifndef SBL_DSP_PRIMITIVES_CROSSFADE_RAMP_HPP_
7#define SBL_DSP_PRIMITIVES_CROSSFADE_RAMP_HPP_
8
9#include <cstdint>
10
11namespace sbl::dsp::primitives {
12
14public:
15 /// @note All public methods are ISR-safe — bounded computation, no I/O.
16
17 /// Start a block that ends at `target` after `n` steps.
18 void begin(float target, uint16_t n) {
19 step_ = (target - value_) / static_cast<float>(n);
20 end_ = target;
21 }
22
23 /// The value for the next sample.
24 float next() { return value_ += step_; }
25
26 /// Close the block exactly on its target, so rounding never drifts.
27 void end() { value_ = end_; }
28
29 float value() const { return value_; }
30 void reset(float value) { value_ = value; end_ = value; step_ = 0.0f; }
31
32private:
33 float value_ = 0.0f;
34 float end_ = 0.0f;
35 float step_ = 0.0f;
36};
37
38} // namespace sbl::dsp::primitives
39
40#endif // SBL_DSP_PRIMITIVES_CROSSFADE_RAMP_HPP_
void end()
Close the block exactly on its target, so rounding never drifts.
void begin(float target, uint16_t n)
Start a block that ends at target after n steps.
float next()
The value for the next sample.
Stateful, single-concern building blocks.