|
Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
|
A modulated phase walked frame by frame as segments, and the crossings of moving thresholds on them. More...
A modulated phase walked frame by frame as segments, and the crossings of moving thresholds on them.
The part of a threshold core that is not about its shape. Each frame its driver gives the phase, in [0, 1), the signed step that led there, in cycles, and a phase offset at the end of each of SUBSTEPS equal parts of the frame. The walk reads the phase plus the offset, and turns the frame into one Segment per part: the phase moving linearly from where the last part ended to where this one ends. A core corrects its events on those segments: where a threshold of its shape, moving across the frame, is crossed.
Each segment ends on the frame's phase less the step still ahead of it, plus the part's offset. Its step is the frame's step times the part's share, plus the offset's change since the last part. The step says how many wraps lie between the segment's two ends, round(start + step - end), so the phase may run forward, backward and through zero, and the ends are the phases themselves: a core's crossings always agree with the naive samples it reads at those phases, whatever rounding its driver's accumulator did.
Crossings are found on the unwrapped segment against the threshold and its images one cycle up and down, in either direction and across the wrap, and every image crossed is reported at its own time. Which side of the threshold each end lies on is read as phase >= threshold, the comparison a core reads its naive sample with, so a core's corrections sum to its naive change however the unwrapped end rounds.
Inputs and their handling, per part:
Below the signal transport: its inputs are natural units, set by the core that owns it. It holds the last part's phase and offset; all state advances per frame.
In a core's frame:
Definition at line 70 of file phase_walk.hpp.
#include <phase_walk.hpp>
Classes | |
| struct | Segment |
One part of a frame: the phase moving linearly from start to end plus wraps cycles. More... | |
Public Member Functions | |
| template<uint8_t SUBSTEPS, class OnSegment > | |
| void | frame (float phase, float step, const float(&offsets)[SUBSTEPS], OnSegment &&on_segment) |
One frame in SUBSTEPS equal parts, each given to on_segment as a Segment. | |
| void | reset (float phase=0.0f, float offset=0.0f) |
| Move to a phase plus an offset, the offset kept as the last part's. | |
| float | phase () const |
| The phase the last part ended on, the offset included, in [0, 1). | |
| float | offset () const |
| The offset the last part ended on, in cycles. | |
Static Public Member Functions | |
| template<class OnCrossing > | |
| static void | crossings (const Segment &s, float c0, float c1, OnCrossing &&on_crossing) |
| Report every image of a threshold crossed by a segment while the threshold moved c0 -> c1. | |
| static float | wrap (float x) |
| Wrap into [0, 1); a value that rounds up to 1 is 0. | |
Static Public Attributes | |
| static constexpr float | MAX_STEP = 1.0f |
|
inline |
One frame in SUBSTEPS equal parts, each given to on_segment as a Segment.
| SUBSTEPS | Parts per frame, at least 1 |
| OnSegment | A callable taking const Segment& |
| phase | The frame's phase, in [0, 1); wrapped; a non-finite phase holds |
| step | The signed step from the previous frame's phase, in cycles; a non-finite step holds |
| offsets | The phase offset at the end of each part, in cycles; offsets[SUBSTEPS - 1] is the frame's; a non-finite offset holds the previous one |
| on_segment | Called once per part, in order, as on_segment(const Segment&) |
Definition at line 98 of file phase_walk.hpp.
References sbl::math::clamp(), sbl::math::is_finite(), MAX_STEP, phase(), sbl::dsp::PhaseWalk::Segment::start, and wrap().
Referenced by sbl::dsp::PhaseSaw< Kernel >::process(), and sbl::dsp::PhasePulse< Kernel >::process().
|
inlinestatic |
Report every image of a threshold crossed by a segment while the threshold moved c0 -> c1.
The threshold's images are c + n for every whole n. Each crossing is given to on_crossing(t, direction, speed):
t, the fraction of a frame from the crossing to the frame's end, in [0, 1), the sub-frame time a BlepCorrector takes;direction, +1 where the phase passed the image upward relative to the threshold's motion, -1 downward;speed, the phase's speed relative to the threshold over the segment, in cycles per frame, signed: positive upward.Most segments cross nothing, so which side each end lies on is tested here, inline in the caller, and the crossings themselves are found out of line. The inlining is forced with [[gnu::always_inline]].
| OnCrossing | A callable taking (float t, int direction, float speed) |
| s | The segment |
| c0 | The threshold at the segment's start, in cycles |
| c1 | The threshold at the segment's end, in cycles |
| on_crossing | Called once per image crossed |
Definition at line 154 of file phase_walk.hpp.
References sbl::dsp::PhaseWalk::Segment::end, sbl::dsp::PhaseWalk::Segment::start, and sbl::dsp::PhaseWalk::Segment::wraps.
|
inline |
Move to a phase plus an offset, the offset kept as the last part's.
| phase | Phase in cycles; a non-finite phase counts as 0 |
| offset | Offset in cycles; a non-finite offset counts as 0 |
Definition at line 169 of file phase_walk.hpp.
References offset(), phase(), and wrap().
Referenced by sbl::dsp::PhasePulse< Kernel >::reset(), and sbl::dsp::PhaseSaw< Kernel >::reset().
|
inline |
The phase the last part ended on, the offset included, in [0, 1).
Definition at line 175 of file phase_walk.hpp.
Referenced by frame(), sbl::dsp::PhasePulse< Kernel >::phase(), sbl::dsp::PhaseSaw< Kernel >::phase(), sbl::dsp::PhaseSaw< Kernel >::process(), sbl::dsp::PhasePulse< Kernel >::process(), sbl::dsp::PhasePulse< Kernel >::reset(), and reset().
|
inline |
The offset the last part ended on, in cycles.
Definition at line 178 of file phase_walk.hpp.
Referenced by sbl::dsp::PhasePulse< Kernel >::offset(), sbl::dsp::PhaseSaw< Kernel >::offset(), and reset().
|
inlinestatic |
Wrap into [0, 1); a value that rounds up to 1 is 0.
| x | A finite value |
Definition at line 186 of file phase_walk.hpp.
Referenced by sbl::dsp::PhasePulse< Kernel >::advance(), frame(), and reset().
|
staticconstexpr |
cycles per frame, either direction
Definition at line 72 of file phase_walk.hpp.
Referenced by frame().