7#include <freertos/event_groups.h>
8#include <freertos/queue.h>
9#include <freertos/FreeRTOS.h>
22static constexpr size_t TASK_STACK_SIZE = 4096;
23static constexpr ssize_t TASK_PRIORITY = 19;
51 void setup()
override;
62 void start()
override;
75 size_t play(
const uint8_t *data,
size_t length, TickType_t ticks_to_wait)
override;
95 static void speaker_task(
void *params);
98 virtual void run_speaker_task() = 0;
102 void stop_(
bool wait_on_empty);
122 esp_err_t
init_i2s_channel_(
const i2s_chan_config_t &chan_cfg,
const i2s_std_config_t &std_cfg,
123 size_t event_queue_size);
Abstract base class for I2S audio speaker implementations.
uint32_t buffer_duration_ms_
static bool i2s_on_sent_cb(i2s_chan_handle_t handle, i2s_event_data_t *event, void *user_ctx)
Callback function used to send playback timestamps to the speaker task.
bool get_pause_state() const override
void stop_i2s_driver_()
Stops the I2S driver and unlocks the I2S port.
i2s_chan_handle_t tx_handle_
void apply_software_volume_(uint8_t *data, size_t bytes_read)
Apply software volume control using Q15 fixed-point scaling.
std::weak_ptr< ring_buffer::RingBuffer > audio_ring_buffer_
TaskHandle_t speaker_task_handle_
void swap_esp32_mono_samples_(uint8_t *data, size_t bytes_read)
Swap adjacent 16-bit mono samples for ESP32 (non-variant) hardware quirk.
audio::AudioStreamInfo current_stream_info_
void dump_config() override
void set_dout_pin(uint8_t pin)
void set_buffer_duration(uint32_t buffer_duration_ms)
optional< uint32_t > timeout_
void set_timeout(uint32_t ms)
void set_pause_state(bool pause_state) override
int32_t q31_volume_factor_
float get_setup_priority() const override
QueueHandle_t write_records_queue_
virtual esp_err_t start_i2s_driver(audio::AudioStreamInfo &audio_stream_info)=0
Starts the ESP32 I2S driver.
QueueHandle_t i2s_event_queue_
EventGroupHandle_t event_group_
esp_err_t init_i2s_channel_(const i2s_chan_config_t &chan_cfg, const i2s_std_config_t &std_cfg, size_t event_queue_size)
Shared I2S channel allocation, initialization, and event queue setup.
i2s_chan_handle_t get_tx_handle() const
Get the I2S TX channel handle.
virtual void on_task_stopped()
Called in loop() when the task has stopped. Override for mode-specific cleanup.
void stop_(bool wait_on_empty)
Plays the provided audio data.
virtual size_t play(const uint8_t *data, size_t length)=0
Plays the provided audio data.
virtual void set_volume(float volume)
virtual void set_mute_state(bool mute_state)
virtual bool has_buffered_data() const =0
@ COMMAND_STOP_GRACEFULLY
constexpr float PROCESSOR
For components that use data from sensors like displays.
spi_device_handle_t handle