I2S gap when reading data from SD card

dafengche
Posts: 2
Joined: Wed May 21, 2025 7:11 pm

I2S gap when reading data from SD card

Postby dafengche » Wed May 21, 2025 7:32 pm

Hi, I have a headache for several weeks now. I am trying to play a PCM file from a microSD card. So I created two tasks:
  • task_read_pcm_data running on core 1 - low priority
  • task_send_data_to_dac running on core 0 - high priority
And I created two buffers:
  • buf0 loads data from the SD card, while buf1 plays
  • buf1 loads data from the SD card, while buf0 plays
Since loading data from the SD card is faster than playing, when loading is finished wait until the current buffer play is finished.
I am able to play the PCM file using I2S. However, each time when fread() starts to load data from the SD card to a buffer, I will not be able to hear the DAC output for a small period. The audio will then resume - not from where it stops, but elapses during the no audio period.
I monitored the I2S DMA buffer and saw correct amount of data was sent out with the correct time interval.
When I loaded two buffers, then swapped them without reading data from the SD card, the sound did not have any gap.
Anyone had this issue before? Any suggestions?
Thank you in advance.
Tom

dafengche
Posts: 2
Joined: Wed May 21, 2025 7:11 pm

Re: I2S gap when reading data from SD card

Postby dafengche » Thu May 22, 2025 8:02 am

To add more information:
I'm on ESP32-S3 using ESP-IDF v5.4.1
In my task to send out data using I2S, I keep on sending out a sine wave. If I don't read SD card, I can hear it continuously. But whenever I read the SD card, the sound will be interrupted for a short period.
I have a SD card socket sitting on the same PCB with PCM5102A. The board was tested with Raspberry Pi Pico2 and it worked fine.

Who is online

Users browsing this forum: Applebot, meta-externalagent, PetalBot and 3 guests