ESP IDF 6.01 I2S API callback on chunk of data available

esp32.damiano
Posts: 36
Joined: Sat Aug 23, 2025 6:09 am

ESP IDF 6.01 I2S API callback on chunk of data available

Postby esp32.damiano » Sun Jun 28, 2026 6:10 pm

Good morning

A key requirement when dealing with AUDIO is the short and periodic handling of a chunk of audio data

a typical time loop has a value of 20ms and every time a chunk of audio data is read, then, task waiting for the data can be waken up and act upon it.

I can have this behaviour using a "waiter task" on i2s receive, reading using something like

Code: Select all

   int retcode = i2s_channel_read(esp_audio.rx_handleP, &i2s_chunk, sizeof(i2s_chunk), &bytes_read, 100);
it works, but there is a LOT of everhead, copying bytes around, for no reason at all

there is a callback mechanism available, but as far as I know/understand it is not possible to set it up so when a chunk of data is available the callback happens.

Code: Select all

    
    static bool i2s_rx_queue_overflow_callback(i2s_chan_handle_t handle, i2s_event_data_t *event, void *user_ctx)
	{
    wicounters.i2s_rx_queue_overflow_count++;
    return false;
	}

bool i2s_rx_queue_callback(i2s_chan_handle_t handle, i2s_event_data_t *event, void *user_ctx)
	{
    wicounters.i2s_rx_queue_cb_count++;
    return false;
	}

static const i2s_event_callbacks_t i2s_callback_cfg = {
    .on_recv = i2s_rx_queue_callback,
    .on_recv_q_ovf = i2s_rx_queue_overflow_callback,
    .on_sent = NULL,
    .on_send_q_ovf = NULL,
};
what is missing is to be able to request a callback only when a well defined number of bytes is available

am I mistaken ?

MicroController
Posts: 2673
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ESP IDF 6.01 I2S API callback on chunk of data available

Postby MicroController » Sun Jun 28, 2026 7:03 pm

The overhead for copying the data is negligible (use memcpy() for that). From a callback, you want to return as quickly as possible anyway, and the fastest way of "processing" data inside the callback is to just copy it elsewhere.

I2S operates on DMA buffers, and that's what you get in the callbacks, because the driver itself is only notified when a DMA buffer finishes.

esp32.damiano
Posts: 36
Joined: Sat Aug 23, 2025 6:09 am

Re: ESP IDF 6.01 I2S API callback on chunk of data available

Postby esp32.damiano » Mon Jun 29, 2026 2:46 pm

Please, read again the question I posted

I know I can be notified when "data is available", the question is "I wish to be notified when a well defined number of bytes are available"

so far, your answer is "no, you get called up on unknown amount of data"

Who is online

Users browsing this forum: Bing [Bot], Bytespider, PerplexityBot and 3 guests