FabGL
ESP32 VGA Controller and Graphics Library
fabgl::SoundGenerator Class Reference

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...
 

Detailed Description

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

Constructor & Destructor Documentation

◆ SoundGenerator()

fabgl::SoundGenerator::SoundGenerator ( int  sampleRate = DEFAULT_SAMPLE_RATE)

Creates an instance of the sound generator. Only one instance is allowed.

Member Function Documentation

◆ attach()

void fabgl::SoundGenerator::attach ( WaveformGenerator value)

Attaches a waveform generator.

Parameters
valuePointer of the waveform generator to attach

Example:

SineWaveformGenerator sine;
soundGenerator.attach(&sine);
sine.enable(true);
sine.setFrequency(500);  // 500 Hz

◆ clear()

void fabgl::SoundGenerator::clear ( )

Stops playing and removes all attached waveform generators.

◆ detach()

void fabgl::SoundGenerator::detach ( WaveformGenerator value)

Detaches a waveform generator.

Parameters
valuePointer of the waveform generator to detach

◆ play()

bool fabgl::SoundGenerator::play ( bool  value)

Starts or stops playing.

Parameters
valueTrue = starts playing, False = stops playing
Returns
Returns previous playing state

Example:

soundGenerator.play(true);

◆ playing()

bool fabgl::SoundGenerator::playing ( )

Determines whether sound generator is playing.

Returns
True when playing, False otherwise

◆ setVolume()

void fabgl::SoundGenerator::setVolume ( int  value)
inline

Sets the overall volume.

Parameters
valueVolume value. Minimum is 0, maximum is 127.

◆ volume()

int fabgl::SoundGenerator::volume ( )
inline

Determines current overall volume.

Returns
Current overall volume (0 = minimum, 127 = maximum)

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