WAV files from SD card with I2S codec (reading/switching 2 files is a problem)

nicolas_soundforce
Posts: 1
Joined: Tue Jun 12, 2018 7:03 pm

WAV files from SD card with I2S codec (reading/switching 2 files is a problem)

Postby nicolas_soundforce » Tue Jun 12, 2018 7:38 pm

Hi There,

first post! My name is Nicolas, I am from Holland and I make electronic music projects. I love the ESP32 it's great, I am using it since a couple of projects now. You can really squeeze a lot of processing.

I picked up my old project of making a wav sample player, from an sd card. I want to playback 2 audio files independently, one on the left channel and one on the right channel. It works 50%...

What works :
- I can open wav files and detect when the audio data is starting
- I can playback the audio bytes through the I2S DAC (PCM5102) and it sounds great
- I can read one file and send either on both channels or only the right/only the left
- I can start and rewind the audio using GPIO interrupt and a button on my dev board

What does not work:
- As soon as I try to read 2 audio files in the loop or somewhere else, the audio becomes distorted, glitchy and terrible...

What have I tried already:
- I tried using 2 cores, Core1 (loop) for i2s playback, Core0 for reading the sd card. Watchdog was triggering on Core0, vTaskDelay helped but introduced glitches. In the end same problem when reading 2 files.
- I tried using buffers, loading 512 bytes of audio in 1 read, even buffering the 2 files not at the same time. Issue still present.
- I tried 3 different SD and FS library, the one from .iotsharing.com, the one from the Arduino Core (that one was too slow for playback of 1 file) and lately SdFat

I attached my code, notice how I commented out all the file2.read(), as soon I include it in the code, the audio goes bad. If I read file1 twice in the loop, the audio sounds weird but is not distorted as with file2.read. So I am guessing it is a problem to switch between files fast enough.

But why do I get the same results using different libraries ?

I am out of ideas...
Attachments
ESP32_SD_v1.7_for_forum.zip
(4.88 KiB) Downloaded 727 times

jerome
Posts: 37
Joined: Wed Jan 23, 2019 2:28 pm

Re: WAV files from SD card with I2S codec (reading/switching 2 files is a problem)

Postby jerome » Wed Mar 06, 2019 2:49 pm

Hi
I'm facing a similar issue and was wondering if you succeeded in solving this ?
Thanks for any tips
Jerome

Who is online

Users browsing this forum: No registered users and 56 guests