|
Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
|
A band-limited slope shape driven by a signed phase, from a falling saw through a triangle to a rising saw. More...
A band-limited slope shape driven by a signed phase, from a falling saw through a triangle to a rising saw.
The shape rises from -1 to +1 over w of the cycle, on [rise, fall), and falls from +1 to -1 over the rest. Its corners sit where PhasePulse's edges sit for the same width and anchor: the trough at PhasePulse::rise(w, a), the peak at PhasePulse::fall(w, a). Width 0.5 is a triangle; toward 0 the shape is a falling saw, toward 1 a rising saw. The anchor means what it means for the pulse: which corner holds as width changes, and how far a change dw moves the fundamental's phase, -a dw/2 of a cycle.
The shape's slope is the pulse's, less its mean, times K = 2 / (w (1 - w)), so each harmonic is K / (2 pi k) times PhasePulse's and a quarter cycle behind it. Its mean is 0 at every width; it carries no DC. Width 1 - w is the shape at w inverted and shifted, so mirrored widths in a pair keep the pulse's relation.
The core owns no phase accumulator and walks each frame as PhasePulse does, through a PhaseWalk: the 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 parts of the frame, and the core reads the phase plus the offset. Forward, backward and through zero, across the wrap, with the offset as phase modulation; every corner crossed in the frame is corrected at its own time through a BlepCorrector over the Kernel, so the output trails the naive shape by LATENCY frames.
A corner's correction is a slope change: K times the phase's speed relative to the corner, in cycles per frame, K taken at the width at the crossing. A trough is a trough in either direction of travel, so the sign is the corner's, not the direction's: +K |speed| at the trough, -K |speed| at the peak. Under phase modulation the speed is each sub-step's. Each correction is a change from the slope before it, so the first frame after a reset starts the count: the shape's slope at the starting phase times the first speed, corrected at the reset's instant. Without it a start on the short segment, or on its trough, leaves the next corner unpaired.
The phase is linear within each sub-step, and the shape's slope is not zero, so where the phase's speed changes between sub-steps or frames the shape's slope changes by its slope times the change: 2 / w on the rising segment. Those changes are not corrected, as BlepOsc leaves a frequency change's. Under phase modulation they leave aliasing that grows with the depth, the pitch and the narrowness of the short segment.
Width and anchor take effect across the next frame, moving linearly, as PhasePulse's do, and nothing is ramped, so a pulse and a saw given the same width and anchor stay in step. A corner a change moves past the phase is corrected like any other crossing. Unlike the pulse's level, the shape's value also changes along a segment when width changes, and the slope changes where that motion starts and stops are not corrected. Near the floor the value at a phase goes as 1 / w, so a large step of width within one frame is no longer a straight segment between corners, and its correction overshoots. Ramped over 48 frames, as a driver's ramp moves it, the peak is no higher than the static one (test_phase_saw.hpp). A driver ramps width, and sets it before reset() for the first frame to start from it.
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 the corners ring, and the peak grows as the short segment shortens toward a step, whose overshoot is 8.2 % of its height (polyblep.hpp). From 110 Hz to 4.4 kHz the peak stays at or under 1.165 at every width (test_phase_saw.hpp).
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 107 of file phase_saw.hpp.
#include <phase_saw.hpp>
Public Member Functions | |
| void | set_width (float fraction_of_cycle) |
| Set the rising segment's share of the cycle. Takes effect next frame. | |
| void | set_anchor (float anchor) |
| Set where width acts. Takes effect next frame. | |
| 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, as PhasePulse's. | |
| 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 | 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 trough, where the shape starts to rise, as PhasePulse::rise(). | |
| static constexpr float | fall (float width, float anchor) |
| The peak, where the shape starts to fall, as PhasePulse::fall(). | |
| static float | shape (float phase, float rise, float fall, float width) |
| The naive shape at a phase. | |
Static Public Attributes | |
| static constexpr float | MAX_STEP = PhaseWalk::MAX_STEP |
| static constexpr float | WIDTH_FLOOR = 0.0005f |
| static constexpr uint8_t | LATENCY = Kernel::LATENCY |
| static constexpr transport::Port | PORTS [] |
| The ports, in the order the buffer call takes them, as PhasePulse's. | |
|
inline |
Set the rising segment's share of the cycle. Takes effect next frame.
| fraction_of_cycle | Width, clamped to [WIDTH_FLOOR, 1 - WIDTH_FLOOR]; non-finite counts as 0.5 |
Definition at line 119 of file phase_saw.hpp.
References sbl::math::clamp(), sbl::math::finite_or(), and sbl::dsp::PhaseSaw< Kernel >::WIDTH_FLOOR.
Referenced by sbl::dsp::PhaseSaw< Kernel >::process().
|
inline |
Set where width acts. Takes effect next frame.
| anchor | Clamped to [-1, 1]: -1 holds the trough at the wrap, 0 the center at 1/2, +1 the peak at the wrap; non-finite counts as 0 |
Definition at line 131 of file phase_saw.hpp.
References sbl::dsp::PhaseSaw< Kernel >::anchor(), sbl::math::clamp(), and sbl::math::finite_or().
Referenced by sbl::dsp::PhaseSaw< Kernel >::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 145 of file phase_saw.hpp.
References sbl::dsp::PhaseSaw< Kernel >::offset(), sbl::dsp::PhaseSaw< Kernel >::phase(), and sbl::dsp::PhaseSaw< Kernel >::process().
Referenced by sbl::dsp::PhaseSaw< Kernel >::process(), and sbl::dsp::PhaseSaw< Kernel >::process().
|
inline |
One frame in SUBSTEPS equal parts, the offset given at the end of each, as PhasePulse'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.
| 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 165 of file phase_saw.hpp.
References sbl::dsp::PhaseSaw< Kernel >::fall(), sbl::dsp::PhaseWalk::frame(), sbl::dsp::PhaseWalk::Segment::last, sbl::dsp::PhaseSaw< Kernel >::phase(), sbl::dsp::PhaseWalk::phase(), sbl::dsp::PhaseSaw< Kernel >::rise(), sbl::dsp::PhaseSaw< Kernel >::shape(), 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 202 of file phase_saw.hpp.
References sbl::dsp::PhaseSaw< Kernel >::phase(), and sbl::dsp::PhaseSaw< Kernel >::process().
Referenced by sbl::dsp::PhaseSaw< Kernel >::process().
|
inline |
A buffer of frames: phase and step per frame, then width, anchor and offset, which may be left off.
As PhasePulse's: width and anchor as blocks are set each frame, as scalars once before the first frame; left off, they hold. The offset 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 227 of file phase_saw.hpp.
References sbl::dsp::PhaseSaw< Kernel >::anchor(), sbl::transport::fits_v, sbl::dsp::PhaseSaw< Kernel >::offset(), sbl::dsp::PhaseSaw< Kernel >::phase(), sbl::dsp::PhaseSaw< Kernel >::process(), sbl::dsp::PhaseSaw< Kernel >::set_anchor(), sbl::dsp::PhaseSaw< Kernel >::set_width(), and sbl::dsp::PhaseSaw< 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 265 of file phase_saw.hpp.
References sbl::dsp::PhaseSaw< Kernel >::offset(), sbl::dsp::PhaseSaw< Kernel >::phase(), and sbl::dsp::PhaseWalk::reset().
|
inline |
The phase the core read last frame, the offset included.
Definition at line 274 of file phase_saw.hpp.
References sbl::dsp::PhaseWalk::phase().
Referenced by sbl::dsp::PhaseSaw< Kernel >::process(), sbl::dsp::PhaseSaw< Kernel >::process(), sbl::dsp::PhaseSaw< Kernel >::process(), sbl::dsp::PhaseSaw< Kernel >::process(), sbl::dsp::PhaseSaw< Kernel >::reset(), and sbl::dsp::PhaseSaw< Kernel >::shape().
|
inline |
The offset the core read last frame, in cycles.
Definition at line 276 of file phase_saw.hpp.
References sbl::dsp::PhaseWalk::offset().
Referenced by sbl::dsp::PhaseSaw< Kernel >::process(), sbl::dsp::PhaseSaw< Kernel >::process(), and sbl::dsp::PhaseSaw< Kernel >::reset().
|
inline |
The width set for the next frame.
Definition at line 278 of file phase_saw.hpp.
Referenced by sbl::dsp::PhaseSaw< Kernel >::fall(), sbl::dsp::PhaseSaw< Kernel >::process(), sbl::dsp::PhaseSaw< Kernel >::rise(), and sbl::dsp::PhaseSaw< Kernel >::shape().
|
inline |
The anchor set for the next frame.
Definition at line 280 of file phase_saw.hpp.
Referenced by sbl::dsp::PhaseSaw< Kernel >::fall(), sbl::dsp::PhaseSaw< Kernel >::process(), sbl::dsp::PhaseSaw< Kernel >::rise(), and sbl::dsp::PhaseSaw< Kernel >::set_anchor().
|
inlinestaticconstexpr |
The trough, where the shape starts to rise, as PhasePulse::rise().
| width | Width, in [0, 1] |
| anchor | Anchor, in [-1, 1] |
Definition at line 289 of file phase_saw.hpp.
References sbl::dsp::PhaseSaw< Kernel >::anchor(), and sbl::dsp::PhaseSaw< Kernel >::width().
Referenced by sbl::dsp::PhaseSaw< Kernel >::process(), and sbl::dsp::PhaseSaw< Kernel >::shape().
|
inlinestaticconstexpr |
The peak, where the shape starts to fall, as PhasePulse::fall().
| width | Width, in [0, 1] |
| anchor | Anchor, in [-1, 1] |
Definition at line 298 of file phase_saw.hpp.
References sbl::dsp::PhaseSaw< Kernel >::anchor(), and sbl::dsp::PhaseSaw< Kernel >::width().
Referenced by sbl::dsp::PhaseSaw< Kernel >::process(), and sbl::dsp::PhaseSaw< Kernel >::shape().
|
inlinestatic |
The naive shape at a phase.
| phase | Phase, in [0, 1) |
| rise | The trough, from rise() |
| fall | The peak, from fall() |
| width | The width the corners were taken at |
Definition at line 309 of file phase_saw.hpp.
References sbl::dsp::PhaseSaw< Kernel >::fall(), sbl::dsp::PhaseSaw< Kernel >::phase(), sbl::dsp::PhaseSaw< Kernel >::rise(), and sbl::dsp::PhaseSaw< Kernel >::width().
Referenced by sbl::dsp::PhaseSaw< Kernel >::process().
|
staticconstexpr |
cycles per frame, either direction
Definition at line 109 of file phase_saw.hpp.
|
staticconstexpr |
the narrowest segment, a two-thousandth of the cycle
Definition at line 110 of file phase_saw.hpp.
Referenced by sbl::dsp::PhaseSaw< Kernel >::set_width().
|
staticconstexpr |
frames the output trails the naive shape
Definition at line 111 of file phase_saw.hpp.
|
staticconstexpr |
The ports, in the order the buffer call takes them, as PhasePulse's.
Definition at line 205 of file phase_saw.hpp.