Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
sbl::dsp::PhaseWalk Class Reference

A modulated phase walked frame by frame as segments, and the crossings of moving thresholds on them. More...

Detailed Description

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:

  • A phase outside [0, 1) is wrapped into it. A non-finite phase or step counts as no motion: the phase holds. A non-finite offset holds the previous one.
  • The step, the offset's change included, is clamped to [-MAX_STEP, MAX_STEP], one cycle per frame. With threshold jumps of up to one cycle a frame, a segment holds at most three crossings per threshold. Past the clamp the segment's two ends stay exact and the motion between them loses whole cycles, whose crossings go unreported.
  • Phase is linear within a part: a crossing is timed on the segment, so an event born and closed within one part is not seen.

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:

walk_.frame(phase, step, offsets, [&](const PhaseWalk::Segment& s) {
PhaseWalk::crossings(s, from, to, [&](float t, int direction, float speed) { ... });
});
const float naive = shape(walk_.phase());
float phase() const
The phase the last part ended on, the offset included, in [0, 1).
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.
One part of a frame: the phase moving linearly from start to end plus wraps cycles.

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
 

Member Function Documentation

◆ frame()

template<uint8_t SUBSTEPS, class OnSegment >
void sbl::dsp::PhaseWalk::frame ( float  phase,
float  step,
const float(&)  offsets[SUBSTEPS],
OnSegment &&  on_segment 
)
inline

One frame in SUBSTEPS equal parts, each given to on_segment as a Segment.

Template Parameters
SUBSTEPSParts per frame, at least 1
OnSegmentA callable taking const Segment&
Parameters
phaseThe frame's phase, in [0, 1); wrapped; a non-finite phase holds
stepThe signed step from the previous frame's phase, in cycles; a non-finite step holds
offsetsThe 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_segmentCalled once per part, in order, as on_segment(const Segment&)
Context
Audio thread; real-time safe.

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().

◆ crossings()

template<class OnCrossing >
static void sbl::dsp::PhaseWalk::crossings ( const Segment &  s,
float  c0,
float  c1,
OnCrossing &&  on_crossing 
)
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]].

Template Parameters
OnCrossingA callable taking (float t, int direction, float speed)
Parameters
sThe segment
c0The threshold at the segment's start, in cycles
c1The threshold at the segment's end, in cycles
on_crossingCalled once per image crossed
Context
Audio thread; real-time safe.

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.

◆ reset()

void sbl::dsp::PhaseWalk::reset ( float  phase = 0.0f,
float  offset = 0.0f 
)
inline

Move to a phase plus an offset, the offset kept as the last part's.

Parameters
phasePhase in cycles; a non-finite phase counts as 0
offsetOffset 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().

◆ phase()

float sbl::dsp::PhaseWalk::phase ( ) const
inline

◆ offset()

float sbl::dsp::PhaseWalk::offset ( ) const
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().

◆ wrap()

static float sbl::dsp::PhaseWalk::wrap ( float  x)
inlinestatic

Wrap into [0, 1); a value that rounds up to 1 is 0.

Parameters
xA finite value
Returns
x - floor(x), or 0 where that rounds to 1

Definition at line 186 of file phase_walk.hpp.

Referenced by sbl::dsp::PhasePulse< Kernel >::advance(), frame(), and reset().

Member Data Documentation

◆ MAX_STEP

constexpr float sbl::dsp::PhaseWalk::MAX_STEP = 1.0f
staticconstexpr

cycles per frame, either direction

Definition at line 72 of file phase_walk.hpp.

Referenced by frame().


The documentation for this class was generated from the following file: