|
Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
|
A band-limited pulse driven by a signed phase, its width placed by a bipolar anchor. More...
A band-limited pulse driven by a signed phase, its width placed by a bipolar anchor.
The pulse is high for w of the cycle, on [c - w/2, c + w/2) with its center at c = 1/2 + a (1 - w)/2, and low elsewhere. The anchor a, in [-1, 1], says which edges a change of width moves: at 0 the pulse is centered on phase 1/2 and both edges move; at +1 its fall sits at the wrap and only the rise moves, as in BlepOsc's pulse; at -1 its rise sits at the wrap and only the fall moves. A change dw in width moves the center by -a dw/2 of a cycle, and the fundamental's phase with it, so the anchor sets how far PWM moves the pitch. Both edges stay in [0, 1] at every width and anchor. Every edge is corrected at its sub-frame time through a BlepCorrector over the Kernel, so the output trails the naive waveform by LATENCY frames, as in BlepOsc.
The core owns no phase accumulator. Each frame its driver gives it the phase, in [0, 1), and the signed step that led there in cycles; one accumulator can drive several cores, each reading it plus its own offset. The step is signed: the phase may run forward, backward and through zero. The core keeps the previous frame's phase, and the step says how many wraps lie between the two, round(previous + step - phase). The phases are the segment's endpoints, so the crossings always agree with the naive samples, whatever rounding the driver's accumulator did.
Crossings are found on the unwrapped segment against each edge and its images one cycle up and down, in either direction and across the wrap, and every image crossed in the frame is corrected at its own time. The frame's segments and their crossings are a PhaseWalk. An edge at the wrap is corrected like any other, and width therefore needs no margin for the bookkeeping and reaches [0, 1] at every step: at 0 and at 1 the edges coincide and their corrections cancel. A change of width or anchor moves the edges across the next frame; nothing is ramped.
Each frame may carry a phase offset, in cycles: the core reads the phase plus the offset, and its step is the given step plus the offset's change since the previous frame. A moving offset is phase modulation, and the edges it moves are corrected like any other motion; a constant offset is a time shift. Each core keeps its own previous offset, so cores reading one accumulator can each carry their own.
A frame call can also report the edges it corrected, each at its time within the frame and with the level's change, and level() gives the naive level at the frame's end. Together they are the naive pulse as a level that steps at exact times, with none of the corrector's latency: what a modulator that listens to the pulse within the same frames needs.
The core is below the signal transport. Its inputs are natural units, set by the driver that owns it.
Inputs and their handling, per frame:
With Bspline4 or Linear2, kernels that never overshoot, output is in [-1, 1]. With Sinc16 a step overshoots by 8.2 % of its height, so the pulse reaches 1.16 (polyblep.hpp). A pulse of width w carries a mean of 2w - 1; the core removes no DC.
Output does not depend on how the stream is split into calls: all state advances per frame.
| Kernel | The BLEP kernel; math::Sinc16 by default |
Definition at line 97 of file phase_pulse.hpp.
#include <phase_pulse.hpp>
Public Member Functions | |
| void | set_width (float fraction_of_cycle) |
| Set the pulse width. Takes effect next frame as moving edges. | |
| void | set_anchor (float anchor) |
| Set where width acts. Takes effect next frame as moving edges. | |
| float | process (float phase, float step, float offset) |
| One frame: the corrected sample LATENCY frames back. | |
| template<uint8_t SUBSTEPS> | |
| float | process (float phase, float step, const float(&offsets)[SUBSTEPS]) |
| One frame in SUBSTEPS equal parts, the offset given at the end of each. | |
| template<uint8_t SUBSTEPS, class OnEdge > | |
| float | process (float phase, float step, const float(&offsets)[SUBSTEPS], OnEdge &&on_edge) |
| The frame call above, reporting each edge the phase crossed. | |
| float | process (float phase, float step) |
| One frame with no offset: an offset carried before moves back to zero, as phase modulation. | |
| template<class... Ports> | |
| void | process (float *out, uint16_t frames, Ports... ports) |
| A buffer of frames: phase and step per frame, then width, anchor and offset, which may be left off. | |
| void | reset (float phase=0.0f, float offset=0.0f) |
| Move to a phase plus an offset; width and anchor to their targets, corrections dropped. | |
| float | phase () const |
| The phase the core read last frame, the offset included. | |
| float | level () const |
| The naive level at the end of the last frame, +1 or -1: the pulse before its corrections, with no latency. | |
| float | offset () const |
| The offset the core read last frame, in cycles. | |
| float | width () const |
| The width set for the next frame. | |
| float | anchor () const |
| The anchor set for the next frame. | |
Static Public Member Functions | |
| static constexpr float | rise (float width, float anchor) |
| The phase where the pulse rises. | |
| static constexpr float | fall (float width, float anchor) |
| The phase where the pulse falls. | |
| static float | advance (float phase, float step) |
| Advance a phase by a signed step and wrap it into [0, 1) | |
Static Public Attributes | |
| static constexpr float | MAX_STEP = PhaseWalk::MAX_STEP |
| static constexpr uint8_t | LATENCY = Kernel::LATENCY |
| static constexpr transport::Port | PORTS [] |
| The ports, in the order the buffer call takes them; width and anchor set what their setters set. | |
|
inline |
Set the pulse width. Takes effect next frame as moving edges.
| fraction_of_cycle | Width as a fraction of the cycle, clamped to [0, 1]; non-finite counts as 0.5 |
Definition at line 108 of file phase_pulse.hpp.
References sbl::math::clamp(), and sbl::math::finite_or().
Referenced by sbl::dsp::PhasePulse< Kernel >::process(), and sbl::dsp::PmPulse::process().
|
inline |
Set where width acts. Takes effect next frame as moving edges.
| anchor | Clamped to [-1, 1]: -1 holds the rise at the wrap, 0 the center at 1/2, +1 the fall at the wrap; non-finite counts as 0 |
Definition at line 119 of file phase_pulse.hpp.
References sbl::dsp::PhasePulse< Kernel >::anchor(), sbl::math::clamp(), and sbl::math::finite_or().
Referenced by sbl::dsp::PhasePulse< Kernel >::process(), and sbl::dsp::PmPulse::process().
|
inline |
One frame: the corrected sample LATENCY frames back.
| phase | The frame's phase, in [0, 1) |
| step | The signed step from the previous frame's phase, in cycles |
| offset | The frame's phase offset, in cycles; its change since the previous frame adds to the step |
Definition at line 133 of file phase_pulse.hpp.
References sbl::dsp::PhasePulse< Kernel >::offset(), sbl::dsp::PhasePulse< Kernel >::phase(), and sbl::dsp::PhasePulse< Kernel >::process().
Referenced by sbl::dsp::PhasePulse< Kernel >::process(), sbl::dsp::PhasePulse< Kernel >::process(), and sbl::dsp::PhasePulse< Kernel >::process().
|
inline |
One frame in SUBSTEPS equal parts, the offset given at the end of each.
Through the frame the phase moves linearly by step to phase, plus the offset at the end of each part; offsets[SUBSTEPS - 1] is the frame's. Each part is a segment of its own, so an offset that curves within the frame is followed SUBSTEPS times more closely than by one segment. Width and anchor move linearly across the frame. One part is the one-segment call above.
| SUBSTEPS | Parts per frame, at least 1 |
| phase | The frame's phase, in [0, 1) |
| step | The signed step from the previous frame's phase, in cycles |
| offsets | The phase offset at the end of each part, in cycles |
Definition at line 156 of file phase_pulse.hpp.
References sbl::dsp::PhasePulse< Kernel >::phase(), and sbl::dsp::PhasePulse< Kernel >::process().
|
inline |
The frame call above, reporting each edge the phase crossed.
The edges are those the corrector is given, so over a frame their heights sum to the change in level(). Parts come in time order; within a part the rising edge's crossings come before the falling edge's, whatever their times.
| SUBSTEPS | Parts per frame, at least 1 |
| OnEdge | A callable taking (float t, float height) |
| phase | The frame's phase, in [0, 1) |
| step | The signed step from the previous frame's phase, in cycles |
| offsets | The phase offset at the end of each part, in cycles |
| on_edge | Called once per crossing as on_edge(t, height): t the time from the crossing to the frame's end, in frames, in [0, 1]; height the naive level's change, +2 or -2 |
Definition at line 179 of file phase_pulse.hpp.
References sbl::dsp::PhasePulse< Kernel >::fall(), sbl::dsp::PhaseWalk::frame(), sbl::dsp::PhaseWalk::Segment::last, sbl::dsp::PhasePulse< Kernel >::phase(), sbl::dsp::PhaseWalk::phase(), sbl::dsp::PhasePulse< Kernel >::rise(), and sbl::dsp::PhaseWalk::Segment::through.
|
inline |
One frame with no offset: an offset carried before moves back to zero, as phase modulation.
| phase | The frame's phase, in [0, 1) |
| step | The signed step from the previous frame's phase, in cycles |
Definition at line 210 of file phase_pulse.hpp.
References sbl::dsp::PhasePulse< Kernel >::phase(), and sbl::dsp::PhasePulse< Kernel >::process().
Referenced by sbl::dsp::PhasePulse< Kernel >::process().
|
inline |
A buffer of frames: phase and step per frame, then width, anchor and offset, which may be left off.
Width and anchor as blocks are set each frame; as scalars they are set once, before the block's first frame. Either way they take effect as moving edges, as their setters say. Left off, they hold. The offset, in cycles, is per frame as a block and constant as a scalar; left off, it is zero.
| Ports | Blocks for phase and step, then a block or an arithmetic scalar for each of the rest |
| [out] | out | Output buffer, frames long |
| frames | Frame count | |
| ports | phase in [0, 1) and step in cycles per frame, then width, anchor and offset in cycles |
Definition at line 237 of file phase_pulse.hpp.
References sbl::dsp::PhasePulse< Kernel >::anchor(), sbl::transport::fits_v, sbl::dsp::PhasePulse< Kernel >::offset(), sbl::dsp::PhasePulse< Kernel >::phase(), sbl::dsp::PhasePulse< Kernel >::process(), sbl::dsp::PhasePulse< Kernel >::set_anchor(), sbl::dsp::PhasePulse< Kernel >::set_width(), and sbl::dsp::PhasePulse< Kernel >::width().
|
inline |
Move to a phase plus an offset; width and anchor to their targets, corrections dropped.
| phase | Phase in cycles; a non-finite phase counts as 0 |
| offset | Offset in cycles, kept as the last frame's; a non-finite offset counts as 0 |
Definition at line 275 of file phase_pulse.hpp.
References sbl::dsp::PhasePulse< Kernel >::fall(), sbl::dsp::PhasePulse< Kernel >::offset(), sbl::dsp::PhasePulse< Kernel >::phase(), sbl::dsp::PhaseWalk::phase(), sbl::dsp::PhaseWalk::reset(), and sbl::dsp::PhasePulse< Kernel >::rise().
Referenced by sbl::dsp::PmPulse::reset().
|
inline |
The phase the core read last frame, the offset included.
Definition at line 284 of file phase_pulse.hpp.
References sbl::dsp::PhaseWalk::phase().
Referenced by sbl::dsp::PhasePulse< Kernel >::advance(), sbl::dsp::PhasePulse< Kernel >::process(), sbl::dsp::PhasePulse< Kernel >::process(), sbl::dsp::PhasePulse< Kernel >::process(), sbl::dsp::PhasePulse< Kernel >::process(), sbl::dsp::PhasePulse< Kernel >::process(), and sbl::dsp::PhasePulse< Kernel >::reset().
|
inline |
The naive level at the end of the last frame, +1 or -1: the pulse before its corrections, with no latency.
Definition at line 287 of file phase_pulse.hpp.
|
inline |
The offset the core read last frame, in cycles.
Definition at line 289 of file phase_pulse.hpp.
References sbl::dsp::PhaseWalk::offset().
Referenced by sbl::dsp::PhasePulse< Kernel >::process(), sbl::dsp::PhasePulse< Kernel >::process(), and sbl::dsp::PhasePulse< Kernel >::reset().
|
inline |
The width set for the next frame.
Definition at line 291 of file phase_pulse.hpp.
Referenced by sbl::dsp::PhasePulse< Kernel >::fall(), sbl::dsp::PhasePulse< Kernel >::process(), and sbl::dsp::PhasePulse< Kernel >::rise().
|
inline |
The anchor set for the next frame.
Definition at line 293 of file phase_pulse.hpp.
Referenced by sbl::dsp::PhasePulse< Kernel >::fall(), sbl::dsp::PhasePulse< Kernel >::process(), sbl::dsp::PhasePulse< Kernel >::rise(), and sbl::dsp::PhasePulse< Kernel >::set_anchor().
|
inlinestaticconstexpr |
The phase where the pulse rises.
| width | Width, in [0, 1] |
| anchor | Anchor, in [-1, 1] |
Definition at line 302 of file phase_pulse.hpp.
References sbl::dsp::PhasePulse< Kernel >::anchor(), and sbl::dsp::PhasePulse< Kernel >::width().
Referenced by sbl::dsp::PhasePulse< Kernel >::process(), and sbl::dsp::PhasePulse< Kernel >::reset().
|
inlinestaticconstexpr |
The phase where the pulse falls.
| width | Width, in [0, 1] |
| anchor | Anchor, in [-1, 1] |
Definition at line 311 of file phase_pulse.hpp.
References sbl::dsp::PhasePulse< Kernel >::anchor(), and sbl::dsp::PhasePulse< Kernel >::width().
Referenced by sbl::dsp::PhasePulse< Kernel >::process(), and sbl::dsp::PhasePulse< Kernel >::reset().
|
inlinestatic |
Advance a phase by a signed step and wrap it into [0, 1)
For a driver's accumulator. A small negative step from just above zero would round to 1.0f on adding a cycle; the result is kept below 1.
| phase | Phase, in cycles |
| step | Signed step, in cycles |
Definition at line 323 of file phase_pulse.hpp.
References sbl::dsp::PhasePulse< Kernel >::phase(), and sbl::dsp::PhaseWalk::wrap().
|
staticconstexpr |
cycles per frame, either direction
Definition at line 99 of file phase_pulse.hpp.
|
staticconstexpr |
frames the output trails the naive pulse
Definition at line 100 of file phase_pulse.hpp.
|
staticconstexpr |
The ports, in the order the buffer call takes them; width and anchor set what their setters set.
Definition at line 213 of file phase_pulse.hpp.