update game
This commit is contained in:
@@ -6,7 +6,7 @@ AudioFileSourceLittleFS *file;
|
||||
AudioOutputI2S *out;
|
||||
|
||||
uint8_t audio_current_Song = 0;
|
||||
const char* nextAudioFile = "";
|
||||
const char *nextAudioFile = "";
|
||||
uint8_t n = 0;
|
||||
|
||||
bool audioState = false;
|
||||
@@ -21,8 +21,28 @@ const char *waveFile[] =
|
||||
// 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;
|
||||
// log_i("ID3 callback for: %s = '", type);
|
||||
|
||||
(void)cbData;
|
||||
log_i("ID3 callback for: %s = '", type);
|
||||
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)
|
||||
@@ -36,52 +56,54 @@ void StatusCallback(void *cbData, int code, const char *string)
|
||||
log_i("STATUS(%s) '%d' = '%s'\n", ptr, code, s1);
|
||||
}
|
||||
|
||||
void playSong(uint8_t index)
|
||||
{
|
||||
if (index > AUDIONSONGS)
|
||||
return;
|
||||
log_i("now playing %s\n", waveFile[index]);
|
||||
file = new AudioFileSourceLittleFS(waveFile[index]);
|
||||
id3 = new AudioFileSourceID3(file);
|
||||
id3->RegisterMetadataCB(MDCallback, (void *)"ID3TAG");
|
||||
mp3->begin(id3, out);
|
||||
}
|
||||
// void playSong(uint8_t index)
|
||||
// {
|
||||
// if (index > AUDIONSONGS)
|
||||
// return;
|
||||
// log_i("now playing %s\n", waveFile[index]);
|
||||
// file = new AudioFileSourceLittleFS(waveFile[index]);
|
||||
// id3 = new AudioFileSourceID3(file);
|
||||
// id3->RegisterMetadataCB(MDCallback, (void *)"ID3TAG");
|
||||
// mp3->RegisterStatusCB(StatusCallback, (void *)"mp3");
|
||||
// mp3->begin(id3, out);
|
||||
// }
|
||||
|
||||
void playSong(String filename)
|
||||
{
|
||||
if(filename != "")
|
||||
if (filename != "")
|
||||
{
|
||||
log_i("now playing %s\n", filename.c_str());
|
||||
file = new AudioFileSourceLittleFS(filename.c_str());
|
||||
id3 = new AudioFileSourceID3(file);
|
||||
id3->RegisterMetadataCB(MDCallback, (void *)"ID3TAG");
|
||||
mp3->RegisterStatusCB(StatusCallback, (void *)"mp3");
|
||||
mp3->begin(id3, out);
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
log_e("no filenae specified");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void initAudio()
|
||||
{
|
||||
log_i("init Audio");
|
||||
audioLogger = &Serial;
|
||||
delay(500);
|
||||
out = new AudioOutputI2S();
|
||||
out->SetPinout(I2S_BCLK, I2S_WCLK, I2S_DATA); //bclk, wclk, data
|
||||
out->SetPinout(I2S_BCLK, I2S_WCLK, I2S_DATA); // bclk, wclk, data
|
||||
out->SetGain(AUDIOGAIN);
|
||||
|
||||
mp3 = new AudioGeneratorMP3();
|
||||
mp3->RegisterStatusCB(StatusCallback, (void *)"mp3");
|
||||
audioInitOk = true;
|
||||
log_i("init Audio Done");
|
||||
//playSong(audio_current_Song);
|
||||
playSong("/Billy-Jean.mp3");
|
||||
}
|
||||
|
||||
void setAudioState(bool state)
|
||||
{
|
||||
audioState = state;
|
||||
log_i("set Audio state %d", state);
|
||||
}
|
||||
|
||||
bool getAudioState(void)
|
||||
@@ -111,6 +133,7 @@ void handleAudio()
|
||||
if (!mp3->loop())
|
||||
{
|
||||
mp3->stop();
|
||||
log_w("Audio: loop");
|
||||
playSong(audio_current_Song);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user