Skip to content

Commit

Permalink
bug fix: direct piezo hits sometimes cause a MIDI mute #142
Browse files Browse the repository at this point in the history
  • Loading branch information
corrados committed Apr 24, 2024
1 parent 89ccdd2 commit cdd53a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
17 changes: 12 additions & 5 deletions edrumulus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions edrumulus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit cdd53a9

Please sign in to comment.