Abstract class used for generating and storing wave buffers. More...
#include <wave.h>
Public Member Functions | |
Wave (uint16_t bitrate) | |
virtual SampleType | getNextSample ()=0 |
void | setNewFormula (FormulaFunction func) |
Set a new formula. | |
void | addToFormula (FormulaFunction func) |
Add an extra formula. | |
void | setLowestFrequency (float freq) |
Set a new lowest frequency. | |
float | getLowestFrequency () |
Retrieve the lowest frequency. | |
void | updateBuffer () |
Update the wave buffer. |
Protected Attributes | |
SampleType * | buffer |
std::size_t | bufferSize |
Abstract class used for generating and storing wave buffers.
The abstract Wave class provides a generic approach to store waves. A Wave represents the sound associated with a note being played, along with any additional effects. IAudioOutput implementations deal with the abstract Wave, leaving SynthModule classes with the flexibility of choosing or even introducing their own subclasses of Wave.
A sound is constructed by setting a formula that generates the data for the wave. SynthModule classes can add more formulas to the initial one to apply any required effects. These formulas are implemented as functions and are called sequentially upon generation of the buffer.
Wave needs to know the lowest frequency present in the sound to accommodate for a buffer which can hold at least one full period.
void Wave< SampleType >::addToFormula | ( | FormulaFunction | func | ) |
float Wave< SampleType >::getLowestFrequency | ( | ) |
void Wave< SampleType >::setLowestFrequency | ( | float | freq | ) |
Set a new lowest frequency.
As Wave bases its buffer size on the length of a full period of the wave, it needs to know the lowest frequency component present in it. When setting or adding formulas, call this method to update the buffer size.
Should you call this method with a higher freq than was used earlier, nothing happens.
freq | New lowest frequency in Hz |
void Wave< SampleType >::setNewFormula | ( | FormulaFunction | func | ) |
void Wave< SampleType >::updateBuffer | ( | ) |
Update the wave buffer.
After setting a formula, adding a formula, or setting a new lowest frequency, you need to update the buffer with newly generated values before a sound can be played.
You should avoid unnecessary calls to this method, calling it once after you are ready with the Wave is best.