Mozzi  version 2016-12-11-17:03
sound synthesis library for Arduino
Phasor< UPDATE_RATE > Class Template Reference

Phasor repeatedly generates a high resolution ramp at a variable frequency. More...

#include <Phasor.h>

Public Member Functions

 Phasor ()
 Constructor. More...
 
unsigned long next ()
 Increments one step along the phase. More...
 
void set (unsigned long value)
 Set the current value of the phasor. More...
 
void setFreq (int frequency)
 Set the Phasor frequency with an unsigned int. More...
 
void setFreq (float frequency)
 Set the Phasor frequency with a float. More...
 
unsigned long phaseIncFromFreq (int frequency)
 phaseIncFromFreq() and setPhaseInc() are for saving processor time when sliding between frequencies. More...
 
void setPhaseInc (unsigned long stepsize)
 Set a specific phase increment. More...
 

Detailed Description

template<unsigned int UPDATE_RATE>
class Phasor< UPDATE_RATE >

Phasor repeatedly generates a high resolution ramp at a variable frequency.

The output of Phasor.next() is an unsigned number between 0 and 4294967295, the maximum that can be expressed by an unsigned long.

Template Parameters
UPDATE_RATEthe rate at which the Phasor will be updated, usually CONTROL_RATE or AUDIO_RATE.

Definition at line 33 of file Phasor.h.

Constructor & Destructor Documentation

§ Phasor()

template<unsigned int UPDATE_RATE>
Phasor< UPDATE_RATE >::Phasor ( )
inline

Constructor.

"Phasor <AUDIO_RATE> myphasor;" makes a Phasor which updates at AUDIO_RATE.

Definition at line 43 of file Phasor.h.

Member Function Documentation

§ next()

template<unsigned int UPDATE_RATE>
unsigned long Phasor< UPDATE_RATE >::next ( )
inline

Increments one step along the phase.

Returns
the next value.

Definition at line 51 of file Phasor.h.

§ phaseIncFromFreq()

template<unsigned int UPDATE_RATE>
unsigned long Phasor< UPDATE_RATE >::phaseIncFromFreq ( int  frequency)
inline

phaseIncFromFreq() and setPhaseInc() are for saving processor time when sliding between frequencies.

Instead of recalculating the phase increment for each frequency in between, you can just calculate the phase increment for each end frequency with phaseIncFromFreq(), then use a Line to interpolate on the fly and use setPhaseInc() to set the phase increment at each step. (Note: I should really profile this with the oscilloscope to see if it's worth the extra confusion!)

Parameters
frequencyfor which you want to calculate a phase increment value.
Returns
the phase increment value which will produce a given frequency.

Definition at line 106 of file Phasor.h.

§ set()

template<unsigned int UPDATE_RATE>
void Phasor< UPDATE_RATE >::set ( unsigned long  value)
inline

Set the current value of the phasor.

The Phasor will continue incrementing from this value using any previously calculated step size.

Definition at line 64 of file Phasor.h.

§ setFreq() [1/2]

template<unsigned int UPDATE_RATE>
void Phasor< UPDATE_RATE >::setFreq ( int  frequency)
inline

Set the Phasor frequency with an unsigned int.

Parameters
frequencyis how many times per second to count from 0 to the maximum unsigned long value 4294967295.
Note
Timing 8us

Definition at line 76 of file Phasor.h.

§ setFreq() [2/2]

template<unsigned int UPDATE_RATE>
void Phasor< UPDATE_RATE >::setFreq ( float  frequency)
inline

Set the Phasor frequency with a float.

Parameters
frequencyis how many times per second to count from 0 to the maximum unsigned long value 4294967295.

Definition at line 87 of file Phasor.h.

§ setPhaseInc()

template<unsigned int UPDATE_RATE>
void Phasor< UPDATE_RATE >::setPhaseInc ( unsigned long  stepsize)
inline

Set a specific phase increment.

See phaseIncFromFreq().

Parameters
stepsizea phase increment value as calculated by phaseIncFromFreq().

Definition at line 116 of file Phasor.h.