Page 1 of 1

ESP IDF 6.01 I2S API callback on chunk of data available

Posted: Sun Jun 28, 2026 6:10 pm
by esp32.damiano
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 ?

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

Posted: Sun Jun 28, 2026 7:03 pm
by MicroController
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.

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

Posted: Mon Jun 29, 2026 2:46 pm
by esp32.damiano
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"