Gamma  0.9.5
Generic Synthesis Library
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
Osc< Tv, Sipol, Stap, Ts > Class Template Reference

Tabulated function oscillator. More...

#include <Oscillator.h>

Inheritance diagram for Osc< Tv, Sipol, Stap, Ts >:
Accum< Stap, Ts > ArrayPow2< Tv > ArrayBase< Tv, SizeArrayPow2, gam::Allocator< Tv > >

List of all members.

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.
OscaddSine (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.
ArrayBaseassign (const Tv &v)
 Sets all elements to value.
ArrayBaseassign (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.

Detailed Description

template<class Tv = gam::real, template< class > class Sipol = ipl::Linear, class Stap = tap::Wrap, class Ts = Synced>
class gam::Osc< Tv, Sipol, Stap, Ts >

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.]

Template Parameters:
Tvtable element type
Sipolinterpolation strategy
Staptable reading strategy

Constructor & Destructor Documentation

Osc ( float  frq = 440,
float  phs = 0,
uint32_t  size = 512 
)

Constructor that allocates an internal table.

Parameters:
[in]frqFrequency
[in]phsPhase in [0, 1)
[in]sizeSize of table (actual number is power of 2 ceiling)
Osc ( float  frq,
float  phs,
ArrayPow2< Tv > &  src 
)

Constructor that references an external table.

Parameters:
[in]frqFrequency
[in]phsPhase in [0, 1)
[in]srcA table to use as a reference

Member Function Documentation

Osc& addSine ( double  cycles,
double  amp = 1,
double  phs = 0 
)

Add sine to table.

Parameters:
[in]cyclesnumber of cycles
[in]ampamplitude
[in]phsunit 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.

Parameters:
[in]vvalue to be copied as new content
[in]endend index (exclusive)
[in]strideindex stride amount
[in]startstart 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.


The documentation for this class was generated from the following file: