Mozzi  alpha 0.01.1m
sound synthesis library for Arduino
 All Classes Functions
Public Member Functions
SampleCompressed< NUM_TABLE_CELLS, UPDATE_RATE > Class Template Reference

SampleCompressed is like Oscil, it plays a wavetable, but defaults to playing once through, from start to finish. More...

List of all members.

Public Member Functions

 SampleCompressed (const char *TABLE_NAME)
 Constructor.
 SampleCompressed ()
 Constructor.
void setTable (const char *TABLE_NAME)
 Change the sound table which will be played by the SampleCompressed.
void start ()
 Resets the phase (the playhead) to the beginning of the table.
void start (unsigned int offset)
 Sets the phase (the playhead) to an offset position.
char next ()
 Updates the phase according to the current frequency and returns the sample at the new phase position, or 0 when the phase overshoots the end of the table.
char phMod (long phmod_proportion)
 Returns the next sample given a phase modulation value.
void setFreq_Q24n8 (unsigned long frequency)
 Set the frequency using Q24n8 fixed-point number format.
void setFreq (unsigned int frequency)
 Set the oscillator frequency with an unsigned int.
void setFreq (float frequency)
 Set the oscillator frequency with a float.
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.

Detailed Description

template<unsigned int NUM_TABLE_CELLS, unsigned int UPDATE_RATE>
class SampleCompressed< NUM_TABLE_CELLS, UPDATE_RATE >

SampleCompressed is like Oscil, it plays a wavetable, but defaults to playing once through, from start to finish.

Template Parameters:
NUM_TABLE_CELLSThis is defined in the table ".h" file the SampleCompressed will be using. It's important that it's either a literal number (eg. "8192") or a defined macro, rather than a const or int, for the SampleCompressed to run fast enough.
UPDATE_RATEThis will be AUDIO_RATE if the SampleCompressed 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.

char2mozzi

Converting soundfiles for Mozzi. There is a python script called char2mozzi.py in the Mozzi/python folder. The usage is: python char2mozzi.py infilename outfilename tablename samplerate

Todo:
Make SampleCompressed a descendent of Oscil.

Definition at line 58 of file SampleCompressed.h.


Constructor & Destructor Documentation

template<unsigned int NUM_TABLE_CELLS, unsigned int UPDATE_RATE>
SampleCompressed< NUM_TABLE_CELLS, UPDATE_RATE >::SampleCompressed ( const char *  TABLE_NAME) [inline]

Constructor.

Parameters:
TABLE_NAMEthe name of the array the SampleCompressed 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.

Definition at line 68 of file SampleCompressed.h.

template<unsigned int NUM_TABLE_CELLS, unsigned int UPDATE_RATE>
SampleCompressed< NUM_TABLE_CELLS, UPDATE_RATE >::SampleCompressed ( ) [inline]

Constructor.

Declare a SampleCompressed 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().

Definition at line 77 of file SampleCompressed.h.


Member Function Documentation

template<unsigned int NUM_TABLE_CELLS, unsigned int UPDATE_RATE>
char SampleCompressed< NUM_TABLE_CELLS, UPDATE_RATE >::atIndex ( unsigned int  index) [inline]

Returns the sample at the given table index.

Parameters:
atIndextable index between 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 199 of file SampleCompressed.h.

template<unsigned int NUM_TABLE_CELLS, unsigned int UPDATE_RATE>
char SampleCompressed< NUM_TABLE_CELLS, UPDATE_RATE >::next ( ) [inline]

Updates the phase according to the current frequency and returns the sample at the new phase position, or 0 when the phase overshoots the end of the table.

Returns:
the next sample value from the table, or 0 if it's finished playing.

Definition at line 120 of file SampleCompressed.h.

template<unsigned int NUM_TABLE_CELLS, unsigned int UPDATE_RATE>
unsigned long SampleCompressed< 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!)

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 215 of file SampleCompressed.h.

template<unsigned int NUM_TABLE_CELLS, unsigned int UPDATE_RATE>
char SampleCompressed< NUM_TABLE_CELLS, UPDATE_RATE >::phMod ( long  phmod_proportion) [inline]

Returns the next sample given a phase modulation value.

Parameters:
aphase 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.
Returns:
a sample from the table.

Definition at line 140 of file SampleCompressed.h.

template<unsigned int NUM_TABLE_CELLS, unsigned int UPDATE_RATE>
void SampleCompressed< NUM_TABLE_CELLS, UPDATE_RATE >::setFreq ( unsigned 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.

Parameters:
frequencyto play the wave table.

Definition at line 171 of file SampleCompressed.h.

template<unsigned int NUM_TABLE_CELLS, unsigned int UPDATE_RATE>
void SampleCompressed< 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 or setFreq_Q24n8 for fractional frequencies.

Parameters:
frequencyto play the wave table.

Definition at line 185 of file SampleCompressed.h.

template<unsigned int NUM_TABLE_CELLS, unsigned int UPDATE_RATE>
void SampleCompressed< NUM_TABLE_CELLS, UPDATE_RATE >::setFreq_Q24n8 ( unsigned long  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).

Parameters:
frequencyin Q24n8 fixed-point number format.

Definition at line 155 of file SampleCompressed.h.

template<unsigned int NUM_TABLE_CELLS, unsigned int UPDATE_RATE>
void SampleCompressed< NUM_TABLE_CELLS, UPDATE_RATE >::setPhaseInc ( unsigned long  phaseinc_fractional) [inline]

Set a specific phase increment.

See phaseIncFromFreq().

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

Definition at line 224 of file SampleCompressed.h.

template<unsigned int NUM_TABLE_CELLS, unsigned int UPDATE_RATE>
void SampleCompressed< NUM_TABLE_CELLS, UPDATE_RATE >::setTable ( const char *  TABLE_NAME) [inline]

Change the sound table which will be played by the SampleCompressed.

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

Definition at line 84 of file SampleCompressed.h.

template<unsigned int NUM_TABLE_CELLS, unsigned int UPDATE_RATE>
void SampleCompressed< NUM_TABLE_CELLS, UPDATE_RATE >::start ( unsigned int  offset) [inline]

Sets the phase (the playhead) to an offset position.

This does the same thing as Oscil::setPhase(phase). Just different ways of thinking about samples and oscillators.

Parameters:
offsetposition in samples.

Definition at line 106 of file SampleCompressed.h.


The documentation for this class was generated from the following file: