Open Hema2-official opened 2 years ago
Here is an example to use ULP on ESP32. The DAC pins are GPIO25 and GPIO26.
If it doesn't work: see https://github.com/earlephilhower/ESP8266Audio/pull/579
#include <WiFi.h>
#include "driver/i2s.h"
#include "AudioFileSourceICYStream.h"
#include "AudioFileSourceBuffer.h"
#include "AudioGeneratorMP3.h"
#include "AudioOutputULP.h"
const char* ssid = "your-ssid";
const char* password = "your-password";
const char *URL = "http://icecast.vrtcdn.be/stubru-high.mp3";
AudioGeneratorMP3 *mp3;
AudioFileSourceICYStream *file;
AudioFileSourceBuffer *buff;
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();
}
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);
// Blijf proberen
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, 2048);
buff->RegisterStatusCB(StatusCallback, (void*)"buffer");
AudioOutput *out = new AudioOutputULP(3); // 1=DAC1; 2=DAC2; 3=DAC1 + DAC2
out->SetGain(0.10); // regel het volume
out->SetRate(44100);
out->begin();
mp3 = new AudioGeneratorMP3();
mp3->RegisterStatusCB(StatusCallback, (void*)"mp3");
mp3->begin(buff, out);
}
void loop()
{
static int lastms = 0;
if (mp3->isRunning()) {
if (millis() - lastms > 1000) {
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);
dacWrite(25, 0);
}
}
Hey!
Long story short: No matter how I try to init the ULP driver, it always drops some compilation errors. (related with the AudioOutputULP class ofc) I need a working example with it... Please gimme one! Until then, I'm stuck with the I2S output....
Thanks! ^^
Edit: I tried using the instructions written in AudioOutputULP.h, too.