Teensy Wavetable Synthesis |

Public Member Functions | Static Public Member Functions | List of all members
AudioSynthWavetable Class Reference
Inheritance diagram for AudioSynthWavetable:

## Public Member Functions
| AudioSynthWavetable (void)
| Class constructor.
void | setInstrument (const instrument_data &instrument)
| Set the instrument_data struct to be used as the playback instrument. More...
void | amplitude (float v)
| Changes the amplitude to 'v'. More...
void | stop (void)
| Stop playing waveform. More...
void | playFrequency (float freq, int amp=DEFAULT_AMPLITUDE)
| Play waveform at defined frequency, amplitude. More...
void | playNote (int note, int amp=DEFAULT_AMPLITUDE)
| Play sample at specified note, amplitude. More...
bool | isPlaying (void)
void | setFrequency (float freq)
| Set various integer offsets to values that will produce intended frequencies. More...
virtual void | update (void)
| Called by the AudioStream library to fill the audio output buffer. More...
envelopeStateEnum | getEnvState (void)

## Static Public Member Functions
static float | midi_volume_transform (int midi_amp)
| Scale midi_amp to a value between 0.0 and 1.0 using a logarithmic tranformation. More...
static float | noteToFreq (int note)
| Convert a MIDI note value to its corresponding frequency. More...
static int | freqToNote (float freq)
| Convert a frequency to the corressponding MIDI note value. More...

## Member Function Documentation

void AudioSynthWavetable::amplitude | ( | float | v | ) |
| inline

Changes the amplitude to 'v'.

A value of 0 will set the synth output to minimum amplitude (i.e., no output). A value of 1 will set the output to the maximum amplitude. Amplitude is set linearly with intermediate values.

Parameters

  v | a value between 0.0 and 1.0

static int AudioSynthWavetable::freqToNote | ( | float | freq | ) |
| inline static

Convert a frequency to the corressponding MIDI note value.

Parameters

  freq | the frequency value as a float to convert

Returns
  a MIDI note (between 0 - 127)

static float AudioSynthWavetable::midi_volume_transform | ( | int | midi_amp | ) |
| inline static

Scale midi_amp to a value between 0.0 and 1.0 using a logarithmic tranformation.

Parameters

  midi_amp | a value between 0 and 127

Returns
  a value between 0.0 to 1.0

static float AudioSynthWavetable::noteToFreq | ( | int | note | ) |
| inline static

Convert a MIDI note value to its corresponding frequency.

Parameters

  note | a value between 0 and 127

Returns
  a frequency

void AudioSynthWavetable::playFrequency | ( | float | freq,
|  | int | amp = `DEFAULT_AMPLITUDE`
| ) |  |

Play waveform at defined frequency, amplitude.

Parameters

  freq | Frequency of note to playback, value between 1.0 and half of AUDIO_SAMPLE_RATE_EXACT
  amp | Amplitude scaling of note, value between 0-127, with 127 being base volume

void AudioSynthWavetable::playNote | ( | int | note,
|  | int | amp = `DEFAULT_AMPLITUDE`
| ) |  |

Play sample at specified note, amplitude.

Parameters

  note | Midi note number to playback, value between 0-127
  amp | Amplitude scaling of playback, value between 0-127, with 127 being base volume

void AudioSynthWavetable::setFrequency | ( | float | freq | ) |

Set various integer offsets to values that will produce intended frequencies.

the main integer offset, tone_incr, is used to step through the current sample's 16-bit PCM audio sample. Specifically, the tone_incr is the rate at which the interpolation code in update() steps through uint32_t space. The remaining offset variables represent a minimum and maximum offset allowed for tone_incr, which allows for low-frequency variation in playback frequency (aka vibrato). Further details on implementation in update() and in sample_data.h.

Parameters

  freq | frequency of the generated output (between 0 and the board-specific sample rate)

void AudioSynthWavetable::setInstrument | ( | const instrument_data & | instrument | ) |
| inline

Set the instrument_data struct to be used as the playback instrument.

A wavetable uses a set of samples to generate sound. This function is used to set the instrument samples.

Parameters

  instrument | a struct of type instrument_data, commonly prodced from a decoded SoundFont file using the SoundFont Decoder Script which accompanies this library.

void AudioSynthWavetable::stop | ( | void |  | ) |

Stop playing waveform.

Waveform does not immediately stop, but fades out based on release time.

void AudioSynthWavetable::update | ( | void |  | ) |
| virtual

Called by the AudioStream library to fill the audio output buffer.

The major parts are the interpoalation stage, and the volume envelope stage. Further details on implementation included inline.