38 #include "freertos/FreeRTOS.h" 48 #define DEFAULT_SAMPLE_RATE 16000 52 #define I2S_SAMPLE_BUFFER_SIZE 200 // must be even 54 #define WAVEGENTASK_STACK_SIZE 1024 60 WaveformGenerator() : next(
nullptr), m_sampleRate(0), m_volume(100), m_enabled(
false) { }
106 void enable(
bool value) { m_enabled = value; }
127 uint16_t m_sampleRate;
145 uint16_t m_frequency;
146 int16_t m_lastSample;
169 uint16_t m_frequency;
187 uint16_t m_frequency;
204 uint16_t m_frequency;
238 int8_t
const * m_data;
286 bool play(
bool value);
335 void i2s_audio_init();
336 static void waveGenTask(
void * arg);
337 bool suspendPlay(
bool value);
341 TaskHandle_t m_waveGenTaskHandle;
345 uint16_t * m_sampleBuffer;
349 uint16_t m_sampleRate;
void setFrequency(int value)
Sets output frequency.
Definition: soundgen.cpp:319
Samples generator.
Definition: soundgen.h:229
int getSample()
Gets next sample.
Definition: soundgen.cpp:324
void clear()
Stops playing and removes all attached waveform generators.
Definition: soundgen.cpp:367
bool play(bool value)
Starts or stops playing.
Definition: soundgen.cpp:398
bool playing()
Determines whether sound generator is playing.
Definition: soundgen.cpp:432
int volume()
Determines current overall volume.
Definition: soundgen.h:330
This file contains some utility classes and functions.
Definition: canvas.cpp:47
SoundGenerator handles audio output.
Definition: soundgen.h:259
This file contains FabGL library configuration settings, like number of supported colors...
void detach(WaveformGenerator *value)
Detaches a waveform generator.
Definition: soundgen.cpp:452
void attach(WaveformGenerator *value)
Attaches a waveform generator.
Definition: soundgen.cpp:439
SoundGenerator(int sampleRate=DEFAULT_SAMPLE_RATE)
Creates an instance of the sound generator. Only one instance is allowed.
Definition: soundgen.cpp:348
void setVolume(int value)
Sets the overall volume.
Definition: soundgen.h:323