Move strings to PROGMEM, save a few heap bytes

This commit is contained in:
Earle F. Philhower, III committed 2017-12-14 10:50:55 -08:00
1 parent ee7febe1ec
commit 8d401a4a39
7 files changed
+32 -35

No files matched your search

+4 -4
View File
@@ -36,7 +36,7 @@ AudioFileSourceSPIRAMBuffer::AudioFileSourceSPIRAMBuffer(AudioFileSource *source
length = 0;
filled = false;
bytesAvailable = 0;
Serial.printf("SPI RAM buffer size: %u Bytes\n", ramSize);
Serial.printf_P(PSTR("SPI RAM buffer size: %u Bytes\n"), ramSize);
}
AudioFileSourceSPIRAMBuffer::~AudioFileSourceSPIRAMBuffer()
@@ -81,7 +81,7 @@ uint32_t AudioFileSourceSPIRAMBuffer::read(void *data, uint32_t len)
writePtr = readPtr = 0;
uint16_t toRead = sizeof(buffer);
// Fill up completely before returning any data at all
Serial.println("Buffering...");
Serial.printf_P(PSTR("Buffering...\n"));
while (bytesAvailable!=ramSize) {
length = src->read(buffer, toRead);
if(length>0) {
@@ -95,7 +95,7 @@ uint32_t AudioFileSourceSPIRAMBuffer::read(void *data, uint32_t len)
}
writePtr = bytesAvailable % ramSize;
filled = true;
Serial.println("Filling Done !");
Serial.printf_P(PSTR("Filling Done !\n"));
}
// Serial.printf("Buffer: %u%\n", bytesAvailable*100/ramSize);
@@ -139,7 +139,7 @@ void AudioFileSourceSPIRAMBuffer::fill()
bytesAvailable+=cnt;
writePtr = (writePtr + cnt) % ramSize;
#ifdef SPIBUF_DEBUG
Serial.printf("SockRead: %u | RamAvail: %u\n", cnt, bytesAvailable);
Serial.printf_P(PSTR("SockRead: %u | RamAvail: %u\n"), cnt, bytesAvailable);
#endif
}
return;
+4 -1
View File
@@ -28,7 +28,10 @@ AudioGeneratorAAC::AudioGeneratorAAC()
file = NULL;
output = NULL;
hAACDecoder = AACInitDecoder();
if (!hAACDecoder) { Serial.println("Out of memory error! hAACDecoder==NULL"); Serial.flush(); }
if (!hAACDecoder) {
Serial.printf_P(PSTR("Out of memory error! hAACDecoder==NULL\n"));
Serial.flush();
}
// For sanity's sake...
memset(buff, 0, sizeof(buff));
memset(outSample, 0, sizeof(outSample));
+1 -1
View File
@@ -186,7 +186,7 @@ void AudioGeneratorFLAC::metadata_cb(const FLAC__StreamDecoder *decoder, const F
{
(void) decoder;
(void) metadata;
Serial.printf("Metadata\n");
Serial.printf_P(PSTR("Metadata\n"));
}
void AudioGeneratorFLAC::error_cb(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
{
+18 -11
View File
@@ -98,7 +98,7 @@ enum mad_flow AudioGeneratorMP3::Input()
int len = buffLen - unused;
len = file->read(buff + unused, len);
if (len == 0) {
Serial.println("MP3 stop, len==0");
Serial.printf_P(PSTR("MP3 stop, len==0\n"));
return MAD_FLOW_STOP;
}
@@ -121,7 +121,7 @@ bool AudioGeneratorMP3::DecodeNextFrame()
return true;
}
} while (stream.error == MAD_ERROR_BUFLEN);
Serial.println("stream.error != mad_Err_bufflen");
Serial.printf_P(PSTR("stream.error != mad_Err_bufflen\n"));
return false;
}
@@ -146,7 +146,7 @@ bool AudioGeneratorMP3::GetOneSample(int16_t sample[2])
switch ( mad_synth_frame_onens(&synth, &frame, nsCount++) ) {
case MAD_FLOW_STOP:
case MAD_FLOW_BREAK: Serial.println("msf1ns failed\n");
case MAD_FLOW_BREAK: Serial.printf_P(PSTR("msf1ns failed\n"));
return false; // Either way we're done
default:
break; // Do nothing
@@ -177,7 +177,7 @@ bool AudioGeneratorMP3::loop()
}
if (!DecodeNextFrame()) {
Serial.println("DNF failed");
Serial.printf_P(PSTR("DNF failed\n"));
return false;
}
samplePtr = 9999;
@@ -185,7 +185,7 @@ bool AudioGeneratorMP3::loop()
}
if (!GetOneSample(lastSample)) {
Serial.println("G1S failed\n");
Serial.printf_P(PSTR("G1S failed\n"));
running = false;
goto done;
}
@@ -207,7 +207,7 @@ bool AudioGeneratorMP3::begin(AudioFileSource *source, AudioOutput *output)
if (!output) return false;
this->output = output;
if (!file->isOpen()) {
Serial.printf("MP3 source file not open\n");
Serial.printf_P(PSTR("MP3 source file not open\n"));
return false; // Error
}
if (!output->begin()) return false;
@@ -249,11 +249,18 @@ extern "C" {
int freeheap = ESP.getFreeHeap();
if ((freestack < 512) || (freeheap < 5120)) {
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;
if (laststack!=freestack|| lastheap !=freeheap) {
Serial.printf_P(PSTR("%s: FREESTACK=%d, FREEHEAP=%d\n"), s, /*t, i,*/ freestack, /*cont_get_free_stack(&g_cont),*/ freeheap);
}
if (freestack < 256) {
Serial.printf_P(PSTR("out of stack!\n"));
}
if (freeheap < 1024) {
Serial.printf_P(PSTR("out of heap!\n"));
}
Serial.flush();
laststack=freestack;
lastheap=freeheap;
}
}
+4 -1
View File
@@ -29,7 +29,10 @@ AudioGeneratorMP3a::AudioGeneratorMP3a()
file = NULL;
output = NULL;
hMP3Decoder = MP3InitDecoder();
if (!hMP3Decoder) { Serial.println("Out of memory error! hMP3Decoder==NULL"); Serial.flush(); }
if (!hMP3Decoder) {
Serial.printf_P(PSTR("Out of memory error! hMP3Decoder==NULL\n"));
Serial.flush();
}
// For sanity's sake...
memset(buff, 0, sizeof(buff));
memset(outSample, 0, sizeof(outSample));
+1 -1
View File
@@ -67,7 +67,7 @@ bool AudioOutputSerialWAV::ConsumeSample(int16_t sample[2])
bool AudioOutputSerialWAV::stop()
{
Serial.print("\n\n\nEOF\n\n\n");
Serial.printf_P(PSTR("\n\n\nEOF\n\n\n"));
return true;
}
-16
View File
@@ -1,16 +0,0 @@
#if !defined(DEBUG_h)
#include <core_pins.h>
#include <HardwareSerial.h>
#define DBG Serial2
//#define DBG_SERIAL Serial
#define DBG_BAUD 115200
void initDBG();
#define DEBUG_h
#endif