synthberry
Software MIDI synthesizer for the Raspberry Pi.
 All Classes Functions
Public Member Functions | Protected Attributes | List of all members
Wave< SampleType > Class Template Reference

Abstract class used for generating and storing wave buffers. More...

#include <wave.h>

Inheritance diagram for Wave< SampleType >:
Inheritance graph
[legend]

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

Detailed Description

template<class SampleType>
class Wave< SampleType >

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.

Definition at line 25 of file wave.h.

Member Function Documentation

template<class SampleType >
void Wave< SampleType >::addToFormula ( FormulaFunction  func)

Add an extra formula.

Add an additional formula to Wave. Used by SynthModule subclasses.

Parameters
funcEffect formula

Definition at line 43 of file wave.cpp.

template<class SampleType >
float Wave< SampleType >::getLowestFrequency ( )

Retrieve the lowest frequency.

Retrieve the lowest known frequency component that was set on an earlier occasion.

Returns
Frequency in Hz

Definition at line 83 of file wave.cpp.

template<class SampleType >
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.

Parameters
freqNew lowest frequency in Hz

Definition at line 61 of file wave.cpp.

template<class SampleType >
void Wave< SampleType >::setNewFormula ( FormulaFunction  func)

Set a new formula.

Clear any current formulas and set a new one to be used for generating the wave buffer. Used by oscillators.

Parameters
funcInitial formula

Definition at line 28 of file wave.cpp.

template<class SampleType >
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.

Definition at line 98 of file wave.cpp.


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