Mozzi  version v2.0
sound synthesis library for Arduino
MetaOscil< NUM_TABLE_CELLS, UPDATE_RATE, N_OSCIL > Class Template Reference

MetaOscil is a wrapper for several Oscil. More...

#include <MetaOscil.h>

Detailed Description

template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE, byte N_OSCIL>
class MetaOscil< NUM_TABLE_CELLS, UPDATE_RATE, N_OSCIL >

MetaOscil is a wrapper for several Oscil.

Once constructed it will behave exactly as an Oscil except that it will automatically switch between Oscil depending on the asked frequency. This allows to produce non-aliased sounds by switching between tables with less and less harmonics as the frequency increases.

Definition at line 31 of file MetaOscil.h.

Public Member Functions

template<class... T>
 MetaOscil (Oscil< NUM_TABLE_CELLS, UPDATE_RATE > *first, T *... elements)
 Constructor Declare a MetaOscil containing any number of Oscil pointers. More...
 
template<typename ... T>
void setOscils (Oscil< NUM_TABLE_CELLS, UPDATE_RATE > *first, T... elements)
 Set all Oscil of a MetaOscil. More...
 
void setOscils ()
 
template<typename ... T>
void setCutoffFreqs (int first, T... elements)
 Set all the cutoff frequencies for changing between Oscil. More...
 
void setCutoffFreqs ()
 
void setCutoffFreq (int freq, byte rank)
 Set or change the cutoff frequency of one Oscil. More...
 
int8_t next ()
 Updates the phase according to the current frequency and returns the sample at the new phase position. More...
 
void setTable (const int8_t *TABLE_NAME, byte rank)
 Change the sound table which will be played by the Oscil of rank. More...
 
void setPhase (unsigned int phase)
 Set the phase of the currently playing Oscil. More...
 
void setPhaseFractional (unsigned long phase)
 Set the phase of the currently playing Oscil in fractional format. More...
 
unsigned long getPhaseFractional ()
 Get the phase of the currently playin Oscil in fractional format. More...
 
int8_t phMod (Q15n16 phmod_proportion)
 Returns the next sample given a phase modulation value. More...
 
void setFreq (int frequency, bool apply=true)
 Set the MetaOsc frequency with an unsigned int. More...
 
void setFreq (float frequency)
 Set the MetaOsc frequency with a float. More...
 
void setFreq_Q24n8 (Q24n8 frequency)
 Set the MetaOsc frequency with a Q24n8 fixed-point number format. More...
 
void setFreq_Q16n16 (Q16n16 frequency)
 Set the MetaOsc frequency with a Q16n16 fixed-point number format. More...
 
int8_t atIndex (unsigned int index)
 Returns the sample at the given table index of the current Oscil. More...
 
unsigned long phaseIncFromFreq (int frequency)
 phaseIncFromFreq() and setPhaseInc() are for saving processor time when sliding between frequencies. More...
 
void setPhaseInc (unsigned long phaseinc_fractional)
 Set a specific phase increment. More...
 

Constructor & Destructor Documentation

◆ MetaOscil()

template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE, byte N_OSCIL>
template<class... T>
MetaOscil< NUM_TABLE_CELLS, UPDATE_RATE, N_OSCIL >::MetaOscil ( Oscil< NUM_TABLE_CELLS, UPDATE_RATE > *  first,
T *...  elements 
)
inline

Constructor Declare a MetaOscil containing any number of Oscil pointers.

Every Oscil should have the same TABLE_NUM_CELLS and UPDATE_RATE which are also passed in the MetaOscil constructor.

Parameters
N_OSCILis the number of Oscil contained in the MetaOscil. This cannot be changed after construction.

Definition at line 38 of file MetaOscil.h.

Member Function Documentation

◆ atIndex()

template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE, byte N_OSCIL>
int8_t MetaOscil< NUM_TABLE_CELLS, UPDATE_RATE, N_OSCIL >::atIndex ( unsigned int  index)
inline

Returns the sample at the given table index of the current Oscil.

Parameters
indexbetween 0 and the table size.The index rolls back around to 0 if it's larger than the table size.
Returns
the sample at the given table index.

Definition at line 203 of file MetaOscil.h.

◆ getPhaseFractional()

template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE, byte N_OSCIL>
unsigned long MetaOscil< NUM_TABLE_CELLS, UPDATE_RATE, N_OSCIL >::getPhaseFractional ( )
inline

Get the phase of the currently playin Oscil in fractional format.

Returns
position in the wavetable, shifted left by OSCIL_F_BITS (which is 16 when this was written).

Definition at line 114 of file MetaOscil.h.

◆ next()

template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE, byte N_OSCIL>
int8_t MetaOscil< NUM_TABLE_CELLS, UPDATE_RATE, N_OSCIL >::next ( )
inline

Updates the phase according to the current frequency and returns the sample at the new phase position.

Returns
the next sample.

Definition at line 93 of file MetaOscil.h.

◆ phaseIncFromFreq()

template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE, byte N_OSCIL>
unsigned long MetaOscil< NUM_TABLE_CELLS, UPDATE_RATE, N_OSCIL >::phaseIncFromFreq ( int  frequency)
inline

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

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 210 of file MetaOscil.h.

◆ phMod()

template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE, byte N_OSCIL>
int8_t MetaOscil< NUM_TABLE_CELLS, UPDATE_RATE, N_OSCIL >::phMod ( Q15n16  phmod_proportion)
inline

Returns the next sample given a phase modulation value.

Parameters
phmod_proportiona phase modulation value given as a proportion of the wave. The phmod_proportion parameter is a Q15n16 fixed-point number where the fractional n16 part represents almost -1 to almost 1, modulating the phase by one whole table length in each direction.
Returns
a sample from the table.

Definition at line 125 of file MetaOscil.h.

◆ setCutoffFreq()

template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE, byte N_OSCIL>
void MetaOscil< NUM_TABLE_CELLS, UPDATE_RATE, N_OSCIL >::setCutoffFreq ( int  freq,
byte  rank 
)
inline

Set or change the cutoff frequency of one Oscil.

Parameters
rankis the rank of the Oscil.
freqis the cutoff frequency.

Definition at line 84 of file MetaOscil.h.

◆ setCutoffFreqs()

template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE, byte N_OSCIL>
template<typename ... T>
void MetaOscil< NUM_TABLE_CELLS, UPDATE_RATE, N_OSCIL >::setCutoffFreqs ( int  first,
T...  elements 
)
inline

Set all the cutoff frequencies for changing between Oscil.

They have to be sorted in increasing values and contain at least N_OSCIL-1 values. Note that the last Oscil will be used by default for frequencies higher than the higher cutoff, hence the last value can be discarded.

Parameters
first,elements...a set of int cutoff frequencies.

Definition at line 71 of file MetaOscil.h.

◆ setFreq() [1/2]

template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE, byte N_OSCIL>
void MetaOscil< NUM_TABLE_CELLS, UPDATE_RATE, N_OSCIL >::setFreq ( float  frequency)
inline

Set the MetaOsc frequency with a float.

Parameters
frequencyto play the wave table.

Definition at line 170 of file MetaOscil.h.

◆ setFreq() [2/2]

template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE, byte N_OSCIL>
void MetaOscil< NUM_TABLE_CELLS, UPDATE_RATE, N_OSCIL >::setFreq ( int  frequency,
bool  apply = true 
)
inline

Set the MetaOsc frequency with an unsigned int.

Parameters
frequencyto play the wave table.

Definition at line 131 of file MetaOscil.h.

◆ setFreq_Q16n16()

template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE, byte N_OSCIL>
void MetaOscil< NUM_TABLE_CELLS, UPDATE_RATE, N_OSCIL >::setFreq_Q16n16 ( Q16n16  frequency)
inline

Set the MetaOsc frequency with a Q16n16 fixed-point number format.

Parameters
frequencyto play the wave table.

Definition at line 190 of file MetaOscil.h.

◆ setFreq_Q24n8()

template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE, byte N_OSCIL>
void MetaOscil< NUM_TABLE_CELLS, UPDATE_RATE, N_OSCIL >::setFreq_Q24n8 ( Q24n8  frequency)
inline

Set the MetaOsc frequency with a Q24n8 fixed-point number format.

Parameters
frequencyto play the wave table.

Definition at line 180 of file MetaOscil.h.

◆ setOscils()

template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE, byte N_OSCIL>
template<typename ... T>
void MetaOscil< NUM_TABLE_CELLS, UPDATE_RATE, N_OSCIL >::setOscils ( Oscil< NUM_TABLE_CELLS, UPDATE_RATE > *  first,
T...  elements 
)
inline

Set all Oscil of a MetaOscil.

Parameters
first...is a list of pointers towards several Oscil

Definition at line 57 of file MetaOscil.h.

◆ setPhase()

template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE, byte N_OSCIL>
void MetaOscil< NUM_TABLE_CELLS, UPDATE_RATE, N_OSCIL >::setPhase ( unsigned int  phase)
inline

Set the phase of the currently playing Oscil.

Parameters
phasea position in the wavetable.

Definition at line 103 of file MetaOscil.h.

◆ setPhaseFractional()

template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE, byte N_OSCIL>
void MetaOscil< NUM_TABLE_CELLS, UPDATE_RATE, N_OSCIL >::setPhaseFractional ( unsigned long  phase)
inline

Set the phase of the currently playing Oscil in fractional format.

Parameters
phasea position in the wavetable.

Definition at line 108 of file MetaOscil.h.

◆ setPhaseInc()

template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE, byte N_OSCIL>
void MetaOscil< NUM_TABLE_CELLS, UPDATE_RATE, N_OSCIL >::setPhaseInc ( unsigned long  phaseinc_fractional)
inline

Set a specific phase increment.

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

Definition at line 216 of file MetaOscil.h.

◆ setTable()

template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE, byte N_OSCIL>
void MetaOscil< NUM_TABLE_CELLS, UPDATE_RATE, N_OSCIL >::setTable ( const int8_t *  TABLE_NAME,
byte  rank 
)
inline

Change the sound table which will be played by the Oscil of rank.

Parameters
TABLE_NAMEis the name of the array in the table ".h" file you're using.
rankis the Oscil.

Definition at line 98 of file MetaOscil.h.