42#include "freertos/FreeRTOS.h"
44#if __has_include("esp32/rom/lldesc.h")
45 #include "esp32/rom/lldesc.h"
47 #include "rom/lldesc.h"
49#include "soc/i2s_struct.h"
50#include "soc/sens_struct.h"
60#define FABGL_SOUNDGEN_DEFAULT_SAMPLE_RATE 16384
65#define FABGL_SOUNDGEN_SAMPLE_BUFFER_SIZE 64
72 WaveformGenerator() : next(
nullptr), m_sampleRate(0), m_volume(100), m_enabled(
false), m_duration(-1), m_autoDestroy(
false), m_autoDetach(
false) { }
104 bool autoDetach() {
return m_autoDetach; }
111 void setAutoDestroy(
bool value) { m_autoDestroy = value; m_autoDetach |= value; }
113 bool autoDestroy() {
return m_autoDestroy; }
150 void enable(
bool value) { m_enabled = value; }
172 void decDuration() { --m_duration;
if (m_duration == 0) m_enabled =
false; }
175 uint16_t m_sampleRate;
196 uint16_t m_frequency;
197 int16_t m_lastSample;
220 uint16_t m_frequency;
238 uint16_t m_frequency;
255 uint16_t m_frequency;
288 uint16_t frequency() {
return m_frequency; }
293 static const uint16_t LFSRINIT = 0x0202;
294 static const int CLK = 4433618;
296 uint16_t m_frequency;
319 int8_t
const * m_data;
392 bool play(
bool value);
430 template <
typename T>
432 auto wf =
new T(waveform);
434 wf->setFrequency(frequency);
436 wf->setAutoDestroy(
true);
437 wf->setDuration(m_sampleRate / 1000 * durationMS);
463 void attach(WaveformGenerator * value);
470 void detach(WaveformGenerator * value);
489 static void ISRHandler(
void * arg);
490 static void timerHandler(
void * args);
493 void sigmadelta_init();
495 void setDMANode(
int index,
volatile uint16_t * buf,
int len);
500 #ifdef FABGL_EMULATED
502 static void SDLAudioCallback(
void *
data, Uint8 * buffer,
int length);
508 uint16_t * m_sampleBuffer[2];
512 uint16_t m_sampleRate;
518 intr_handle_t m_isr_handle;
520 lldesc_t
volatile * m_DMAChain;
526 esp_timer_handle_t m_timerHandle;
528 #ifdef FABGL_EMULATED
529 SDL_AudioDeviceID m_device;
int getSample()
Gets next sample.
void setFrequency(int value)
Sets output frequency.
void attach(WaveformGenerator *value)
Attaches a waveform generator.
void detach(WaveformGenerator *value)
Detaches a waveform generator.
SoundGenerator(int sampleRate=16384, gpio_num_t gpio=GPIO_AUTO, SoundGenMethod genMethod=SoundGenMethod::Auto)
Creates an instance of the sound generator. Only one instance is allowed.
int volume()
Determines current overall volume.
void setVolume(int value)
Sets the overall volume.
SamplesGenerator * playSamples(int8_t const *data, int length, int volume=100, int durationMS=0)
Plays the specified samples.
bool playing()
Determines whether sound generator is playing.
bool play(bool value)
Starts or stops playing.
void playSound(T const &waveform, int frequency, int durationMS, int volume=100)
Plays the specified waveform.
void clear()
Stops playing and removes all attached waveform generators.
SoundGenerator handles audio output.
int getSample()
Gets next sample.
void setFrequency(int value)
Sets output frequency.
Emulates VIC6561 (VIC20) noise generator.
This file contains FabGL library configuration settings, like number of supported colors,...
This file contains some utility classes and functions.
SoundGenMethod
Specifies sound generation method.