Tabulated function oscillator. More...
#include <Oscillator.h>
Public Member Functions | |
Osc (float frq=440, float phs=0, uint32_t size=512) | |
Constructor that allocates an internal table. | |
Osc (float frq, float phs, ArrayPow2< Tv > &src) | |
Constructor that references an external table. | |
Tv | operator() () |
Generate next sample. | |
Tv | val () const |
Get current value. | |
Osc & | addSine (double cycles, double amp=1, double phs=0) |
Add sine to table. | |
void | zero () |
Zero table elements. | |
void | freq (float v) |
Set frequency. | |
float | freq () const |
Get frequency. | |
void | phase (float v) |
Set phase from [0, 1) of one period. | |
float | phase () const |
Get phase in [0, 1) | |
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. | |
uint32_t | freqI () const |
Get fixed-point frequency. | |
float | freqUnit () const |
Get frequency in [0, 1) | |
uint32_t | phaseI () const |
Get fixed-point phase. | |
uint32_t | cycle () |
Returns 0x80000000 on phase wrap, 0 otherwise. | |
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. | |
uint32_t | fracBits () const |
Returns number of bits in fraction (32 - bits()) | |
float | fraction (uint32_t phase) const |
Get floating-point fractional part of fixed-point phase. | |
uint32_t | index (uint32_t phase) const |
Get integer part of fixed-point phase. | |
uint32_t | log2Size () const |
Returns log base-2 of the number of array elements. | |
uint32_t | oneIndex () const |
Returns 32-bit phase increment for one element index. | |
const Tv & | atPhase (uint32_t phase) const |
Get element at truncated fixed-point phase. | |
void | putPhase (uint32_t phase, Tvv) |
Set element at truncated fixed point phase. | |
Tv & | operator[] (uint32_t i) |
Get write reference to element. | |
const Tv & | operator[] (uint32_t i) const |
Get read-only reference to element. | |
ArrayBase & | assign (const Tv &v) |
Sets all elements to value. | |
ArrayBase & | assign (const Tv &v, uint32_t end, uint32_t stride=1, uint32_t start=0) |
Sets linear slice of elements to value. | |
Tv * | elems () |
Get writable pointer to elements. | |
const Tv * | elems () const |
Get read-only pointer to elements. | |
uint32_t | size () const |
Returns number of elements in array. | |
void | clear () |
Destroys all elements and frees memory. | |
void | own () |
Ensures ownership of elements. | |
bool | isSoleOwner () const |
Returns true if we are the sole owner of data internally allocated. | |
void | resize (uint32_t newSize, const Tv &c=Tv()) |
Resizes number of elements in array. | |
void | source (ArrayBase< Tv, SizeArrayPow2, gam::Allocator< Tv > > &src) |
Sets source of array elements to another array. | |
void | source (Tv *src, uint32_t size) |
Sets source of array elements to another array. | |
Static Public Member Functions | |
static int | references (Tv *m) |
Returns number of pointers to memory address being managed. |
Tabulated function oscillator.
This generator produces a periodic signal by reading values from a table. Its advantage over other types of waveform generators is that it can produce arbitrary periodic waveforms with a fixed computational cost. Its main weakness is lack of parametric control over the waveform timbre. This generator is named after the generator of the same name in the MUSIC series of compilers. [Mathews, M. (1969). The Technology of Computer Music. The M.I.T. Press, Boston.]
Tv | table element type |
Sipol | interpolation strategy |
Stap | table reading strategy |
Osc | ( | float | frq = 440 , |
float | phs = 0 , |
||
uint32_t | size = 512 |
||
) |
Constructor that allocates an internal table.
[in] | frq | Frequency |
[in] | phs | Phase in [0, 1) |
[in] | size | Size of table (actual number is power of 2 ceiling) |
Constructor that references an external table.
[in] | frq | Frequency |
[in] | phs | Phase in [0, 1) |
[in] | src | A table to use as a reference |
Add sine to table.
[in] | cycles | number of cycles |
[in] | amp | amplitude |
[in] | phs | unit phase, [0, 1) |
ArrayBase& assign | ( | const Tv & | v, |
uint32_t | end, | ||
uint32_t | stride = 1 , |
||
uint32_t | start = 0 |
||
) | [inherited] |
Sets linear slice of elements to value.
[in] | v | value to be copied as new content |
[in] | end | end index (exclusive) |
[in] | stride | index stride amount |
[in] | start | start index (inclusive) |
uint32_t cycle | ( | ) | [inherited] |
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.
void own | ( | ) | [inherited] |
Ensures ownership of elements.
If the array is not already the sole owner, new memory is allocated and the previously referenced array elements are copied.
void resize | ( | uint32_t | newSize, |
const Tv & | c = T() |
||
) | [inherited] |
Resizes number of elements in array.
If the new size is less than the old size, then elements are truncated. If the new size is greater than the old size, then the argument value is copied into the additional elements.