ESPHome 2026.6.4
Loading...
Searching...
No Matches
i2s_audio_speaker_standard.cpp
Go to the documentation of this file.
2
3#ifdef USE_ESP32
4
5#include <driver/i2s_std.h>
6#include <hal/dma_types.h>
7
10
11#include "esphome/core/hal.h"
12#include "esphome/core/log.h"
13
14#include "esp_timer.h"
15
16namespace esphome::i2s_audio {
17
18static const char *const TAG = "i2s_audio.speaker.std";
19
20static constexpr uint32_t DMA_BUFFER_DURATION_MS = 10;
21static constexpr size_t DMA_BUFFERS_COUNT = 5;
22// ESP-IDF clamps each DMA descriptor to this many bytes when allocating the channel (see i2s_get_buf_size in
23// the I2S driver). Mirror its target-dependent selection so the requested dma_frame_num stays in range; the
24// speaker task reads the size actually allocated back from the driver rather than relying on this value.
25#if SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE
26static constexpr size_t I2S_DMA_BUFFER_MAX_SIZE = DMA_DESCRIPTOR_BUFFER_MAX_SIZE_64B_ALIGNED;
27#else
28static constexpr size_t I2S_DMA_BUFFER_MAX_SIZE = DMA_DESCRIPTOR_BUFFER_MAX_SIZE_4B_ALIGNED;
29#endif
30// Sized to comfortably absorb scheduling jitter: at most DMA_BUFFERS_COUNT events can be in flight,
31// doubled so that a transient backlog never overruns the queue (which would desync the lockstep
32// invariant between i2s_event_queue_ and write_records_queue_).
33static constexpr size_t I2S_EVENT_QUEUE_COUNT = DMA_BUFFERS_COUNT * 2;
34// Generous timeout for ``i2s_channel_write`` blocking. A buffer frees roughly every
35// DMA_BUFFER_DURATION_MS, so a multiple of that gives plenty of slack against scheduling jitter
36// without masking real failures.
37static constexpr TickType_t WRITE_TIMEOUT_TICKS = pdMS_TO_TICKS(DMA_BUFFER_DURATION_MS * (DMA_BUFFERS_COUNT + 1));
38
39// Requested frames per DMA buffer for the given stream, clamped so the byte size stays within the ESP-IDF
40// maximum DMA descriptor size. This is only the value handed to the channel config: ESP-IDF may still adjust
41// it (e.g. cache-line rounding on some targets), so the speaker task reads the size actually allocated back
42// from the driver instead of assuming this value. Clamping here keeps the request in range and avoids a
43// noisy ESP-IDF "dma frame num is out of dma buffer size" warning at high sample rates or bit depths.
44static uint32_t dma_buffer_frames(const audio::AudioStreamInfo &stream_info) {
45 const uint32_t frames_from_duration = stream_info.ms_to_frames(DMA_BUFFER_DURATION_MS);
46 const uint32_t max_frames = I2S_DMA_BUFFER_MAX_SIZE / stream_info.frames_to_bytes(1);
47 return std::min(frames_from_duration, max_frames);
48}
49
52 const char *fmt_str;
53 switch (this->i2s_comm_fmt_) {
54 case I2SCommFmt::PCM:
55 fmt_str = "pcm";
56 break;
57 case I2SCommFmt::MSB:
58 fmt_str = "msb";
59 break;
60 default:
61 fmt_str = "std";
62 break;
63 }
64 ESP_LOGCONFIG(TAG, " Communication format: %s", fmt_str);
65}
66
68 xEventGroupSetBits(this->event_group_, SpeakerEventGroupBits::TASK_STARTING);
69
70 const uint32_t dma_buffers_duration_ms = DMA_BUFFER_DURATION_MS * DMA_BUFFERS_COUNT;
71 // Ensure ring buffer duration is at least the duration of all DMA buffers
72 const uint32_t ring_buffer_duration = std::max(dma_buffers_duration_ms, this->buffer_duration_ms_);
73
74 // The DMA buffers may have more bits per sample, so calculate buffer sizes based on the input audio stream info
75 const size_t bytes_per_frame = this->current_stream_info_.frames_to_bytes(1);
76 // Round the ring buffer size down to a multiple of bytes_per_frame so the wrap boundary stays frame-aligned and
77 // avoids unnecessary single-frame splices.
78 const size_t ring_buffer_size =
79 (this->current_stream_info_.ms_to_bytes(ring_buffer_duration) / bytes_per_frame) * bytes_per_frame;
80 // ESP-IDF may allocate smaller (or cache-line-rounded) DMA buffers than dma_buffer_frames() requested: it
81 // clamps each descriptor to the max DMA descriptor size and, on targets that route internal memory through
82 // the L1 cache (e.g. ESP32-P4), rounds the buffer to the cache line. Read the size the driver actually
83 // allocated so preload, silence padding, and the write/event lockstep all match it exactly. The channel is
84 // in the READY state here because start_i2s_driver() initialized it before this task was created.
85 size_t dma_buffer_bytes;
86 i2s_chan_info_t chan_info;
87 if (i2s_channel_get_info(this->tx_handle_, &chan_info) == ESP_OK && chan_info.total_dma_buf_size > 0) {
88 // total_dma_buf_size spans all DMA_BUFFERS_COUNT descriptors and is an exact multiple of the count.
89 dma_buffer_bytes = chan_info.total_dma_buf_size / DMA_BUFFERS_COUNT;
90 } else {
91 // Should not happen for a READY channel; fall back to the requested size.
92 dma_buffer_bytes = this->current_stream_info_.frames_to_bytes(dma_buffer_frames(this->current_stream_info_));
93 }
94 const uint32_t frames_per_dma_buffer = this->current_stream_info_.bytes_to_frames(dma_buffer_bytes);
95
96 bool successful_setup = false;
97
98 std::unique_ptr<audio::RingBufferAudioSource> audio_source;
99
100 // Pre-zeroed buffer used to silence-pad each DMA descriptor whenever real audio doesn't fully fill it.
101 RAMAllocator<uint8_t> silence_allocator;
102 uint8_t *silence_buffer = silence_allocator.allocate(dma_buffer_bytes);
103
104 if (silence_buffer != nullptr) {
105 memset(silence_buffer, 0, dma_buffer_bytes);
106
107 std::shared_ptr<ring_buffer::RingBuffer> temp_ring_buffer = ring_buffer::RingBuffer::create(ring_buffer_size);
108 audio_source =
109 audio::RingBufferAudioSource::create(temp_ring_buffer, dma_buffer_bytes, static_cast<uint8_t>(bytes_per_frame));
110
111 if (audio_source != nullptr) {
112 // audio_source is nullptr if the ring buffer fails to allocate
113 this->audio_ring_buffer_ = temp_ring_buffer;
114 successful_setup = true;
115 }
116 }
117
118 if (successful_setup) {
119 // Preload every DMA descriptor with silence and push a matching zero-real-frames record per buffer.
120 // This guarantees that every on_sent event has a corresponding write record from the start, so
121 // ``i2s_event_queue_`` and ``write_records_queue_`` stay in lockstep for the entire task lifetime.
122 for (size_t i = 0; i < DMA_BUFFERS_COUNT; i++) {
123 size_t bytes_loaded = 0;
124 esp_err_t err = i2s_channel_preload_data(this->tx_handle_, silence_buffer, dma_buffer_bytes, &bytes_loaded);
125 if (err != ESP_OK || bytes_loaded != dma_buffer_bytes) {
126 ESP_LOGV(TAG, "Failed to preload silence into DMA buffer %u (err=%d, loaded=%u)", (unsigned) i, (int) err,
127 (unsigned) bytes_loaded);
128 successful_setup = false;
129 break;
130 }
131 uint32_t zero_real_frames = 0;
132 if (xQueueSend(this->write_records_queue_, &zero_real_frames, 0) != pdTRUE) {
133 // Should never happen: the queue was just reset and is sized for DMA_BUFFERS_COUNT * 2 entries.
134 ESP_LOGV(TAG, "Failed to push preload write record");
135 successful_setup = false;
136 break;
137 }
138 }
139 }
140
141 if (successful_setup) {
142 // Register the on_sent callback BEFORE enabling the channel so the very first transmitted buffer
143 // generates a queued event that pairs with the first preloaded silence record.
144 const i2s_event_callbacks_t callbacks = {.on_sent = i2s_on_sent_cb};
145 i2s_channel_register_event_callback(this->tx_handle_, &callbacks, this);
146
147 if (i2s_channel_enable(this->tx_handle_) != ESP_OK) {
148 ESP_LOGV(TAG, "Failed to enable I2S channel");
149 successful_setup = false;
150 }
151 }
152
153 if (!successful_setup) {
154 xEventGroupSetBits(this->event_group_, SpeakerEventGroupBits::ERR_ESP_NO_MEM);
155 } else {
156 bool stop_gracefully = false;
157 // Number of records currently in ``write_records_queue_`` that carry real audio. Used by graceful
158 // stop to wait until every real-audio buffer has been confirmed played by an ISR event.
159 uint32_t pending_real_buffers = 0;
160 uint32_t last_data_received_time = millis();
161
162 xEventGroupSetBits(this->event_group_, SpeakerEventGroupBits::TASK_RUNNING);
163
164 // Main speaker task loop. Continues while:
165 // - Paused, OR
166 // - No timeout configured, OR
167 // - Timeout hasn't elapsed since last data
168 //
169 // Always-fill model: every iteration writes exactly one DMA buffer's worth, mixing real audio
170 // and silence padding as needed. The blocking ``i2s_channel_write`` paces the loop at the DMA
171 // consumption rate, and every buffer write is matched 1:1 with a record on ``write_records_queue_``.
172 //
173 // While paused, the real-audio fill is skipped and the entire DMA buffer is filled with silence;
174 // the same blocking ``i2s_channel_write`` provides natural pacing (one buffer per ~DMA_BUFFER_DURATION_MS),
175 // so the lockstep invariant is preserved without burning CPU.
176 while (this->pause_state_ || !this->timeout_.has_value() ||
177 (millis() - last_data_received_time) <= this->timeout_.value()) {
178 uint32_t event_group_bits = xEventGroupGetBits(this->event_group_);
179
180 if (event_group_bits & SpeakerEventGroupBits::COMMAND_STOP) {
181 // COMMAND_STOP is set both by user-initiated stop() and by the ISR when it drops a completion
182 // event (paired with ERR_DROPPED_EVENT so loop() can distinguish the two cases).
183 xEventGroupClearBits(this->event_group_, SpeakerEventGroupBits::COMMAND_STOP);
184 ESP_LOGV(TAG, "Exiting: COMMAND_STOP received");
185 break;
186 }
187 if (event_group_bits & SpeakerEventGroupBits::COMMAND_STOP_GRACEFULLY) {
188 xEventGroupClearBits(this->event_group_, SpeakerEventGroupBits::COMMAND_STOP_GRACEFULLY);
189 stop_gracefully = true;
190 }
191
192 if (this->audio_stream_info_ != this->current_stream_info_) {
193 // Audio stream info changed, stop the speaker task so it will restart with the proper settings.
194 ESP_LOGV(TAG, "Exiting: stream info changed");
195 break;
196 }
197
198 // Drain ISR-stamped completion events. Each event corresponds 1:1 with a write_records_queue_
199 // entry by construction (preloaded records at startup, plus exactly one record pushed per
200 // iteration alongside exactly one DMA-buffer-sized write).
201 int64_t write_timestamp;
202 bool lockstep_broken = false;
203 while (xQueueReceive(this->i2s_event_queue_, &write_timestamp, 0)) {
204 uint32_t real_frames = 0;
205 if (xQueueReceive(this->write_records_queue_, &real_frames, 0) != pdTRUE) {
206 // Should never happen: would indicate the lockstep invariant is broken.
207 ESP_LOGV(TAG, "Event without matching write record");
209 lockstep_broken = true;
210 break;
211 }
212 if (real_frames > 0) {
213 pending_real_buffers--;
214 // Real audio is packed at the start of each DMA buffer with any silence padding on the
215 // tail, so the real audio finished playing earlier than the buffer-completion timestamp
216 // by the duration of the trailing zeros.
217 const uint32_t silence_frames = frames_per_dma_buffer - real_frames;
218 const int64_t adjusted_ts =
219 write_timestamp - this->current_stream_info_.frames_to_microseconds(silence_frames);
220 this->audio_output_callback_(real_frames, adjusted_ts);
221 }
222 }
223 if (lockstep_broken) {
224 break;
225 }
226
227 // Graceful stop: exit only after the source's exposed chunk is drained, the underlying ring
228 // buffer has nothing left to hand over, and every real-audio buffer we submitted has been
229 // confirmed played. ``has_buffered_data()`` returns bytes still sitting in the ring buffer
230 // awaiting fill().
231 if (stop_gracefully && audio_source->available() == 0 && !this->has_buffered_data() &&
232 pending_real_buffers == 0) {
233 ESP_LOGV(TAG, "Exiting: graceful stop complete");
234 break;
235 }
236
237 // Compose exactly one DMA buffer's worth: drain as much real audio as the source currently
238 // exposes (may take multiple fill() calls when crossing a ring buffer wrap), then pad any
239 // remainder with silence. All writes pack into the next free DMA descriptor in order, so the
240 // descriptor ends up holding [real audio][silence padding].
241 size_t bytes_written_total = 0;
242 size_t real_bytes_total = 0;
243 bool partial_write_failure = false;
244
245 if (!this->pause_state_) {
246 while (bytes_written_total < dma_buffer_bytes) {
247 size_t bytes_read = audio_source->fill(pdMS_TO_TICKS(DMA_BUFFER_DURATION_MS) / 2, false);
248 if (bytes_read > 0) {
249 uint8_t *new_data = audio_source->mutable_data() + audio_source->available() - bytes_read;
250 this->apply_software_volume_(new_data, bytes_read);
251 this->swap_esp32_mono_samples_(new_data, bytes_read);
252 }
253
254 const size_t to_write = std::min(audio_source->available(), dma_buffer_bytes - bytes_written_total);
255 if (to_write == 0) {
256 // Ring buffer has nothing more to hand over right now; pad the rest of this DMA buffer
257 // with silence so the lockstep invariant (one write per iteration) is preserved.
258 break;
259 }
260
261 size_t bw = 0;
262 i2s_channel_write(this->tx_handle_, audio_source->data(), to_write, &bw, WRITE_TIMEOUT_TICKS);
263 if (bw != to_write) {
264 // A short real-audio write breaks DMA descriptor alignment for every subsequent event;
265 // the only safe recovery is to restart the task.
266 ESP_LOGV(TAG, "Partial real audio write: %u of %u bytes", (unsigned) bw, (unsigned) to_write);
268 partial_write_failure = true;
269 break;
270 }
271 audio_source->consume(bw);
272 bytes_written_total += bw;
273 real_bytes_total += bw;
274 }
275 if (real_bytes_total > 0) {
276 last_data_received_time = millis();
277 }
278 }
279
280 if (partial_write_failure) {
281 break;
282 }
283
284 const size_t silence_bytes = dma_buffer_bytes - bytes_written_total;
285 if (silence_bytes > 0) {
286 size_t bw = 0;
287 i2s_channel_write(this->tx_handle_, silence_buffer, silence_bytes, &bw, WRITE_TIMEOUT_TICKS);
288 if (bw != silence_bytes) {
289 // Same descriptor-alignment hazard as a partial real-audio write.
290 ESP_LOGV(TAG, "Partial silence write: %u of %u bytes", (unsigned) bw, (unsigned) silence_bytes);
292 break;
293 }
294 }
295
296 const uint32_t real_frames_in_buffer = this->current_stream_info_.bytes_to_frames(real_bytes_total);
297 // Push the matching write record. Capacity headroom in I2S_EVENT_QUEUE_COUNT guarantees this
298 // succeeds even with a transient backlog of unprocessed events; if it ever fails the lockstep
299 // invariant is broken and every subsequent timestamp would be silently wrong, so bail.
300 if (xQueueSend(this->write_records_queue_, &real_frames_in_buffer, 0) != pdTRUE) {
301 ESP_LOGV(TAG, "Exiting: write records queue full");
303 break;
304 }
305 if (real_frames_in_buffer > 0) {
306 pending_real_buffers++;
307 }
308 }
309 }
310
311 xEventGroupSetBits(this->event_group_, SpeakerEventGroupBits::TASK_STOPPING);
312
313 audio_source.reset();
314
315 if (silence_buffer != nullptr) {
316 silence_allocator.deallocate(silence_buffer, dma_buffer_bytes);
317 silence_buffer = nullptr;
318 }
319
320 xEventGroupSetBits(this->event_group_, SpeakerEventGroupBits::TASK_STOPPED);
321
322 while (true) {
323 // Continuously delay until the loop method deletes the task
324 vTaskDelay(pdMS_TO_TICKS(10));
325 }
326}
327
329 this->current_stream_info_ = audio_stream_info;
330
331 if ((this->i2s_role_ & I2S_ROLE_SLAVE) && (this->sample_rate_ != audio_stream_info.get_sample_rate())) { // NOLINT
332 // Can't reconfigure I2S bus, so the sample rate must match the configured value
333 ESP_LOGE(TAG, "Incompatible stream settings");
334 return ESP_ERR_NOT_SUPPORTED;
335 }
336
337 if (this->slot_bit_width_ != I2S_SLOT_BIT_WIDTH_AUTO &&
338 (i2s_slot_bit_width_t) audio_stream_info.get_bits_per_sample() > this->slot_bit_width_) {
339 // Currently can't handle the case when the incoming audio has more bits per sample than the configured value
340 ESP_LOGE(TAG, "Stream bits per sample must be less than or equal to the speaker's configuration");
341 return ESP_ERR_NOT_SUPPORTED;
342 }
343
344#ifdef USE_ESP32_VARIANT_ESP32
345 // The original ESP32 I2S peripheral stores each sample in a whole number of 16-bit words (a 24-bit sample
346 // occupies 4 bytes in the DMA buffer, an 8-bit sample 2 bytes), but ESPHome's audio pipeline packs samples
347 // tightly (3 bytes for 24-bit, 1 for 8-bit). The two layouts only line up when the bit depth is a multiple
348 // of 16, so reject anything else rather than emit corrupted audio.
349 if (audio_stream_info.get_bits_per_sample() % 16 != 0) {
350 ESP_LOGE(TAG, "ESP32 supports only 16- or 32-bit audio, got %u-bit",
351 (unsigned) audio_stream_info.get_bits_per_sample());
352 return ESP_ERR_NOT_SUPPORTED;
353 }
354#endif // USE_ESP32_VARIANT_ESP32
355
356 if (!this->parent_->try_lock()) {
357 ESP_LOGE(TAG, "Parent bus is busy");
358 return ESP_ERR_INVALID_STATE;
359 }
360
361 uint32_t dma_buffer_length = dma_buffer_frames(audio_stream_info);
362
363 i2s_role_t i2s_role = this->i2s_role_;
364 i2s_clock_src_t clk_src = I2S_CLK_SRC_DEFAULT;
365
366#if SOC_CLK_APLL_SUPPORTED
367 if (this->use_apll_) {
368 clk_src = i2s_clock_src_t::I2S_CLK_SRC_APLL;
369 }
370#endif // SOC_CLK_APLL_SUPPORTED
371
372 // Log DMA configuration for debugging
373 ESP_LOGV(TAG, "I2S DMA config: %zu buffers x %lu frames", (size_t) DMA_BUFFERS_COUNT,
374 (unsigned long) dma_buffer_length);
375
376 i2s_chan_config_t chan_cfg = {
377 .id = this->parent_->get_port(),
378 .role = i2s_role,
379 .dma_desc_num = DMA_BUFFERS_COUNT,
380 .dma_frame_num = dma_buffer_length,
381 .auto_clear = true,
382 .intr_priority = 3,
383 };
384
385 // Build standard I2S clock/slot/gpio configuration
386 i2s_std_clk_config_t clk_cfg = {
387 .sample_rate_hz = audio_stream_info.get_sample_rate(),
388 .clk_src = clk_src,
389 .mclk_multiple = this->mclk_multiple_,
390 };
391
392 i2s_slot_mode_t slot_mode = this->slot_mode_;
393 i2s_std_slot_mask_t slot_mask = this->std_slot_mask_;
394 if (audio_stream_info.get_channels() == 1) {
395 slot_mode = I2S_SLOT_MODE_MONO;
396 } else if (audio_stream_info.get_channels() == 2) {
397 slot_mode = I2S_SLOT_MODE_STEREO;
398 slot_mask = I2S_STD_SLOT_BOTH;
399 }
400
401 i2s_std_slot_config_t slot_cfg;
402 switch (this->i2s_comm_fmt_) {
403 case I2SCommFmt::PCM:
404 slot_cfg =
405 I2S_STD_PCM_SLOT_DEFAULT_CONFIG((i2s_data_bit_width_t) audio_stream_info.get_bits_per_sample(), slot_mode);
406 break;
407 case I2SCommFmt::MSB:
408 slot_cfg =
409 I2S_STD_MSB_SLOT_DEFAULT_CONFIG((i2s_data_bit_width_t) audio_stream_info.get_bits_per_sample(), slot_mode);
410 break;
411 default:
412 slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG((i2s_data_bit_width_t) audio_stream_info.get_bits_per_sample(),
413 slot_mode);
414 break;
415 }
416
417#ifdef USE_ESP32_VARIANT_ESP32
418 // There seems to be a bug on the ESP32 (non-variant) platform where setting the slot bit width higher than the
419 // bits per sample causes the audio to play too fast. Setting the ws_width to the configured slot bit width seems
420 // to make it play at the correct speed while sending more bits per slot.
421 if (this->slot_bit_width_ != I2S_SLOT_BIT_WIDTH_AUTO) {
422 uint32_t configured_bit_width = static_cast<uint32_t>(this->slot_bit_width_);
423 slot_cfg.ws_width = configured_bit_width;
424 if (configured_bit_width > 16) {
425 slot_cfg.msb_right = false;
426 }
427 }
428#else
429 slot_cfg.slot_bit_width = this->slot_bit_width_;
430 if (this->slot_bit_width_ != I2S_SLOT_BIT_WIDTH_AUTO) {
431 slot_cfg.ws_width = static_cast<uint32_t>(this->slot_bit_width_);
432 }
433#endif // USE_ESP32_VARIANT_ESP32
434 slot_cfg.slot_mask = slot_mask;
435
436 i2s_std_gpio_config_t gpio_cfg = this->parent_->get_pin_config();
437 gpio_cfg.dout = this->dout_pin_;
438
439 i2s_std_config_t std_cfg = {
440 .clk_cfg = clk_cfg,
441 .slot_cfg = slot_cfg,
442 .gpio_cfg = gpio_cfg,
443 };
444
445 esp_err_t err = this->init_i2s_channel_(chan_cfg, std_cfg, I2S_EVENT_QUEUE_COUNT);
446 if (err != ESP_OK) {
447 return err;
448 }
449
450 // The speaker task will enable the channel after preloading.
451
452 return ESP_OK;
453}
454
455} // namespace esphome::i2s_audio
456
457#endif // USE_ESP32
An STL allocator that uses SPI or internal RAM.
Definition helpers.h:2053
void deallocate(T *p, size_t n)
Definition helpers.h:2110
T * allocate(size_t n)
Definition helpers.h:2080
size_t ms_to_bytes(uint32_t ms) const
Converts duration to bytes.
Definition audio.h:73
size_t frames_to_bytes(uint32_t frames) const
Converts frames to bytes.
Definition audio.h:53
uint8_t get_bits_per_sample() const
Definition audio.h:28
uint32_t frames_to_microseconds(uint32_t frames) const
Computes the duration, in microseconds, the given amount of frames represents.
Definition audio.cpp:25
uint32_t bytes_to_frames(size_t bytes) const
Convert bytes to frames.
Definition audio.h:43
uint8_t get_channels() const
Definition audio.h:29
uint32_t get_sample_rate() const
Definition audio.h:30
static std::unique_ptr< RingBufferAudioSource > create(std::shared_ptr< ring_buffer::RingBuffer > ring_buffer, size_t max_fill_bytes, uint8_t alignment_bytes=1)
Creates a new ring-buffer-backed audio source after validating its parameters.
i2s_std_slot_mask_t std_slot_mask_
Definition i2s_audio.h:28
i2s_slot_bit_width_t slot_bit_width_
Definition i2s_audio.h:29
i2s_mclk_multiple_t mclk_multiple_
Definition i2s_audio.h:32
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.
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_
void swap_esp32_mono_samples_(uint8_t *data, size_t bytes_read)
Swap adjacent 16-bit mono samples for ESP32 (non-variant) hardware quirk.
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.
esp_err_t start_i2s_driver(audio::AudioStreamInfo &audio_stream_info) override
static std::unique_ptr< RingBuffer > create(size_t len, MemoryPreference preference=MemoryPreference::EXTERNAL_FIRST)
CallbackManager< void(uint32_t, int64_t)> audio_output_callback_
Definition speaker.h:122
audio::AudioStreamInfo audio_stream_info_
Definition speaker.h:114
auto * new_data
Definition helpers.cpp:29
uint32_t IRAM_ATTR HOT millis()
Definition hal.cpp:28
static void uint32_t