From 109462f0b0ef3e22bf9959146b16fb8ea515f589 Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Mon, 20 Dec 2021 17:11:57 +0100 Subject: [PATCH] Fixes for stereo-panning. Fixes for dynamic memory allocation of the delaylines for chorus effects. --- MicroDexed.ino | 31 +++++++++++++++++-------------- UI.hpp | 6 +++--- effect_stereo_panorama.cpp | 26 ++++++++++---------------- 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index fedbda6..31420f6 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -407,10 +407,10 @@ int perform_release_mod[NUM_DEXED] = { 0 }; #endif #if defined(USE_FX) // Allocate the delay lines for chorus -int16_t delayline[NUM_DEXED][MOD_DELAY_SAMPLE_BUFFER]; +int16_t* delayline[NUM_DEXED]; #ifdef USE_EPIANO -int16_t ep_delayline_r[MOD_DELAY_SAMPLE_BUFFER]; -int16_t ep_delayline_l[MOD_DELAY_SAMPLE_BUFFER]; +int16_t* ep_delayline_r; +int16_t* ep_delayline_l; #endif #endif @@ -589,7 +589,8 @@ void setup() #if defined(USE_FX) #if defined(USE_EPIANO) // EP_CHORUS - memset(ep_delayline_r, 0, sizeof(ep_delayline_r)); + 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)) { #ifdef DEBUG @@ -597,7 +598,8 @@ void setup() #endif while (1); } - memset(ep_delayline_l, 0, sizeof(ep_delayline_l)); + 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)) { #ifdef DEBUG @@ -628,8 +630,9 @@ void setup() // Setup effects #if defined(USE_FX) for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) -{ - memset(delayline[instance_id], 0, sizeof(delayline[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)) { #ifdef DEBUG Serial.print(F("AudioEffectModulatedDelay - begin failed [")); @@ -653,9 +656,9 @@ void setup() sd_card = check_sd_cards(); if (sd_card < 1) -{ + { #ifdef DEBUG - Serial.println(F("SD card not accessable.")); + Serial.println(F("SD card not accessable.")); #endif } else @@ -691,8 +694,8 @@ void setup() // Load voices #ifdef DEBUG for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) -{ - Serial.print(F("Dexed instance ")); + { + Serial.print(F("Dexed instance ")); Serial.print(instance_id); Serial.println(F(":")); Serial.print(F("Bank/Voice [")); @@ -717,8 +720,8 @@ void setup() // Init master_mixer #if NUM_DEXED > 1 for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) -{ - master_mixer_r.gain(instance_id, VOL_MAX_FLOAT); + { + master_mixer_r.gain(instance_id, VOL_MAX_FLOAT); master_mixer_l.gain(instance_id, VOL_MAX_FLOAT); } #else @@ -2507,7 +2510,7 @@ void set_fx_params(void) uint16_t midi_sync_delay_time = uint16_t(60000.0 * midi_ticks_factor[configuration.fx.delay_sync[instance_id]] / seq.seq_bpm); delay_fx[instance_id]->delay(0, constrain(midi_sync_delay_time, DELAY_TIME_MIN, DELAY_TIME_MAX * 10)); } - + // REVERB SEND reverb_mixer_r.gain(instance_id, volume_transform(mapfloat(configuration.fx.reverb_send[instance_id], REVERB_SEND_MIN, REVERB_SEND_MAX, 0.0, VOL_MAX_FLOAT))); reverb_mixer_l.gain(instance_id, volume_transform(mapfloat(configuration.fx.reverb_send[instance_id], REVERB_SEND_MIN, REVERB_SEND_MAX, 0.0, VOL_MAX_FLOAT))); diff --git a/UI.hpp b/UI.hpp index 27a84bd..0bb40d5 100644 --- a/UI.hpp +++ b/UI.hpp @@ -3065,7 +3065,7 @@ void UI_func_epiano_chorus_frequency(uint8_t param) if (LCDML.FUNC_loop()) // ****** LOOP ********* { - if ((LCDML.BT_checkDown() && encoderDir[ENC_R].Down()) || (LCDML.BT_checkUp() && encoderDir[ENC_R].Up()) || (LCDML.BT_checkEnter() && encoderDir[ENC_R].ButtonShort())) + if ((LCDML.BT_checkDown() && encoderDir[ENC_R].Down()) || (LCDML.BT_checkUp() && encoderDir[ENC_R].Up())) { if (LCDML.BT_checkDown()) configuration.fx.ep_chorus_frequency = constrain(configuration.fx.ep_chorus_frequency + ENCODER[ENC_R].speed(), EP_CHORUS_FREQUENCY_MIN, EP_CHORUS_FREQUENCY_MAX); @@ -3145,7 +3145,7 @@ void UI_func_epiano_chorus_depth(uint8_t param) if (LCDML.FUNC_loop()) // ****** LOOP ********* { - if ((LCDML.BT_checkDown() && encoderDir[ENC_R].Down()) || (LCDML.BT_checkUp() && encoderDir[ENC_R].Up()) || (LCDML.BT_checkEnter() && encoderDir[ENC_R].ButtonShort())) + if ((LCDML.BT_checkDown() && encoderDir[ENC_R].Down()) || (LCDML.BT_checkUp() && encoderDir[ENC_R].Up())) { if (LCDML.BT_checkDown()) configuration.fx.ep_chorus_depth = constrain(configuration.fx.ep_chorus_depth + ENCODER[ENC_R].speed(), EP_CHORUS_DEPTH_MIN, EP_CHORUS_DEPTH_MAX); @@ -3178,7 +3178,7 @@ void UI_func_epiano_chorus_level(uint8_t param) if (LCDML.FUNC_loop()) // ****** LOOP ********* { - if ((LCDML.BT_checkDown() && encoderDir[ENC_R].Down()) || (LCDML.BT_checkUp() && encoderDir[ENC_R].Up()) || (LCDML.BT_checkEnter() && encoderDir[ENC_R].ButtonShort())) + if ((LCDML.BT_checkDown() && encoderDir[ENC_R].Down()) || (LCDML.BT_checkUp() && encoderDir[ENC_R].Up())) { if (LCDML.BT_checkDown()) { diff --git a/effect_stereo_panorama.cpp b/effect_stereo_panorama.cpp index ab9aee2..869a8a3 100644 --- a/effect_stereo_panorama.cpp +++ b/effect_stereo_panorama.cpp @@ -68,18 +68,8 @@ inline float mapfloat(float val, float in_min, float in_max, float out_min, floa void AudioEffectStereoPanorama::panorama(float p) { - if (p == 0.5) - pan_l = pan_r = 1.0; - else if (p > 0.5) - { - pan_r = 0.5 - abs(0.5 - p); - pan_l = 1.0 - pan_r; - } - else - { - pan_l = 0.5 - abs(0.5 - p); - pan_r = 1.0 - p; - } + pan_r = mapfloat(p, 0.0, 1.0, -1.0, 1.0); + pan_l = pan_r * -1.0; } void AudioEffectStereoPanorama::update(void) @@ -105,10 +95,14 @@ void AudioEffectStereoPanorama::update(void) for (uint16_t n = 0; n < AUDIO_BLOCK_SAMPLES; n++) { - out_f[0][n] = in_f[0][n] * pan_r; - out_f[0][n] += in_f[1][n] * pan_l; - out_f[1][n] = in_f[1][n] * pan_r; - out_f[1][n] += in_f[0][n] * pan_l; + if (pan_r > 0.0) + out_f[0][n] = (pan_r / 2.0 * in_f[1][n]) + ((1.0 - pan_r) / 2.0 * in_f[0][n]); + else + out_f[0][n] = abs(pan_r) * in_f[0][n]; + if (pan_l > 0.0) + out_f[1][n] = (pan_l / 2.0 * in_f[0][n]) + ((1.0 - pan_l) / 2.0 * in_f[1][n]); + else + out_f[1][n] = abs(pan_l) * in_f[1][n]; } arm_float_to_q15(out_f[0], out[0]->data, AUDIO_BLOCK_SAMPLES);