-
Hello! I'm sorry, that I write to wrong topic, but in right topic there is no answer to me. I want to play mp3 from SD card on Pico. It may be possible with ESP8266audio library here, but I can't to do this. In existing examples (included in library) I can't see code for rp2040:
Can someone help me? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
I think the commenting out the example code for RP2040 is a relict. You can just build a MP3 to I2S from SD card player by combining https://github.com/earlephilhower/ESP8266Audio/blob/master/examples/PlayMP3FromSPIFFS/PlayMP3FromSPIFFS.ino and https://github.com/earlephilhower/ESP8266Audio/blob/master/examples/PlayFLAC-SD-SPDIF/PlayFLAC-SD-SPDIF.ino. I just tested that #include <Arduino.h>
#include "AudioFileSourceSD.h"
#include "AudioFileSourceID3.h"
#include "AudioGeneratorMP3.h"
#include "AudioOutputI2SNoDAC.h"
AudioGeneratorMP3 *mp3;
AudioFileSourceSD *file;
AudioOutputI2SNoDAC *out;
AudioFileSourceID3 *id3;
// Defines MISO, MOSI, SCLK, CS pins for SD card
#define SDCARD_SPI SPI
#define SDCARD_CS_PIN 10
// pno_cs.mp3 can be downloaded from https://ccrma.stanford.edu/~jos/pasp/Sound_Examples.html
// Called when a metadata event occurs (i.e. an ID3 tag, an ICY block, etc.
void MDCallback(void *cbData, const char *type, bool isUnicode, const char *string)
{
(void)cbData;
Serial.printf("ID3 callback for: %s = '", type);
if (isUnicode) {
string += 2;
}
while (*string) {
char a = *(string++);
if (isUnicode) {
string++;
}
Serial.printf("%c", a);
}
Serial.printf("'\n");
Serial.flush();
}
void setup()
{
Serial.begin(115200);
delay(1000);
SD.begin(SDCARD_CS_PIN, SDCARD_SPI);
Serial.printf("Sample MP3 playback begins...\n");
audioLogger = &Serial;
file = new AudioFileSourceSD("/pno-cs.mp3");
id3 = new AudioFileSourceID3(file);
id3->RegisterMetadataCB(MDCallback, (void*)"ID3TAG");
out = new AudioOutputI2SNoDAC();
mp3 = new AudioGeneratorMP3();
mp3->begin(id3, out);
}
void loop()
{
if (mp3->isRunning()) {
if (!mp3->loop()) mp3->stop();
} else {
Serial.printf("MP3 done\n");
delay(1000);
}
} compiles fine. Don't have an SD card or I2S DAC to test. I2S output is by default GPIO28 for data and GPIO26 for clock. |
Beta Was this translation helpful? Give feedback.
-
The code above doesn't work. Here's the working code. You need to solder a jumper on the PCM5102 module (shown in the photo) and power the module from 5 V. To avoid jerks during playback, you need to increase the SPI speed, as shown in the code. Also, use overclocking up to 200 MHz. Under these conditions, MP3 320 kbps Stereo is played.
|
Beta Was this translation helpful? Give feedback.
The code above doesn't work. Here's the working code. You need to solder a jumper on the PCM5102 module (shown in the photo) and power the module from 5 V. To avoid jerks during playback, you need to increase the SPI speed, as shown in the code. Also, use overclocking up to 200 MHz. Under these conditions, MP3 320 kbps Stereo is played.