install and use a global audioLogger instead of Serial (#198)
* use of global audioLogger-> instead of Serial. * default to silence * initialize logger in examples
This commit is contained in:
1 parent
598163dd59
commit
4fed6a230f
25 files changed
+74
-31
No files matched your search
@@ -27,7 +27,7 @@ AudioFileSourceBuffer::AudioFileSourceBuffer(AudioFileSource *source, uint32_t b
|
||||
{
|
||||
buffSize = buffSizeBytes;
|
||||
buffer = (uint8_t*)malloc(sizeof(uint8_t) * buffSize);
|
||||
if (!buffer) Serial.printf_P(PSTR("Unable to allocate AudioFileSourceBuffer::buffer[]\n"));
|
||||
if (!buffer) audioLogger->printf_P(PSTR("Unable to allocate AudioFileSourceBuffer::buffer[]\n"));
|
||||
deallocateBuffer = true;
|
||||
writePtr = 0;
|
||||
readPtr = 0;
|
||||
|
||||
@@ -59,7 +59,7 @@ AudioFileSourceHTTPStream::~AudioFileSourceHTTPStream()
|
||||
uint32_t AudioFileSourceHTTPStream::read(void *data, uint32_t len)
|
||||
{
|
||||
if (data==NULL) {
|
||||
Serial.printf_P(PSTR("ERROR! AudioFileSourceHTTPStream::read passed NULL data\n"));
|
||||
audioLogger->printf_P(PSTR("ERROR! AudioFileSourceHTTPStream::read passed NULL data\n"));
|
||||
return 0;
|
||||
}
|
||||
return readInternal(data, len, false);
|
||||
@@ -68,7 +68,7 @@ uint32_t AudioFileSourceHTTPStream::read(void *data, uint32_t len)
|
||||
uint32_t AudioFileSourceHTTPStream::readNonBlock(void *data, uint32_t len)
|
||||
{
|
||||
if (data==NULL) {
|
||||
Serial.printf_P(PSTR("ERROR! AudioFileSourceHTTPStream::readNonBlock passed NULL data\n"));
|
||||
audioLogger->printf_P(PSTR("ERROR! AudioFileSourceHTTPStream::readNonBlock passed NULL data\n"));
|
||||
return 0;
|
||||
}
|
||||
return readInternal(data, len, true);
|
||||
|
||||
@@ -36,7 +36,7 @@ AudioFileSourceSPIRAMBuffer::AudioFileSourceSPIRAMBuffer(AudioFileSource *source
|
||||
length = 0;
|
||||
filled = false;
|
||||
bytesAvailable = 0;
|
||||
Serial.printf_P(PSTR("SPI RAM buffer size: %u Bytes\n"), ramSize);
|
||||
audioLogger->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.printf_P(PSTR("Buffering...\n"));
|
||||
audioLogger->printf_P(PSTR("Buffering...\n"));
|
||||
while (bytesAvailable!=ramSize) {
|
||||
length = src->read(buffer, toRead);
|
||||
if(length>0) {
|
||||
@@ -98,10 +98,10 @@ uint32_t AudioFileSourceSPIRAMBuffer::read(void *data, uint32_t len)
|
||||
}
|
||||
writePtr = bytesAvailable % ramSize;
|
||||
filled = true;
|
||||
Serial.printf_P(PSTR("Filling Done !\n"));
|
||||
audioLogger->printf_P(PSTR("Filling Done !\n"));
|
||||
}
|
||||
|
||||
// Serial.printf("Buffer: %u%\n", bytesAvailable*100/ramSize);
|
||||
// audioLogger->printf("Buffer: %u%\n", bytesAvailable*100/ramSize);
|
||||
|
||||
uint8_t *ptr = reinterpret_cast<uint8_t*>(data);
|
||||
uint32_t toReadFromBuffer = (len < bytesAvailable) ? len : bytesAvailable;
|
||||
@@ -142,7 +142,7 @@ void AudioFileSourceSPIRAMBuffer::fill()
|
||||
bytesAvailable+=cnt;
|
||||
writePtr = (writePtr + cnt) % ramSize;
|
||||
#ifdef SPIBUF_DEBUG
|
||||
Serial.printf_P(PSTR("SockRead: %u | RamAvail: %u\n"), cnt, bytesAvailable);
|
||||
audioLogger->printf_P(PSTR("SockRead: %u | RamAvail: %u\n"), cnt, bytesAvailable);
|
||||
#endif
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -34,13 +34,13 @@ AudioGeneratorAAC::AudioGeneratorAAC()
|
||||
buff = (uint8_t*)malloc(buffLen);
|
||||
outSample = (int16_t*)malloc(1024 * 2 * sizeof(uint16_t));
|
||||
if (!buff || !outSample) {
|
||||
Serial.printf_P(PSTR("ERROR: Out of memory in AAC\n"));
|
||||
audioLogger->printf_P(PSTR("ERROR: Out of memory in AAC\n"));
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
hAACDecoder = AACInitDecoder();
|
||||
if (!hAACDecoder) {
|
||||
Serial.printf_P(PSTR("Out of memory error! hAACDecoder==NULL\n"));
|
||||
audioLogger->printf_P(PSTR("Out of memory error! hAACDecoder==NULL\n"));
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
@@ -69,12 +69,12 @@ AudioGeneratorAAC::AudioGeneratorAAC(void *preallocateData, int preallocateSz)
|
||||
int used = p - (uint8_t*)preallocateSpace;
|
||||
int availSpace = preallocateSize - used;
|
||||
if (availSpace < 0 ) {
|
||||
Serial.printf_P(PSTR("ERROR: Out of memory in AAC\n"));
|
||||
audioLogger->printf_P(PSTR("ERROR: Out of memory in AAC\n"));
|
||||
}
|
||||
|
||||
hAACDecoder = AACInitDecoderPre(p, availSpace);
|
||||
if (!hAACDecoder) {
|
||||
Serial.printf_P(PSTR("Out of memory error! hAACDecoder==NULL\n"));
|
||||
audioLogger->printf_P(PSTR("Out of memory error! hAACDecoder==NULL\n"));
|
||||
Serial.flush();
|
||||
}
|
||||
buffValid = 0;
|
||||
|
||||
@@ -186,7 +186,7 @@ void AudioGeneratorFLAC::metadata_cb(const FLAC__StreamDecoder *decoder, const F
|
||||
{
|
||||
(void) decoder;
|
||||
(void) metadata;
|
||||
Serial.printf_P(PSTR("Metadata\n"));
|
||||
audioLogger->printf_P(PSTR("Metadata\n"));
|
||||
}
|
||||
void AudioGeneratorFLAC::error_cb(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
|
||||
{
|
||||
|
||||
@@ -73,7 +73,7 @@ void AudioGeneratorMIDI::midi_error(const char *msg, int curpos)
|
||||
cb.st(curpos, msg);
|
||||
#if 0
|
||||
int ptr;
|
||||
Serial.printf("---> MIDI file error at position %04X (%d): %s\n", (uint16_t) curpos, (uint16_t) curpos, msg);
|
||||
audioLogger->printf("---> MIDI file error at position %04X (%d): %s\n", (uint16_t) curpos, (uint16_t) curpos, msg);
|
||||
/* print some bytes surrounding the error */
|
||||
ptr = curpos - 16;
|
||||
if (ptr < 0) ptr = 0;
|
||||
@@ -81,9 +81,9 @@ void AudioGeneratorMIDI::midi_error(const char *msg, int curpos)
|
||||
for (int i = 0; i < 32; i++) {
|
||||
char c;
|
||||
buffer.read (buffer.data, &c, 1);
|
||||
Serial.printf((ptr + i) == curpos ? " [%02X] " : "%02X ", (int) c & 0xff);
|
||||
audioLogger->printf((ptr + i) == curpos ? " [%02X] " : "%02X ", (int) c & 0xff);
|
||||
}
|
||||
Serial.printf("\n");
|
||||
audioLogger->printf("\n");
|
||||
#endif
|
||||
running = false;
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ enum mad_flow AudioGeneratorMP3::Input()
|
||||
int len = buffLen - unused;
|
||||
len = file->read(buff + unused, len);
|
||||
if (len == 0) {
|
||||
Serial.printf_P(PSTR("MP3 stop, len==0\n"));
|
||||
audioLogger->printf_P(PSTR("MP3 stop, len==0\n"));
|
||||
return MAD_FLOW_STOP;
|
||||
}
|
||||
|
||||
@@ -162,7 +162,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.printf_P(PSTR("msf1ns failed\n"));
|
||||
case MAD_FLOW_BREAK: audioLogger->printf_P(PSTR("msf1ns failed\n"));
|
||||
return false; // Either way we're done
|
||||
default:
|
||||
break; // Do nothing
|
||||
@@ -201,7 +201,7 @@ retry:
|
||||
}
|
||||
|
||||
if (!GetOneSample(lastSample)) {
|
||||
Serial.printf_P(PSTR("G1S failed\n"));
|
||||
audioLogger->printf_P(PSTR("G1S failed\n"));
|
||||
running = false;
|
||||
goto done;
|
||||
}
|
||||
@@ -223,7 +223,7 @@ bool AudioGeneratorMP3::begin(AudioFileSource *source, AudioOutput *output)
|
||||
if (!output) return false;
|
||||
this->output = output;
|
||||
if (!file->isOpen()) {
|
||||
Serial.printf_P(PSTR("MP3 source file not open\n"));
|
||||
audioLogger->printf_P(PSTR("MP3 source file not open\n"));
|
||||
return false; // Error
|
||||
}
|
||||
|
||||
@@ -252,7 +252,7 @@ bool AudioGeneratorMP3::begin(AudioFileSource *source, AudioOutput *output)
|
||||
p += (sizeof(struct mad_synth)+7) & ~7;
|
||||
int neededBytes = p - reinterpret_cast<uint8_t *>(preallocateSpace);
|
||||
if (neededBytes > preallocateSize) {
|
||||
Serial.printf_P("OOM error in MP3: Want %d bytes, have %d bytes preallocated.\n", neededBytes, preallocateSize);
|
||||
audioLogger->printf_P("OOM error in MP3: Want %d bytes, have %d bytes preallocated.\n", neededBytes, preallocateSize);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@@ -313,13 +313,13 @@ extern "C" {
|
||||
if ((freestack < 512) || (freeheap < 5120)) {
|
||||
static int laststack, lastheap;
|
||||
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);
|
||||
audioLogger->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"));
|
||||
audioLogger->printf_P(PSTR("out of stack!\n"));
|
||||
}
|
||||
if (freeheap < 1024) {
|
||||
Serial.printf_P(PSTR("out of heap!\n"));
|
||||
audioLogger->printf_P(PSTR("out of heap!\n"));
|
||||
}
|
||||
Serial.flush();
|
||||
laststack = freestack;
|
||||
|
||||
@@ -30,7 +30,7 @@ AudioGeneratorMP3a::AudioGeneratorMP3a()
|
||||
output = NULL;
|
||||
hMP3Decoder = MP3InitDecoder();
|
||||
if (!hMP3Decoder) {
|
||||
Serial.printf_P(PSTR("Out of memory error! hMP3Decoder==NULL\n"));
|
||||
audioLogger->printf_P(PSTR("Out of memory error! hMP3Decoder==NULL\n"));
|
||||
Serial.flush();
|
||||
}
|
||||
// For sanity's sake...
|
||||
|
||||
@@ -257,7 +257,7 @@ bool AudioGeneratorRTTTL::GetNextNote()
|
||||
}
|
||||
ttlSamples = (rate * dur ) / 1000;
|
||||
|
||||
//Serial.printf("%d %d %d %d %d\n", dur, note, scale, ttlSamplesPerWaveFP10, ttlSamples );
|
||||
//audioLogger->printf("%d %d %d %d %d\n", dur, note, scale, ttlSamplesPerWaveFP10, ttlSamples );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
|
||||
#include "AudioLogger.h"
|
||||
|
||||
DevNullOut silencedLogger;
|
||||
Print* audioLogger = &silencedLogger;
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#ifndef _AUDIOLOGGER_H
|
||||
#define _AUDIOLOGGER_H
|
||||
|
||||
class DevNullOut: public Print
|
||||
{
|
||||
public:
|
||||
virtual size_t write(uint8_t) { return 1; }
|
||||
};
|
||||
|
||||
extern DevNullOut silencedLogger;
|
||||
|
||||
// Global `audioLogger` is initialized to &silencedLogger
|
||||
// It can be initialized anytime to &Serial or any other Print:: derivative instance.
|
||||
extern Print* audioLogger;
|
||||
|
||||
#endif
|
||||
@@ -69,9 +69,9 @@ AudioOutputI2S::AudioOutputI2S(int port, int output_mode, int dma_buf_count, int
|
||||
.dma_buf_len = 64,
|
||||
.use_apll = use_apll // Use audio PLL
|
||||
};
|
||||
Serial.printf("+%d %p\n", portNo, &i2s_config_dac);
|
||||
audioLogger->printf("+%d %p\n", portNo, &i2s_config_dac);
|
||||
if (i2s_driver_install((i2s_port_t)portNo, &i2s_config_dac, 0, NULL) != ESP_OK) {
|
||||
Serial.println("ERROR: Unable to install I2S drives\n");
|
||||
audioLogger->println("ERROR: Unable to install I2S drives\n");
|
||||
}
|
||||
if (output_mode == INTERNAL_DAC || output_mode == INTERNAL_PDM) {
|
||||
i2s_set_pin((i2s_port_t)portNo, NULL);
|
||||
@@ -100,7 +100,7 @@ AudioOutputI2S::~AudioOutputI2S()
|
||||
{
|
||||
#ifdef ESP32
|
||||
if (i2sOn) {
|
||||
Serial.printf("UNINSTALL I2S\n");
|
||||
audioLogger->printf("UNINSTALL I2S\n");
|
||||
i2s_driver_uninstall((i2s_port_t)portNo); //stop & destroy i2s driver
|
||||
}
|
||||
#else
|
||||
|
||||
@@ -72,7 +72,7 @@ bool AudioOutputSerialWAV::ConsumeSample(int16_t sample[2])
|
||||
|
||||
bool AudioOutputSerialWAV::stop()
|
||||
{
|
||||
Serial.printf_P(PSTR("\n\n\nEOF\n\n\n"));
|
||||
audioLogger->printf_P(PSTR("\n\n\nEOF\n\n\n"));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "AudioLogger.h"
|
||||
|
||||
class AudioStatus
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in new issue
Block a user