template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE>
class Oscil< NUM_TABLE_CELLS, UPDATE_RATE >
Oscil plays a wavetable, cycling through the table to generate an audio or control signal.
The frequency of the signal can be set or changed with setFreq(), and the output of an Oscil can be produced with next() for a simple cycling oscillator, or atIndex() for a particular sample in the table.
- Template Parameters
-
NUM_TABLE_CELLS | This is defined in the table ".h" file the Oscil will be using. It's important that it's a power of 2, and either a literal number (eg. "8192") or a defined macro, rather than a const or int, for the Oscil to run fast enough. |
UPDATE_RATE | This will be AUDIO_RATE if the Oscil is updated in updateAudio(), or CONTROL_RATE if it's updated each time updateControl() is called. It could also be a fraction of CONTROL_RATE if you are doing some kind of cyclic updating in updateControl(), for example, to spread out the processor load. |
- Note
- If you #define OSCIL_DITHER_PHASE before you #include <Oscil.h>, the phase increments will be dithered, which reduces spurious frequency spurs in the audio output, at the cost of some extra processing and memory.
int8_t2mozzi
Converting soundfiles for Mozzi There is a python script called char2mozzi.py in the Mozzi/python folder. The usage is: char2mozzi.py infilename outfilename tablename samplerate
Definition at line 62 of file Oscil.h.
template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE>
unsigned long Oscil< NUM_TABLE_CELLS, 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
-
frequency | for which you want to calculate a phase increment value. |
- Returns
- the phase increment value which will produce a given frequency.
Definition at line 262 of file Oscil.h.
template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE>
void Oscil< NUM_TABLE_CELLS, UPDATE_RATE >::setFreq |
( |
int |
frequency | ) |
|
|
inline |
Set the oscillator frequency with an unsigned int.
This is faster than using a float, so it's useful when processor time is tight, but it can be tricky with low and high frequencies, depending on the size of the wavetable being used. If you're not getting the results you expect, try explicitly using a float, or try setFreq_Q24n8() or or setFreq_Q16n16().
- Parameters
-
frequency | to play the wave table. |
Definition at line 165 of file Oscil.h.
template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE>
void Oscil< NUM_TABLE_CELLS, UPDATE_RATE >::setFreq |
( |
float |
frequency | ) |
|
|
inline |
Set the oscillator frequency with a float.
Using a float is the most reliable way to set frequencies, -Might- be slower than using an int but you need either this, setFreq_Q24n8() or setFreq_Q16n16() for fractional frequencies.
- Parameters
-
frequency | to play the wave table. |
Definition at line 180 of file Oscil.h.
template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE>
void Oscil< NUM_TABLE_CELLS, UPDATE_RATE >::setFreq_Q16n16 |
( |
Q16n16 |
frequency | ) |
|
|
inline |
Set the frequency using Q16n16 fixed-point number format.
This is useful in combination with Q16n16_mtof(), a fast alternative to mtof(), using Q16n16 fixed-point format instead of floats.
- Note
- This should work OK with tables 2048 cells or smaller and frequencies up to 4096 Hz. Can't be used with UPDATE_RATE less than 64 Hz.
-
This didn't run faster than float last time it was tested, after 2014 code changes. Need to see if 2014 changes improved or worsened performance.
- Parameters
-
frequency | in Q16n16 fixed-point number format. |
Definition at line 220 of file Oscil.h.
template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE>
void Oscil< NUM_TABLE_CELLS, UPDATE_RATE >::setFreq_Q24n8 |
( |
Q24n8 |
frequency | ) |
|
|
inline |
Set the frequency using Q24n8 fixed-point number format.
This might be faster than the float version for setting low frequencies such as 1.5 Hz, or other values which may not work well with your table size. A Q24n8 representation of 1.5 is 384 (ie. 1.5 * 256). Can't be used with UPDATE_RATE less than 64 Hz.
- Parameters
-
frequency | in Q24n8 fixed-point number format. |
Definition at line 194 of file Oscil.h.
template<uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE>
void Oscil< NUM_TABLE_CELLS, UPDATE_RATE >::setPhase |
( |
unsigned int |
phase | ) |
|
|
inline |
Set the phase of the Oscil.
This does the same thing as Sample::start(offset). Just different ways of thinking about oscillators and samples.
- Parameters
-
phase | a position in the wavetable. |
Definition at line 112 of file Oscil.h.