97 lines
2.0 KiB
C++
97 lines
2.0 KiB
C++
#include <Arduino.h>
|
|
|
|
#include "AudioFileSourcePROGMEM.h"
|
|
#include <AudioFileSourceLittleFS.h>
|
|
//#include "AudioGeneratorWAV.h"
|
|
#include "AudioGeneratorMP3.h"
|
|
#include "AudioFileSourceID3.h"
|
|
#include "AudioOutputI2S.h"
|
|
|
|
#include "storage.h"
|
|
|
|
// VIOLA sample taken from https://ccrma.stanford.edu/~jos/pasp/Sound_Examples.html
|
|
#include "viola.h"
|
|
|
|
//AudioGeneratorWAV *wav;
|
|
AudioGeneratorMP3 *mp3;
|
|
AudioFileSourceID3 *id3;
|
|
|
|
AudioFileSourceLittleFS *file;
|
|
|
|
AudioOutputI2S *out;
|
|
|
|
const char *waveFile = "/003_short.mp3";
|
|
|
|
// 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();
|
|
}
|
|
|
|
// 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);
|
|
|
|
initStorage();
|
|
|
|
audioLogger = &Serial;
|
|
file = new AudioFileSourceLittleFS(waveFile);
|
|
id3 = new AudioFileSourceID3(file);
|
|
id3->RegisterMetadataCB(MDCallback, (void *)"ID3TAG");
|
|
|
|
mp3 = new AudioGeneratorMP3();
|
|
mp3->RegisterStatusCB(StatusCallback, (void*)"mp3");
|
|
|
|
out = new AudioOutputI2S();
|
|
out->SetPinout(21, 13, 14); //bclk, wclk, data
|
|
mp3->begin(id3, out);
|
|
out->SetGain(0.25);
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
if (mp3->isRunning())
|
|
{
|
|
if (!mp3->loop())
|
|
{
|
|
mp3->stop();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Serial.printf("sound done\n");
|
|
delay(1000);
|
|
}
|
|
}
|