From 12a1962281100c4a934657b39c188843b9b2d729 Mon Sep 17 00:00:00 2001 From: Phil Schatzmann Date: Sun, 16 Apr 2023 17:55:06 +0200 Subject: [PATCH 1/2] Update library.properties --- library.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library.properties b/library.properties index 700f552..c2ea80e 100644 --- a/library.properties +++ b/library.properties @@ -1,7 +1,7 @@ name=vs1053 version=1.1.4 -author=Phil Schatzmann -maintainer=Phil Schatzmann/Marcin Szałomski/J. Coliz/ Ed Smallenburg/Henry Li +author=Marcin Szałomski/J. Coliz/ Ed Smallenburg/Henry Li/Phil Schatzmann +maintainer=Phil Schatzmann sentence=driver library for VS1053 Codec paragraph=driver library for VS1053 Codec category=Device Control From 286338212d1e328ebb26454681729b09838a44f0 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Mon, 22 Apr 2024 11:22:43 +0200 Subject: [PATCH 2/2] Options to minimize memory usage --- src/VS1053Config.h | 21 +++++++++++++++++++-- src/VS1053Driver.cpp | 12 +++++++++++- src/VS1053Driver.h | 4 +++- src/VS1053Ext.h | 2 +- src/VS1053Logger.h | 4 ++-- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/VS1053Config.h b/src/VS1053Config.h index 8bb4950..1028780 100644 --- a/src/VS1053Config.h +++ b/src/VS1053Config.h @@ -5,11 +5,28 @@ namespace arduino_vs1053{} // Define Logging Port #ifndef VS1053_LOG_PORT -#define VS1053_LOG_PORT Serial +# define VS1053_LOG_PORT Serial +#endif + +// Define the size of the log buffer +#ifndef LOG_BUFFER_SIZE +# define LOG_BUFFER_SIZE 100 +#endif + +// Enable support for MIDI: set to 0 to minimize memory usage +#ifndef USE_MIDI +# define USE_MIDI 1 +#endif + +// Load patches: set to 0 to minimize memory usage +#ifndef USE_PATCHES +# define USE_PATCHES 1 #endif // I2S Configuration: Use custom SPI Class for ESP -#define USE_ESP_SPI_CUSTOM 0 +#ifndef USE_ESP_SPI_CUSTOM +# define USE_ESP_SPI_CUSTOM 0 +#endif // In Arduino we usually do not want to work with namespaces. So we bring in the relevant namespace automatically. // Comment out or define VS1053_NO_USING_NAMESPACE if you need to use namespace in sketch diff --git a/src/VS1053Driver.cpp b/src/VS1053Driver.cpp index 001781c..5670259 100644 --- a/src/VS1053Driver.cpp +++ b/src/VS1053Driver.cpp @@ -532,11 +532,15 @@ void VS1053::loadUserCode(const unsigned short* plugin, unsigned short plugin_si /** * Load the latest generic firmware patch */ -void VS1053::loadDefaultVs1053Patches() { +bool VS1053::loadDefaultVs1053Patches() { +#if USE_PATCHES if (getChipVersion() == 4) { // Only perform an update if we really are using a VS1053, not. eg. VS1003 VS1053_LOGD("loadDefaultVs1053Patches"); loadUserCode(PATCHES, PATCHES_SIZE); + return true; } +#endif + return false; } /// Provides the treble amplitude value @@ -608,6 +612,7 @@ void VS1053::end() { softReset(); } +#if USE_MIDI bool VS1053::beginMidi() { VS1053_LOGI("beginMIDI"); @@ -671,6 +676,7 @@ void VS1053::sendMidiMessage(uint8_t cmd, uint8_t data1, uint8_t data2) { sdi_send_buffer(data, len); } +#endif void VS1053::writeAudio(uint8_t*data, size_t len){ if (mode == VS1053_MIDI){ @@ -714,6 +720,7 @@ bool VS1053::beginInput(VS1053Recording &opt) { bool VS1053::begin_input_vs1053(VS1053Recording &opt){ +#ifdef USE_INPUT VS1053_LOGD("%s",__func__); // clear SM_ADPCM bit writeRegister(SCI_AICTRL0, opt.sampleRate()); @@ -740,6 +747,9 @@ bool VS1053::begin_input_vs1053(VS1053Recording &opt){ loadUserCode(pcm1053, PLUGIN_SIZE_pcm1053); return true; +#else + return false; +#endif } bool VS1053::begin_input_vs1003(VS1053Recording &opt){ diff --git a/src/VS1053Driver.h b/src/VS1053Driver.h index 93e56e8..4bf14a6 100644 --- a/src/VS1053Driver.h +++ b/src/VS1053Driver.h @@ -355,7 +355,7 @@ class VS1053 { void loadUserCode(const unsigned short* plugin, unsigned short plugin_size); /// Loads the latest generic firmware patch. - void loadDefaultVs1053Patches(); + bool loadDefaultVs1053Patches(); /// Provides the treble amplitude value @@ -382,11 +382,13 @@ class VS1053 { /// Stops the recording of sound - and resets the module void end(); +#if USE_MIDI /// Starts the MIDI output processing bool beginMidi(); /// performs a MIDI command void sendMidiMessage(uint8_t cmd, uint8_t data1, uint8_t data2); +#endif /// Starts the recording of sound as WAV data bool beginInput(VS1053Recording &opt); diff --git a/src/VS1053Ext.h b/src/VS1053Ext.h index 4d4e5ed..faf66d8 100644 --- a/src/VS1053Ext.h +++ b/src/VS1053Ext.h @@ -26,7 +26,7 @@ #endif #ifndef PROGMEM -#define PROGMEM +# define PROGMEM #endif namespace arduino_vs1053 { diff --git a/src/VS1053Logger.h b/src/VS1053Logger.h index a3cc026..6b450aa 100644 --- a/src/VS1053Logger.h +++ b/src/VS1053Logger.h @@ -30,13 +30,13 @@ class VS1053LoggerClass { /// Print log message void log(VS1053LogLevel_t level, const char *fmt...) { if (logLevel <= level) { // AUDIOKIT_LOG_LEVEL = Debug - char log_buffer[200]; + char log_buffer[LOG_BUFFER_SIZE]; strcpy(log_buffer,"VS1053 - "); strcat(log_buffer, VS1053_log_msg[level]); strcat(log_buffer, ": "); va_list arg; va_start(arg, fmt); - vsprintf(log_buffer + 9, fmt, arg); + vsnprintf(log_buffer + 9, LOG_BUFFER_SIZE-9, fmt, arg); va_end(arg); p_out->println(log_buffer); }