From df26d255d46954c24b75a56736792041d61bd54e Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Wed, 22 Dec 2021 12:23:59 +0100 Subject: [PATCH] Fixes for memory allocation. --- MicroDexed.ino | 63 ++++++++++++++++++----- third-party/LCDMenuLib2/src/LCDMenuLib2.h | 2 +- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 79d5c90..a8d614a 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -509,8 +509,6 @@ void setup() //sgtl5000.enhanceBass(1.0, 1.5, 0, 5); // enhanceBass(1.0, 1.0, 1, 2); // Configures the bass enhancement by setting the levels of the original stereo signal and the bass-enhanced mono level which will be mixed together. The high-pass filter may be enabled (0) or bypassed (1). //sgtl5000.surroundSoundEnable(); //sgtl5000.surroundSound(7, 3); // Configures virtual surround width from 0 (mono) to 7 (widest). select may be set to 1 (disable), 2 (mono input) or 3 (stereo input). - //sgtl5000.autoVolumeEnable(); - //sgtl5000.autoVolumeControl(1, 1, 1, 0.9, 0.01, 0.05); #else sgtl5000.audioProcessorDisable(); sgtl5000.autoVolumeDisable(); @@ -589,21 +587,44 @@ void setup() #if defined(USE_FX) #if defined(USE_EPIANO) // EP_CHORUS - ep_delayline_l = new int16_t[MOD_DELAY_SAMPLE_BUFFER]; - memset(ep_delayline_r, 0, MOD_DELAY_SAMPLE_BUFFER * sizeof(int16_t)); - if (!ep_modchorus_r.begin(ep_delayline_r, MOD_DELAY_SAMPLE_BUFFER)) + //ep_delayline_r = new (std::nothrow) int16_t[MOD_DELAY_SAMPLE_BUFFER]; + ep_delayline_r = (int16_t*)malloc(MOD_DELAY_SAMPLE_BUFFER * sizeof(int16_t)); + if (ep_delayline_r != NULL) { + memset(ep_delayline_r, 0, MOD_DELAY_SAMPLE_BUFFER * sizeof(int16_t)); + if (!ep_modchorus_r.begin(ep_delayline_r, MOD_DELAY_SAMPLE_BUFFER)) + { #ifdef DEBUG - Serial.println(F("AudioEffectModulatedDelay R - begin failed EP")); + Serial.println(F("AudioEffectModulatedDelay R - begin failed EP")); +#endif + while (1); + } + } + else + { +#ifdef DEBUG + Serial.println(F("AudioEffectModulatedDelay R - memory allocation failed EP")); #endif while (1); } - ep_delayline_r = new int16_t[MOD_DELAY_SAMPLE_BUFFER]; - memset(ep_delayline_l, 0, MOD_DELAY_SAMPLE_BUFFER * sizeof(int16_t)); - if (!ep_modchorus_l.begin(ep_delayline_l, MOD_DELAY_SAMPLE_BUFFER)) + + //ep_delayline_l = new (std::nothrow) int16_t[MOD_DELAY_SAMPLE_BUFFER]; + ep_delayline_l = (int16_t*)malloc(MOD_DELAY_SAMPLE_BUFFER * sizeof(int16_t)); + if (ep_delayline_l != NULL) + { + memset(ep_delayline_l, 0, MOD_DELAY_SAMPLE_BUFFER * sizeof(int16_t)); + if (!ep_modchorus_l.begin(ep_delayline_l, MOD_DELAY_SAMPLE_BUFFER)) + { +#ifdef DEBUG + Serial.println(F("AudioEffectModulatedDelay L - begin failed EP")); +#endif + while (1); + } + } + else { #ifdef DEBUG - Serial.println(F("AudioEffectModulatedDelay L - begin failed EP")); + Serial.println(F("AudioEffectModulatedDelay L - memory allocation failed EP")); #endif while (1); } @@ -631,11 +652,25 @@ void setup() #if defined(USE_FX) for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) { - delayline[instance_id] = new int16_t[MOD_DELAY_SAMPLE_BUFFER]; - memset(delayline[instance_id], 0, MOD_DELAY_SAMPLE_BUFFER * sizeof(int16_t)); - if (!modchorus[instance_id]->begin(delayline[instance_id], MOD_DELAY_SAMPLE_BUFFER)) { + //delayline[instance_id] = new (std::nothrow) int16_t[MOD_DELAY_SAMPLE_BUFFER]; + delayline[instance_id] = (int16_t*)malloc(MOD_DELAY_SAMPLE_BUFFER * sizeof(int16_t)); + if (delayline[instance_id] != NULL) + { + memset(delayline[instance_id], 0, MOD_DELAY_SAMPLE_BUFFER * sizeof(int16_t)); + if (!modchorus[instance_id]->begin(delayline[instance_id], MOD_DELAY_SAMPLE_BUFFER)) + { +#ifdef DEBUG + Serial.print(F("AudioEffectModulatedDelay - begin failed [")); + Serial.print(instance_id); + Serial.println(F("]")); +#endif + while (1); + } + } + else + { #ifdef DEBUG - Serial.print(F("AudioEffectModulatedDelay - begin failed [")); + Serial.print(F("AudioEffectModulatedDelay - memory allocation failed [")); Serial.print(instance_id); Serial.println(F("]")); #endif diff --git a/third-party/LCDMenuLib2/src/LCDMenuLib2.h b/third-party/LCDMenuLib2/src/LCDMenuLib2.h index f63b3a0..56b61b0 100644 --- a/third-party/LCDMenuLib2/src/LCDMenuLib2.h +++ b/third-party/LCDMenuLib2/src/LCDMenuLib2.h @@ -80,7 +80,7 @@ #endif // Version - #define _LCDML_VERSION "LCDML2 v2.2.7" + #define _LCDML_VERSION "LCDML2 v2.2.7-T" // this makro is for unused variables which exists for compatibility things ... #define LCDML_UNUSED(expr) do { (void)(expr); } while (0)