From 2737dec473613dba97141348b9afc166c0ddc6d7 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Tue, 21 Nov 2017 20:09:37 -0800 Subject: [PATCH] Fix block corruption when hitting an ICY block Wasn't incrementing the returned data pointer when we had to split the requested read into pre- and post-ICY blocks. This resulted in errors in the decoded stream. --- src/AudioFileSourceICYStream.cpp | 37 +++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/AudioFileSourceICYStream.cpp b/src/AudioFileSourceICYStream.cpp index f5efe7c..9a82865 100644 --- a/src/AudioFileSourceICYStream.cpp +++ b/src/AudioFileSourceICYStream.cpp @@ -107,16 +107,23 @@ uint32_t AudioFileSourceICYStream::readInternal(void *data, uint32_t len, bool n read += ret; pos += ret; len -= ret; + data = (void *)(reinterpret_cast(data) + ret); icyByteCount += ret; + if (ret != beforeIcy) return read; // Partial read + uint8_t mdSize; int mdret = stream->readBytes(&mdSize, 1); if ((mdret == 1) && (mdSize > 0)) { - char *mdBuff = (char*)malloc(mdSize * 16); - mdret = stream->readBytes(reinterpret_cast(mdBuff), mdSize * 16); - if (mdret == mdSize * 16) { - Serial.printf("ICY metadata:\n%s\n---end---\n", mdBuff); - free(mdBuff); + char mdBuff[17]; + mdBuff[16] = 0; + Serial.print("ICY MD: "); + for (int i=0; ireadBytes(reinterpret_cast(mdBuff), 16); + if (mdret == 16) { + Serial.printf("%s", mdBuff); + } } + Serial.println("\n---end---"); } icyByteCount = 0; } @@ -127,4 +134,24 @@ uint32_t AudioFileSourceICYStream::readInternal(void *data, uint32_t len, bool n icyByteCount += ret; return read; } +extern "C" { +void flush() { Serial.flush(); } +extern "C" { + #include + extern cont_t g_cont; + void stack(const char *s, const char *t, int i) { + (void) t; + (void) i; + register uint32_t *sp asm("a1"); + int freestack = 4 * (sp - g_cont.stack); + int freeheap = ESP.getFreeHeap(); + static int laststack, lastheap; + if (laststack!=freestack|| lastheap !=freeheap) + Serial.printf("%s: FREESTACK=%d, FREEHEAP=%d\n", s, /*t, i,*/ freestack, /*cont_get_free_stack(&g_cont),*/ freeheap); Serial.flush(); + if (freestack < 256) {Serial.printf("out of stack!\n"); while (1); } + if (freeheap < 1024) {Serial.printf("out of heap!\n"); while (1); } + laststack=freestack;lastheap=freeheap; + } +} +};