Stuttering in I2S_write
Posted: Sun Apr 14, 2019 4:20 pm
Hello ESP32 team,
I have encountered an issue where there is a stuttering in the I2S_write. Here are the flow of the code:
1.) On init, I2S dma buffer length = 256*2, no. of buffers = 8, I2S 16 bits.
2.) In the main task, process 256 samples of buffer that takes around 2.217ms (timed it with a scope).
3.) i2s_write called with 256 samples of that buffer.
4.) Process 2 and 3 repeats again and again.
However, after 3 seconds, the audio stuttered badly, and watchdog tripped. When I measured the I2S transmitting buffer time, it takes about 5.804ms, which is more than the processing time.
In other microcontrollers I worked with, I used a double buffering mode where two identical buffers with 256 samples being exchanged everytime the DMA block transfer complete is being set. This one works even for the PIC32 and the K210. Here in the ESP32-IDF, I have no control over what I2S_write was doing. There are no semaphores or task-notify for a transfer complete, or anything else. Once it is being sent, I do not know whether if that particular sample has being pushed or not. What I have seen during the init was the I2S functions already started pushing data even when the buffers are empty.
Is there an example of the I2S DMA with the simple double-buffering method, or other suggestions on how to effectively use the I2S_write?
I have encountered an issue where there is a stuttering in the I2S_write. Here are the flow of the code:
1.) On init, I2S dma buffer length = 256*2, no. of buffers = 8, I2S 16 bits.
2.) In the main task, process 256 samples of buffer that takes around 2.217ms (timed it with a scope).
3.) i2s_write called with 256 samples of that buffer.
4.) Process 2 and 3 repeats again and again.
However, after 3 seconds, the audio stuttered badly, and watchdog tripped. When I measured the I2S transmitting buffer time, it takes about 5.804ms, which is more than the processing time.
In other microcontrollers I worked with, I used a double buffering mode where two identical buffers with 256 samples being exchanged everytime the DMA block transfer complete is being set. This one works even for the PIC32 and the K210. Here in the ESP32-IDF, I have no control over what I2S_write was doing. There are no semaphores or task-notify for a transfer complete, or anything else. Once it is being sent, I do not know whether if that particular sample has being pushed or not. What I have seen during the init was the I2S functions already started pushing data even when the buffers are empty.
Is there an example of the I2S DMA with the simple double-buffering method, or other suggestions on how to effectively use the I2S_write?