Mozzi  version v2.0
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>

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 32 bit integer.

Template Parameters
UPDATE_RATEthe rate at which the Phasor will be updated, usually MOZZI_CONTROL_RATE or MOZZI_AUDIO_RATE.

Definition at line 28 of file Phasor.h.

Public Member Functions

 Phasor ()
 Constructor. More...
 
uint32_t next ()
 Increments one step along the phase. More...
 
void set (uint32_t 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...
 
uint32_t phaseIncFromFreq (int frequency)
 phaseIncFromFreq() and setPhaseInc() are for saving processor time when sliding between frequencies. More...
 
void setPhaseInc (uint32_t stepsize)
 Set a specific phase increment. More...
 

Constructor & Destructor Documentation

◆ Phasor()

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

Constructor.

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

Definition at line 38 of file Phasor.h.

Member Function Documentation

◆ next()

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

Increments one step along the phase.

Returns
the next value.

Definition at line 46 of file Phasor.h.

◆ phaseIncFromFreq()

template<unsigned int UPDATE_RATE>
uint32_t 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 94 of file Phasor.h.

◆ set()

template<unsigned int UPDATE_RATE>
void Phasor< UPDATE_RATE >::set ( uint32_t  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 56 of file Phasor.h.

◆ setFreq() [1/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 uint32_t value 4294967295.

Definition at line 79 of file Phasor.h.

◆ setFreq() [2/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 uint32_t value 4294967295.
Note
Timing 8us

Definition at line 68 of file Phasor.h.

◆ setPhaseInc()

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

Set a specific phase increment.

See phaseIncFromFreq().

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

Definition at line 104 of file Phasor.h.