4 #ifndef __M5_Speaker_Class_H__
5 #define __M5_Speaker_Class_H__
9 #if defined ( ESP_PLATFORM )
11 #include <freertos/FreeRTOS.h>
12 #include <freertos/task.h>
13 #include <driver/i2s.h>
19 #ifndef I2S_PIN_NO_CHANGE
20 #define I2S_PIN_NO_CHANGE (-1)
90 #if defined (ESP_PLATFORM)
137 void stop(uint8_t channel);
147 bool tone(
float frequency, uint32_t duration,
int channel,
bool stop_current_sound,
const uint8_t* raw_data,
size_t array_len,
bool stereo =
false)
149 return _play_raw(raw_data, array_len,
false,
false, frequency * (array_len >> stereo), stereo, (duration != UINT32_MAX) ? (uint32_t)(duration * frequency / 1000) : UINT32_MAX, channel, stop_current_sound,
true);
156 bool tone(
float frequency, uint32_t duration = UINT32_MAX,
int channel = -1,
bool stop_current_sound =
true) {
return tone(frequency, duration, channel, stop_current_sound,
_default_tone_wav,
sizeof(
_default_tone_wav),
false); }
168 bool playRaw(
const int8_t* raw_data,
size_t array_len, uint32_t sample_rate = 44100,
bool stereo =
false, uint32_t repeat = 1,
int channel = -1,
bool stop_current_sound =
false)
170 return _play_raw(
static_cast<const void*
>(raw_data), array_len,
false,
true, sample_rate, stereo, repeat, channel, stop_current_sound,
false);
172 [[deprecated(
"The playRAW function has been renamed to playRaw")]]
173 bool playRAW(
const int8_t* raw_data,
size_t array_len, uint32_t sample_rate = 44100,
bool stereo =
false, uint32_t repeat = 1,
int channel = -1,
bool stop_current_sound =
false)
175 return _play_raw(
static_cast<const void*
>(raw_data), array_len,
false,
true, sample_rate, stereo, repeat, channel, stop_current_sound,
false);
188 bool playRaw(
const uint8_t* raw_data,
size_t array_len, uint32_t sample_rate = 44100,
bool stereo =
false, uint32_t repeat = 1,
int channel = -1,
bool stop_current_sound =
false)
190 return _play_raw(
static_cast<const void*
>(raw_data), array_len,
false,
false, sample_rate, stereo, repeat, channel, stop_current_sound,
false);
192 [[deprecated(
"The playRAW function has been renamed to playRaw")]]
193 bool playRAW(
const uint8_t* raw_data,
size_t array_len, uint32_t sample_rate = 44100,
bool stereo =
false, uint32_t repeat = 1,
int channel = -1,
bool stop_current_sound =
false)
195 return _play_raw(
static_cast<const void*
>(raw_data), array_len,
false,
false, sample_rate, stereo, repeat, channel, stop_current_sound,
false);
208 bool playRaw(
const int16_t* raw_data,
size_t array_len, uint32_t sample_rate = 44100,
bool stereo =
false, uint32_t repeat = 1,
int channel = -1,
bool stop_current_sound =
false)
210 return _play_raw(
static_cast<const void*
>(raw_data), array_len,
true,
true, sample_rate, stereo, repeat, channel, stop_current_sound,
false);
214 [[deprecated(
"The playRAW function has been renamed to playRaw")]]
215 bool playRAW(
const int16_t* raw_data,
size_t array_len, uint32_t sample_rate = 44100,
bool stereo =
false, uint32_t repeat = 1,
int channel = -1,
bool stop_current_sound =
false)
217 return _play_raw(
static_cast<const void*
>(raw_data), array_len,
true,
true, sample_rate, stereo, repeat, channel, stop_current_sound,
false);
225 bool playWav(
const uint8_t* wav_data,
size_t data_len = ~0u, uint32_t repeat = 1,
int channel = -1,
bool stop_current_sound =
false);
272 bool _play_raw(
const void* wav,
size_t array_len,
bool flg_16bit,
bool flg_signed,
float sample_rate,
bool flg_stereo, uint32_t repeat_count,
int channel,
bool stop_current_sound,
bool no_clear_index);
#define I2S_PIN_NO_CHANGE
bool(* _cb_set_enabled)(void *args, bool enabled)
void setAllChannelVolume(uint8_t volume)
bool isEnabled(void) const
volatile bool _task_running
bool playRAW(const int8_t *raw_data, size_t array_len, uint32_t sample_rate=44100, bool stereo=false, uint32_t repeat=1, int channel=-1, bool stop_current_sound=false)
void stop(void)
stop sound output.
bool playRaw(const int16_t *raw_data, size_t array_len, uint32_t sample_rate=44100, bool stereo=false, uint32_t repeat=1, int channel=-1, bool stop_current_sound=false)
size_t isPlaying(uint8_t channel) const volatile
bool playRAW(const int16_t *raw_data, size_t array_len, uint32_t sample_rate=44100, bool stereo=false, uint32_t repeat=1, int channel=-1, bool stop_current_sound=false)
bool tone(float frequency, uint32_t duration=UINT32_MAX, int channel=-1, bool stop_current_sound=true)
speaker_config_t config(void) const
void * _cb_set_enabled_args
bool _set_next_wav(size_t ch, const wav_info_t &wav)
TaskHandle_t _task_handle
void config(const speaker_config_t &cfg)
bool playRAW(const uint8_t *raw_data, size_t array_len, uint32_t sample_rate=44100, bool stereo=false, uint32_t repeat=1, int channel=-1, bool stop_current_sound=false)
channel_info_t _ch_info[sound_channel_max]
bool isRunning(void) const
volatile uint8_t _master_volume
bool playWav(const uint8_t *wav_data, size_t data_len=~0u, uint32_t repeat=1, int channel=-1, bool stop_current_sound=false)
bool _play_raw(const void *wav, size_t array_len, bool flg_16bit, bool flg_signed, float sample_rate, bool flg_stereo, uint32_t repeat_count, int channel, bool stop_current_sound, bool no_clear_index)
esp_err_t _setup_i2s(void)
static void spk_task(void *args)
uint8_t getVolume(void) const
bool isPlaying(void) const volatile
size_t getPlayingChannels(void) const volatile
static const uint8_t _default_tone_wav[16]
virtual ~Speaker_Class(void)
std::atomic< uint16_t > _play_channel_bits
void setVolume(uint8_t master_volume)
static constexpr const size_t sound_channel_max
bool playRaw(const uint8_t *raw_data, size_t array_len, uint32_t sample_rate=44100, bool stereo=false, uint32_t repeat=1, int channel=-1, bool stop_current_sound=false)
uint8_t getChannelVolume(uint8_t channel) const
bool tone(float frequency, uint32_t duration, int channel, bool stop_current_sound, const uint8_t *raw_data, size_t array_len, bool stereo=false)
volatile SemaphoreHandle_t _task_semaphore
void setCallback(void *args, bool(*func)(void *, bool))
bool playRaw(const int8_t *raw_data, size_t array_len, uint32_t sample_rate=44100, bool stereo=false, uint32_t repeat=1, int channel=-1, bool stop_current_sound=false)
void setChannelVolume(uint8_t channel, uint8_t volume)
uint32_t sample_rate_x256
-1 mean infinity repeat
uint8_t task_pinned_core
background task pinned core
uint8_t magnification
multiplier for output value
uint8_t dac_zero_level
Zero level reference value when using DAC ( 0=Dynamic change )
bool buzzer
use single gpio buzzer, ( need only pin_data_out )
bool stereo
use stereo output
int pin_data_out
i2s_data_out (for spk)
uint8_t task_priority
background task priority
uint32_t sample_rate
output sampling rate (Hz)
i2s_port_t i2s_port
I2S port.
size_t dma_buf_count
for I2S dma_buf_count
size_t dma_buf_len
for I2S dma_buf_len (max 1024)