Fixed-point phase accumulator. More...
#include <Oscillator.h>
Public Member Functions | |
Accum (float frq=0, float phs=0) | |
void | freq (float v) |
Set frequency. | |
void | phase (float v) |
Set phase from [0, 1) of one period. | |
void | phaseMax () |
Set phase to maximum value. | |
void | phaseAdd (float v) |
Add value to phase [0, 1) | |
void | period (float v) |
Set period length. | |
void | reset () |
Reset phase accumulator. | |
bool | done () const |
Returns true if tap is done. | |
float | freq () const |
Get frequency. | |
uint32_t | freqI () const |
Get fixed-point frequency. | |
float | freqUnit () const |
Get frequency in [0, 1) | |
float | phase () const |
Get phase in [0, 1) | |
uint32_t | phaseI () const |
Get fixed-point phase. | |
uint32_t | cycle () |
Returns 0x80000000 on phase wrap, 0 otherwise. | |
uint32_t | operator() () |
Alias of cycle() | |
uint32_t | nextPhase () |
Increment phase and return pre-incremented phase. | |
uint32_t | nextPhasePost () |
Increment phase and return post-incremented phase. | |
uint32_t | cycles () |
Get 1 to 0 transitions of all accumulator bits. |
Fixed-point phase accumulator.
This is a linear phase accumulator that uses integer (fixed-point) arithmetic. The advantage of using fixed-point versus floating-point is that the phase is wrapped automatically when the integer overflows. As long as we used unsigned integers, this wrapping behavior is well-defined- all results of addition are taken modulo the maximum size of the integer.
Accum | ( | float | frq = 0 , |
float | phs = 0 |
||
) |
[in] | frq | Frequency |
[in] | phs | Phase in [0, 1) |
uint32_t cycle | ( | ) |
Returns 0x80000000 on phase wrap, 0 otherwise.
The return value can be used as a bool. It's an integer because it saves a conditional check converting to a bool.