FabGL
ESP32 VGA Controller and Graphics Library
|
SoundGenerator handles audio output. More...
#include <soundgen.h>
Public Member Functions | |
SoundGenerator (int sampleRate=DEFAULT_SAMPLE_RATE) | |
Creates an instance of the sound generator. Only one instance is allowed. More... | |
void | attach (WaveformGenerator *value) |
Attaches a waveform generator. More... | |
void | clear () |
Stops playing and removes all attached waveform generators. More... | |
void | detach (WaveformGenerator *value) |
Detaches a waveform generator. More... | |
bool | play (bool value) |
Starts or stops playing. More... | |
bool | playing () |
Determines whether sound generator is playing. More... | |
void | setVolume (int value) |
Sets the overall volume. More... | |
int | volume () |
Determines current overall volume. More... | |
SoundGenerator handles audio output.
Applications attach waveform generators (like SineWaveformGenerator, SquareWaveformGenerator, etc...) and call SoundGenerator.play() to start audio generation.
The GPIO used for audio output is GPIO-25. See Configuring Audio port for audio connection sample schema.
Here is supported sound generators: SineWaveformGenerator SquareWaveformGenerator TriangleWaveformGenerator SawtoothWaveformGenerator NoiseWaveformGenerator SamplesGenerator
fabgl::SoundGenerator::SoundGenerator | ( | int | sampleRate = DEFAULT_SAMPLE_RATE | ) |
Creates an instance of the sound generator. Only one instance is allowed.
void fabgl::SoundGenerator::attach | ( | WaveformGenerator * | value | ) |
Attaches a waveform generator.
value | Pointer of the waveform generator to attach |
Example:
SineWaveformGenerator sine; soundGenerator.attach(&sine); sine.enable(true); sine.setFrequency(500); // 500 Hz
void fabgl::SoundGenerator::clear | ( | ) |
Stops playing and removes all attached waveform generators.
void fabgl::SoundGenerator::detach | ( | WaveformGenerator * | value | ) |
Detaches a waveform generator.
value | Pointer of the waveform generator to detach |
bool fabgl::SoundGenerator::play | ( | bool | value | ) |
Starts or stops playing.
value | True = starts playing, False = stops playing |
Example:
soundGenerator.play(true);
bool fabgl::SoundGenerator::playing | ( | ) |
Determines whether sound generator is playing.
|
inline |
Sets the overall volume.
value | Volume value. Minimum is 0, maximum is 127. |
|
inline |
Determines current overall volume.