Arduino library to play MOD, WAV, FLAC, MIDI, RTTTL, MP3, and AAC files on I2S DACs or with a software emulated delta-sigma DAC on the ESP8266 and ESP32
Hi all,
I am using this awesome library to stream internet radio on an ESP32-WROVER-IE (8MB) with a PCM5102A DAC to my stereo using a very simple sketch compiled in Arduino IDE (as proof of concept first.) Many of my favorite stations play well, however, I only hear "garbled sound snippets" on Jazz24, my all-time favorite :), via this link: 128k MP3: http://live.wostreaming.net/direct/ppm-jazz24mp3-ibc1
#include <Arduino.h>
#include <WiFi.h>
#include "AudioFileSourceICYStream.h"
#include "AudioFileSourceBuffer.h"
#include "AudioGeneratorMP3.h"
#include "AudioOutputI2S.h"
// Enter your WiFi setup here:
const char *SSID = "xxx";
const char *PASSWORD = "xxx";
//const char *URL="http://fm02-ice.stream.khz.se/fm02_mp3";
//const char *URL="http://stream.ffn.de/energybremen/mp3-192/;stream.nsv";
const char *URL="http://live.wostreaming.net/direct/ppm-jazz24mp3-ibc1";
AudioGeneratorMP3 *mp3;
AudioFileSourceICYStream *file;
AudioFileSourceBuffer *buff;
AudioOutputI2S *out;
// 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)
{
const char *ptr = reinterpret_cast<const char *>(cbData);
(void) isUnicode; // Punt this ball for now
// Note that the type and string may be in PROGMEM, so copy them to RAM for printf
char s1[32], s2[64];
strncpy_P(s1, type, sizeof(s1));
s1[sizeof(s1)-1]=0;
strncpy_P(s2, string, sizeof(s2));
s2[sizeof(s2)-1]=0;
Serial.printf("METADATA(%s) '%s' = '%s'\n", ptr, s1, s2);
Serial.flush();
}
// Called when there's a warning or error (like a buffer underflow or decode hiccup)
void StatusCallback(void *cbData, int code, const char *string)
{
const char *ptr = reinterpret_cast<const char *>(cbData);
// Note that the string may be in PROGMEM, so copy it to RAM for printf
char s1[64];
strncpy_P(s1, string, sizeof(s1));
s1[sizeof(s1)-1]=0;
Serial.printf("STATUS(%s) '%d' = '%s'\n", ptr, code, s1);
Serial.flush();
}
void setup()
{
Serial.begin(115200);
delay(1000);
Serial.println("Connecting to WiFi");
WiFi.disconnect();
WiFi.softAPdisconnect(true);
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, PASSWORD);
// Try forever
while (WiFi.status() != WL_CONNECTED) {
Serial.println("...Connecting to WiFi");
delay(1000);
}
Serial.println("Connected");
audioLogger = &Serial;
file = new AudioFileSourceICYStream(URL);
file->RegisterMetadataCB(MDCallback, (void*)"ICY");
buff = new AudioFileSourceBuffer(file, 65536); // playing with this value did not help Jazz24
buff->RegisterStatusCB(StatusCallback, (void*)"buffer");
out = new AudioOutputI2S();
out->SetGain(0.1);
out->SetPinout(27, 26, 25);
mp3 = new AudioGeneratorMP3();
mp3->RegisterStatusCB(StatusCallback, (void*)"mp3");
delay(1000); // Don't start and stop while filling first buffer
mp3->begin(buff, out);
}
void loop()
{
static int lastms = 0;
if (mp3->isRunning()) {
if (millis()-lastms > 10000) {
lastms = millis();
Serial.printf("Running for %d ms...\n", lastms);
Serial.flush();
}
if (!mp3->loop()) mp3->stop();
} else {
Serial.printf("MP3 done\n");
delay(1000);
}
}
Many thanks for any hint on how to solve this riddle.
Hi all, I am using this awesome library to stream internet radio on an ESP32-WROVER-IE (8MB) with a PCM5102A DAC to my stereo using a very simple sketch compiled in Arduino IDE (as proof of concept first.) Many of my favorite stations play well, however, I only hear "garbled sound snippets" on Jazz24, my all-time favorite :), via this link: 128k MP3: http://live.wostreaming.net/direct/ppm-jazz24mp3-ibc1
Here the error messages:
Here the sketch:
Many thanks for any hint on how to solve this riddle.
Daniel