"Double buffering" internal DAC DMA

globalsequence
Posts: 2
Joined: Sat Aug 24, 2024 9:18 pm

"Double buffering" internal DAC DMA

Postby globalsequence » Sat Aug 24, 2024 11:58 pm

Hello,

I am trying to write some code for audio processing purposes in the ESP32 IDF. My goal is to have the DMA running in a 'double buffer' configuration. In a double buffer configuration, the DMA reads from one buffer, while the second buffer of equal size is written to. Once the DMA transfer is complete, the DMA points to the first address of the newly filled buffer, and the previously read buffer is now the one being written to. As an audio application, the switching of the buffers would be seamless causing no audio artifacting.

Looking at the dac_audio_example_main file, I am having trouble understanding whether I should be using synchronous or asynchronous reading, for example, do the dac_event_callbacks apply to both synchronous and asynchronous reading? I am also having trouble understanding the 'desc_num' as it relates to 'buf_size' in the dac_continuous_config_t.

There is more about the internal DAC DMA that I am having trouble understanding, but I am afraid that the more granular that I make my questions, the more I might confuse what I'm trying to achieve so I will start there. Any help is appreciated. Thank you!

ESP_Sprite
Posts: 9724
Joined: Thu Nov 26, 2015 4:08 am

Re: "Double buffering" internal DAC DMA

Postby ESP_Sprite » Thu Aug 29, 2024 12:49 am

The DAC driver already does double-buffering (actually, you can set the number of buffers yourself) internal to the driver. Specifically, in that file

Code: Select all

        .desc_num = 4,
        .buf_size = 2048,
sets the buffering situation: in this case it sets up 4 2K buffers. Every time the DAC finishes reading a buffer, your application gets the chance to re-fill it; more than 2 buffers help in case the ESP32 is busy doing other high-prio things.

Async or sync mode depends on your applications requirements; from the drivers point of view it doesn't really make that much of a difference.

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 273 guests