From 634d0b8d025ae090ef704e7b4bda0f37fdb52c1d Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Fri, 15 Dec 2017 10:31:19 -0800 Subject: [PATCH] Store AAC/MP3 flag in EEPROM for WebRadio --- examples/WebRadio/WebRadio.ino | 8 +++++--- src/AudioFileSourceBuffer.cpp | 1 + src/AudioGeneratorMP3.cpp | 7 ++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/WebRadio/WebRadio.ino b/examples/WebRadio/WebRadio.ino index 701bc5b..d13f0d3 100644 --- a/examples/WebRadio/WebRadio.ino +++ b/examples/WebRadio/WebRadio.ino @@ -52,6 +52,7 @@ bool isAAC = false; typedef struct { char url[64]; + bool isAAC; int16_t checksum; } Settings; @@ -282,6 +283,7 @@ void setup() if (s.checksum == sum) { strcpy(url, s.url); + isAAC = s.isAAC; Serial.printf_P(PSTR("Resuming stream from EEPROM: %s"), url); newUrl = true; } @@ -298,6 +300,7 @@ void StartNewURL() // Store in "EEPROM" to restart automatically Settings s; strcpy(s.url, url); + s.isAAC = isAAC; s.checksum = 0x1234; for (size_t i=0; i(&s); @@ -310,7 +313,7 @@ void StartNewURL() file = new AudioFileSourceICYStream(url); file->RegisterMetadataCB(MDCallback, NULL); - buff = new AudioFileSourceBuffer(file, 1500); + buff = new AudioFileSourceBuffer(file, 4096); buff->RegisterStatusCB(StatusCallback, NULL); out = new AudioOutputI2SDAC(); decoder = isAAC ? (AudioGenerator*) new AudioGeneratorAAC() : (AudioGenerator*) new AudioGeneratorMP3(); @@ -335,7 +338,6 @@ void loop() { static int lastms = 0; static int retryms = 0; - if (millis()-lastms > 1000) { lastms = millis(); Serial.printf_P(PSTR("Running for %d seconds...Free mem=%d\n"), lastms/1000, ESP.getFreeHeap()); @@ -345,7 +347,7 @@ void loop() retryms = 0; newUrl = true; } - + if (newUrl) { StartNewURL(); } diff --git a/src/AudioFileSourceBuffer.cpp b/src/AudioFileSourceBuffer.cpp index a2d9008..92f7d04 100644 --- a/src/AudioFileSourceBuffer.cpp +++ b/src/AudioFileSourceBuffer.cpp @@ -27,6 +27,7 @@ AudioFileSourceBuffer::AudioFileSourceBuffer(AudioFileSource *source, int buffSi { buffSize = buffSizeBytes; buffer = (uint8_t*)malloc(sizeof(uint8_t) * buffSize); + if (!buffer) Serial.printf_P("Unable to allocate AudioFileSourceBuffer::buffer[]\n"); writePtr = 0; readPtr = 0; src = source; diff --git a/src/AudioGeneratorMP3.cpp b/src/AudioGeneratorMP3.cpp index d82c4db..2ad073e 100644 --- a/src/AudioGeneratorMP3.cpp +++ b/src/AudioGeneratorMP3.cpp @@ -241,7 +241,8 @@ extern "C" { #include extern cont_t g_cont; - void stack(const char *s, const char *t, int i) { + void stack(const char *s, const char *t, int i) + { (void) t; (void) i; register uint32_t *sp asm("a1"); @@ -259,8 +260,8 @@ extern "C" { Serial.printf_P(PSTR("out of heap!\n")); } Serial.flush(); - laststack=freestack; - lastheap=freeheap; + laststack = freestack; + lastheap = freeheap; } }