ring_buffer-->i2s_stream-->[codec_chip]

Altivecer
Posts: 15
Joined: Thu May 05, 2022 10:55 pm

ring_buffer-->i2s_stream-->[codec_chip]

Postby Altivecer » Tue May 10, 2022 5:23 pm

Hi,

I'm looking for an example that creates a set of ring buffers in memory and then plays them through the i2s using the esp-adf libraries.
Once it starts playing, there would be a call-back to allow the program to refill the buffer.

The goal is to play a on-the-fly generated waveform
Like a signal generator or synthesizer.

I'm using a ESP32-LyraT-mini

Altivecer
Posts: 15
Joined: Thu May 05, 2022 10:55 pm

Re: ring_buffer-->i2s_stream-->[codec_chip]

Postby Altivecer » Fri May 20, 2022 4:54 pm

I figured it out.

I created a function static void fillBufferTask(void *para)
In it I write from my buffer into the ring buffer in a tight loop. The call to raw_stream_write blocks until it has transferred all the data. When it returns it swaps to the other buffer and start writing it.

while (bytesToSend > 0)
{
bytesToSend -= raw_stream_write(RB, (char *)buffer, bytesToSend);

if (bytesToSend > 0)
{
vTaskDelay(1);
ESP_LOGI(THREAD, "Delay");
}
}

The vTaskDelay is never called.

In the main program it is kicked off like this
xTaskCreate(fillBufferTask, "fill_buffer", 4096, raw_write, 1, NULL);


The pipeline is set up like this

ESP_LOGI(TAG, "[2.1] Create i2s stream to write data to codec chip and read data from codec chip");
i2s_stream_cfg_t i2s_cfg1 = I2S_STREAM_CFG_DEFAULT();
i2s_cfg1.type = AUDIO_STREAM_WRITER;
i2s_stream_writer = i2s_stream_init(&i2s_cfg1);

ESP_LOGI(TAG, "[2.2] Create raw write stream");
raw_stream_cfg_t raw_cfg = RAW_STREAM_CFG_DEFAULT();
raw_cfg.type = AUDIO_STREAM_WRITER;
raw_write = raw_stream_init(&raw_cfg);

ESP_LOGI(TAG, "[3.0] Register all elements to audio pipeline");
audio_pipeline_register(pipeline_d, raw_write, "raw_w");
audio_pipeline_register(pipeline_d, i2s_stream_writer, "i2s_w");

ESP_LOGI(TAG, "[3.1] Link it together raw_writer-->i2s_stream_writer-->[codec_chip]");
const char *link_d[2] = {"raw_w", "i2s_w"};
audio_pipeline_link(pipeline_d, &link_d[0], 2);

Who is online

Users browsing this forum: No registered users and 26 guests