|
Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
|
A phase advanced by a signed step each frame, held as a 32-bit count of the cycle. More...
A phase advanced by a signed step each frame, held as a 32-bit count of the cycle.
The phase is a 32-bit unsigned count, 2^32 counts to the cycle, and each frame adds the step's count to it. Integer addition is exact and wraps by itself, so the phase accumulates no rounding error: the one error is the step's rounding to the nearest count, a frequency resolution of fs / 2^32, about 11 uHz at 48 kHz, which does not grow with time. A float accumulator rounds every add instead.
The interface is float, in natural units: a step in cycles per frame in; the phase in [0, 1), and the step as it is taken, out. The count stays inside. Below the signal transport: the component that owns an accumulator converts its ports to the step.
The step is signed, so the phase runs forward, backward and through zero, as PhasePulse reads it. A signed count tells the direction only for steps under half a cycle a frame, so the step is clamped to MAX_STEP either way; a pitch alone stays far under it. A non-finite step counts as no motion. The phase out is the count's top 24 bits, exact in a float and never 1.
Definition at line 42 of file phase_accumulator.hpp.
#include <phase_accumulator.hpp>
Public Member Functions | |
| float | set_step (float cycles_per_frame) |
| Set the step each later advance() takes. | |
| float | advance () |
| One frame: advance by the step. | |
| float | phase () const |
| The phase after the last advance, in [0, 1). | |
| float | step () const |
| The step each advance takes, in cycles per frame. | |
| void | reset (float phase=0.0f) |
| Move to a phase. The step stays. | |
Static Public Attributes | |
| static constexpr float | MAX_STEP = 0.49999997f |
|
inline |
Set the step each later advance() takes.
| cycles_per_frame | Step in cycles per frame, signed; clamped to MAX_STEP either way; non-finite counts as 0 |
Definition at line 53 of file phase_accumulator.hpp.
References step().
Referenced by sbl::dsp::PmPulse::process().
|
inline |
One frame: advance by the step.
Definition at line 64 of file phase_accumulator.hpp.
References phase().
Referenced by sbl::dsp::PmPulse::process().
|
inline |
The phase after the last advance, in [0, 1).
Definition at line 70 of file phase_accumulator.hpp.
Referenced by advance(), sbl::dsp::PmPulse::phase(), and reset().
|
inline |
The step each advance takes, in cycles per frame.
Definition at line 73 of file phase_accumulator.hpp.
Referenced by set_step().
|
inline |
Move to a phase. The step stays.
| phase | Phase in cycles, wrapped into [0, 1); non-finite counts as 0 |
Definition at line 80 of file phase_accumulator.hpp.
References phase().
Referenced by sbl::dsp::PmPulse::reset().
|
staticconstexpr |
cycles per frame either way: the float just under 1/2
Definition at line 44 of file phase_accumulator.hpp.