From cdd53a9909894776fbdd2d16cb7fd8f28fdd3763 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Wed, 24 Apr 2024 21:12:44 +0200 Subject: [PATCH] bug fix: direct piezo hits sometimes cause a MIDI mute #142 --- edrumulus.cpp | 17 ++++++++++++----- edrumulus.h | 5 +++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/edrumulus.cpp b/edrumulus.cpp index a6f4fc2..49089fd 100644 --- a/edrumulus.cpp +++ b/edrumulus.cpp @@ -582,11 +582,18 @@ void Edrumulus::Pad::initialize() x_low_hist_len = x_sq_hist_len + lp_filt_len; // clipping compensation initialization - for ( int i = 0; i < length_ampmap; i++ ) + length_ampmap = 0; + for ( int i = 0; i < max_length_ampmap; i++ ) { - // never to higher than 5 - amplification_mapping[i] = min ( 5.0f, pow ( 10.0f, ( i * pad_settings.clip_comp_ampmap_step ) * - ( i * pad_settings.clip_comp_ampmap_step ) ) ); + const float amp_map_val = pow ( 10.0f, ( i * pad_settings.clip_comp_ampmap_step ) * + ( i * pad_settings.clip_comp_ampmap_step ) ); + + // never to higher than 5 but at least two values + if ( ( length_ampmap < 2 ) || ( amp_map_val <= 5.0f ) ) + { + amplification_mapping[i] = amp_map_val; + length_ampmap++; + } } // pre-calculate equations needed for 3 sensor get position function @@ -996,7 +1003,7 @@ float Edrumulus::Pad::process_sample ( const float* input, mean_neighbor = sqrt ( right_neighbor ); // only right neighbor available } - const float a_low = amplification_mapping[min ( length_ampmap - 1, number_overloaded_samples )]; + const float a_low = amplification_mapping[min ( length_ampmap - 2, number_overloaded_samples )]; const float a_high = amplification_mapping[min ( length_ampmap - 1, number_overloaded_samples + 1 )]; const float a_diff = a_high - a_low; const float a_diff_abs = a_diff * peak_val_sqrt / a_low; diff --git a/edrumulus.h b/edrumulus.h index 8f8bdea..33d0a3d 100644 --- a/edrumulus.h +++ b/edrumulus.h @@ -342,7 +342,7 @@ class Edrumulus void initialize(); // this function should not be called directly but use sched_init() instead void sched_init() { init_delay_cnt = init_delay_value; }; // schedule initialization function (for delayed initialization) const float init_delay_value_s = 0.2; // init delay value in seconds - static const int length_ampmap = 20; // maxmimum number of amplification mappings for clipping compensation + static const int max_length_ampmap = 20; // maxmimum number of amplification mappings for clipping compensation static const int ctrl_history_len = 10; // (MUST BE AN EVEN VALUE) control history length; the longer, the more noise reduction but more delay // band-pass filter coefficients (they are constant and must not be changed) @@ -430,7 +430,8 @@ const float ADC_noise_peak_velocity_scaling = 1.0f / 6.0f; int init_delay_value; int overload_hist_len; int max_num_overloads; - float amplification_mapping[length_ampmap]; + int length_ampmap; + float amplification_mapping[max_length_ampmap]; int scan_time; int pre_scan_time; int total_scan_time;