ESP32-audioI2S icon indicating copy to clipboard operation
ESP32-audioI2S copied to clipboard

Seamless Audio Playback with ESP32 and PCM5102

Open 48mert opened this issue 1 year ago • 0 comments

Subject: Seeking Assistance for Seamless Audio Playback with ESP32 and PCM5102

Hello everyone,

I'm currently working on a project using an ESP32 with a PCM5102 DAC, where I'm attempting to play back individual piano notes stored as MP3 files on an SD card/SPIFFS. My aim is to achieve seamless playback between notes, with minimal silence when transitioning from one note to the next. Despite my efforts, I'm experiencing a noticeable gap between the notes. My Code may not be efficient, sorry for that.

Here's my code:

`#include "Arduino.h" #include "Audio.h" #include "SD.h" #include "FS.h"

// Digital I/O used #define SD_CS 5 #define SPI_MOSI 23 // SD Card #define SPI_MISO 19 #define SPI_SCK 18

#define I2S_DOUT 25 #define I2S_BCLK 27 // I2S #define I2S_LRC 26

Audio audio;

String noten[] = {"/B6.mp3", "/Gs6.mp3", "/G6.mp3", "/F6.mp3", "/E6.mp3", "/Cs6.mp3", "/C6.mp3"}; int noteIndex = 0;

void melodie(unsigned long *rand_melodie) { for (int i = 0; i < 5; i++) { rand_melodie[i] = random(0, 7); Serial.println(rand_melodie[i]); } } void setup() { Serial.begin(115200);

if (!SD.begin(SD_CS)) { Serial.println("Error talking to SD card!"); return; }

pinMode(SD_CS, OUTPUT); digitalWrite(SD_CS, HIGH); SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI); audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT); audio.setVolume(21);

unsigned long rand_melodie[5]; melodie(rand_melodie);

audio.connecttoFS(SD, noten[noteIndex].c_str()); }

void audio_eof_mp3(const char *info) {

Serial.print("eof_mp3 "); Serial.println(info);

noteIndex++; // Gehe zur nächsten Note über if (noteIndex >= sizeof(noten) / sizeof(noten[0])) { noteIndex = 0; } audio.connecttoFS(SD, noten[noteIndex].c_str());

}

void loop() { audio.loop(); }

`

48mert avatar Dec 17 '23 21:12 48mert