Browse Source

add decoder polymorphism

main
Hendrik Langer 7 years ago
parent
commit
5d10493dba
  1. 20
      src/mp3.cpp
  2. 2
      src/mp3.h

20
src/mp3.cpp

@ -57,6 +57,7 @@ void MP3::start() {
} }
void MP3::mp3_decoder_task(void *pvParameters) { void MP3::mp3_decoder_task(void *pvParameters) {
strcpy(titleStr, "...");
file = new AudioFileSourceICYStream(URL); file = new AudioFileSourceICYStream(URL);
file->RegisterMetadataCB(MDCallback, (void*)"ICY"); file->RegisterMetadataCB(MDCallback, (void*)"ICY");
buff = new AudioFileSourceBuffer(file, preallocateBuffer, preallocateBufferSize); buff = new AudioFileSourceBuffer(file, preallocateBuffer, preallocateBufferSize);
@ -65,31 +66,32 @@ void MP3::mp3_decoder_task(void *pvParameters) {
out = new AudioOutputI2S(I2S_NUM_0, false, 0); out = new AudioOutputI2S(I2S_NUM_0, false, 0);
out->SetPinout(12, 13, 25); out->SetPinout(12, 13, 25);
} }
mp3 = new AudioGeneratorMP3(); decoder = new AudioGeneratorMP3();
mp3->RegisterStatusCB(StatusCallback, (void*)"mp3"); decoder->RegisterStatusCB(StatusCallback, (void*)"mp3");
mp3->begin(buff, out); decoder->begin(buff, out);
out->SetGain(1.0); out->SetGain(1.0);
playing = true; playing = true;
while(mp3->isRunning()) { while(decoder->isRunning()) {
if (millis()-lastms > 1000) { if (millis()-lastms > 1000) {
lastms = millis(); lastms = millis();
Serial.printf("Running for %d ms...\n", lastms); Serial.printf("Running for %d ms...\n", lastms);
Serial.flush(); Serial.flush();
} }
if (!mp3->loop()) break; if (!decoder->loop()) break;
if (!playing) break; if (!playing) break;
vTaskDelay(5 / portTICK_PERIOD_MS); vTaskDelay(5 / portTICK_PERIOD_MS);
} }
Serial.printf("MP3 done\n"); Serial.printf("MP3 done\n");
strcpy(titleStr, "___");
playing = false; playing = false;
if (mp3) { if (decoder) {
mp3->stop(); decoder->stop();
delete mp3; delete decoder;
mp3 = NULL; decoder = NULL;
} }
if (buff) { if (buff) {
buff->close(); buff->close();

2
src/mp3.h

@ -22,7 +22,7 @@ class MP3 {
void start(void); void start(void);
bool playing = false; bool playing = false;
private: private:
AudioGeneratorMP3 *mp3; AudioGenerator *decoder;
AudioFileSourceICYStream *file; AudioFileSourceICYStream *file;
AudioFileSourceBuffer *buff; AudioFileSourceBuffer *buff;
AudioOutputI2S *out; AudioOutputI2S *out;

Loading…
Cancel
Save