Sample is like Oscil, it plays a wavetable. More...
Public Member Functions | |
Sample (const char *TABLE_NAME) | |
Constructor. | |
Sample () | |
Constructor. | |
void | setTable (const char *TABLE_NAME) |
Change the sound table which will be played by the Sample. | |
void | setStart (unsigned int start) |
Sets the starting position in samples. | |
void | start () |
Resets the phase (the playhead) to the start position, which will be 0 unless set to another value with setStart();. | |
void | start (unsigned int startpos) |
Sets the a new start position and sets the phase (the playhead) to that position. | |
void | setEnd (unsigned int end) |
Sets the end position in samples from the beginning of the sound. | |
void | rangeWholeSample () |
Sets the start and end points to include the range of the whole sound table. | |
void | setLoopingOn () |
Turns looping on, with the whole sample length as the loop range. | |
void | setLoopingOff () |
Turns looping off. | |
char | next () |
Returns the sample at the current phase position, or 0 if looping is off and the phase overshoots the end of the sample. | |
void | setFreq (unsigned int frequency) |
Returns the next sample given a phase modulation value. | |
void | setFreq (float frequency) |
Set the sample frequency with a float. | |
void | setFreq_Q24n8 (Q24n8 frequency) |
Set the frequency using Q24n8 fixed-point number format. | |
char | atIndex (unsigned int index) |
Returns the sample at the given table index. | |
unsigned long | phaseIncFromFreq (unsigned int frequency) |
phaseIncFromFreq() and setPhaseInc() are for saving processor time when sliding between frequencies. | |
void | setPhaseInc (unsigned long phaseinc_fractional) |
Set a specific phase increment. |
Sample is like Oscil, it plays a wavetable.
However, Sample can be set to play once through only, with variable start and end points, or can loop, also with variable start and end points. It defaults to playing once through the whole sound table, from start to finish.
NUM_TABLE_CELLS | This is defined in the table ".h" file the Sample will be using. The sound table can be arbitrary length for Sample. It's important that NUM_TABLE_CELLS is either a literal number (eg. "8192") or a defined macro, rather than a const or int, for the Sample to run fast enough. |
UPDATE_RATE | This will be AUDIO_RATE if the Sample 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. |
Converting soundfiles for Mozzi. There is a python script called char2mozzi.py in the Mozzi/python folder. The script converts raw sound data saved from a program like Audacity. Instructions are in the char2mozzi.py file.
Sample< NUM_TABLE_CELLS, UPDATE_RATE >::Sample | ( | const char * | TABLE_NAME | ) | [inline] |
Constructor.
TABLE_NAME | the name of the array the Sample will be using. This can be found in the table ".h" file if you are using a table made for Mozzi by the char2mozzi.py python script in Mozzi's python folder. Sound tables can be of arbitrary lengths for Sample(). |
Sample< NUM_TABLE_CELLS, UPDATE_RATE >::Sample | ( | ) | [inline] |
Constructor.
Declare a Sample with template TABLE_NUM_CELLS and UPDATE_RATE parameters, without specifying a particular wave table for it to play. The table can be set or changed on the fly with setTable().
char Sample< NUM_TABLE_CELLS, UPDATE_RATE >::next | ( | ) | [inline] |
Returns the sample at the current phase position, or 0 if looping is off and the phase overshoots the end of the sample.
Updates the phase according to the current frequency.
unsigned long Sample< NUM_TABLE_CELLS, UPDATE_RATE >::phaseIncFromFreq | ( | unsigned 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!)
frequency | for which you want to calculate a phase increment value. |
void Sample< NUM_TABLE_CELLS, UPDATE_RATE >::setFreq | ( | unsigned int | frequency | ) | [inline] |
Returns the next sample given a phase modulation value.
a | phase modulation value given as a proportion of the wave. The phmod_proportion parameter is a Q15n16 fixed-point number where to fractional n16 part represents -1 to 1, modulating the phase by one whole table length in each direction. |
frequency | to play the wave table. |
void Sample< 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. Note: use with caution because it's prone to overflow with higher frequencies and larger table sizes. An Q24n8 representation of 1.5 is 384 (ie. 1.5 * 256).
frequency | in Q24n8 fixed-point number format. |
void Sample< NUM_TABLE_CELLS, UPDATE_RATE >::setPhaseInc | ( | unsigned long | phaseinc_fractional | ) | [inline] |
Set a specific phase increment.
See phaseIncFromFreq().
phaseinc_fractional | a phase increment value as calculated by phaseIncFromFreq(). |