MP3 comes in chunks of encoded data started by a header sequence. Scan for it in the decoder and only pass in data that starts with this header to avoid the burst errors Avoids a avalanche of `lost synchronization` error reports when there is a file error. Also enable additional sketches on the RP2040/RP2350
54 lines
1.1 KiB
Arduino
54 lines
1.1 KiB
Arduino
#if (defined(ESP32) && (__GNUC__ >= 8) && (__XTENSA__))
|
|
// GCC compiler bug for the Xtensa ESP32s, no MIDI for you. :(
|
|
void setup() {}
|
|
void loop() {}
|
|
#else
|
|
#include <Arduino.h>
|
|
#ifdef ESP8266
|
|
#include <ESP8266WiFi.h>
|
|
#else
|
|
#include <WiFi.h>
|
|
#endif
|
|
#include <AudioOutputI2S.h>
|
|
#include <AudioGeneratorMIDI.h>
|
|
#include <AudioFileSourceLittleFS.h>
|
|
|
|
AudioFileSourceLittleFS *sf2;
|
|
AudioFileSourceLittleFS *mid;
|
|
AudioOutputI2S *dac;
|
|
AudioGeneratorMIDI *midi;
|
|
|
|
void setup() {
|
|
const char *soundfont = "/1mgm.sf2";
|
|
const char *midifile = "/furelise.mid";
|
|
|
|
WiFi.mode(WIFI_OFF);
|
|
|
|
Serial.begin(115200);
|
|
Serial.println("Starting up...\n");
|
|
|
|
audioLogger = &Serial;
|
|
sf2 = new AudioFileSourceLittleFS(soundfont);
|
|
mid = new AudioFileSourceLittleFS(midifile);
|
|
|
|
dac = new AudioOutputI2S();
|
|
midi = new AudioGeneratorMIDI();
|
|
midi->SetSoundfont(sf2);
|
|
midi->SetSampleRate(22050);
|
|
Serial.printf("BEGIN...\n");
|
|
midi->begin(mid, dac);
|
|
}
|
|
|
|
void loop() {
|
|
if (midi->isRunning()) {
|
|
if (!midi->loop()) {
|
|
midi->stop();
|
|
}
|
|
} else {
|
|
Serial.printf("MIDI done\n");
|
|
delay(1000);
|
|
}
|
|
}
|
|
|
|
#endif
|