@@ -514,9 +514,10 @@ void Edrumulus::Pad::initialize()
514
514
rim_max_power_low_limit = ADC_MAX_NOISE_AMPL * ADC_MAX_NOISE_AMPL / 31 .0f ; // lower limit on detected rim power, 15 dB below max noise amplitude
515
515
x_rim_hist_len = x_sq_hist_len + rim_shot_window_len;
516
516
cancellation_factor = static_cast <float > ( pad_settings.cancellation ) / 31 .0f ; // cancellation factor: range of 0.0..1.0
517
- ctrl_history_len = 10 ; // (MUST BE AN EVEN VALUE) control history length, use a fixed value
518
- ctrl_velocity_range_fact = 4 .0f ; // use a fixed value (TODO make it adjustable)
519
- ctrl_velocity_threshold = 5 .0f ; // use a fixed value (TODO make it adjustable)
517
+ ctrl_history_len = 10 ; // (MUST BE AN EVEN VALUE) control history length, use a fixed value
518
+ ctrl_history_len_half = ctrl_history_len / 2 ;
519
+ ctrl_velocity_range_fact = 20 .0f ; // use a fixed value (TODO make it adjustable)
520
+ ctrl_velocity_threshold = 1 .0f ; // use a fixed value (TODO make it adjustable)
520
521
max_num_overloads = 3 ; // maximum allowed number of overloaded samples until the overload special case is activated
521
522
522
523
// The ESP32 ADC has 12 bits resulting in a range of 20*log10(2048)=66.2 dB.
@@ -1502,22 +1503,24 @@ void Edrumulus::Pad::process_control_sample ( const int* input,
1502
1503
// detect pedal hit
1503
1504
update_fifo ( cur_midi_ctrl_value, ctrl_history_len, ctrl_hist );
1504
1505
1505
- float prev_ctrl_average = 0 ;
1506
- float cur_ctrl_average = 0 ;
1507
- for ( int i = 0 ; i < ctrl_history_len / 2 ; i++ )
1506
+ float prev_ctrl_average = 0 . 0f ;
1507
+ float cur_ctrl_average = 0 . 0f ;
1508
+ for ( int i = 0 ; i < ctrl_history_len_half ; i++ )
1508
1509
{
1509
- prev_ctrl_average += ctrl_hist[i]; // use first half for previous value
1510
- cur_ctrl_average += ctrl_hist[i + ctrl_history_len / 2 ]; // use second half for current value
1510
+ prev_ctrl_average += ctrl_hist[i]; // use first half for previous value
1511
+ cur_ctrl_average += ctrl_hist[i + ctrl_history_len_half ]; // use second half for current value
1511
1512
}
1512
- prev_ctrl_average /= ctrl_history_len / 2 ;
1513
- cur_ctrl_average /= ctrl_history_len / 2 ;
1513
+ prev_ctrl_average /= ctrl_history_len_half;
1514
+ cur_ctrl_average /= ctrl_history_len_half;
1515
+
1516
+ const float ctrl_gradient = ( cur_ctrl_average - prev_ctrl_average ) / ctrl_history_len_half;
1514
1517
1515
1518
if ( ( prev_ctrl_average < hi_hat_is_open_MIDI_threshold ) &&
1516
1519
( cur_ctrl_average >= hi_hat_is_open_MIDI_threshold ) &&
1517
- ( cur_ctrl_average - prev_ctrl_average > ctrl_velocity_threshold ) )
1520
+ ( ctrl_gradient > ctrl_velocity_threshold ) )
1518
1521
{
1519
1522
// map curve difference (gradient) to velocity
1520
- midi_velocity = min ( 127 , static_cast <int > ( ( cur_ctrl_average - prev_ctrl_average - ctrl_velocity_threshold ) * ctrl_velocity_range_fact ) );
1523
+ midi_velocity = min ( 127 , max ( 1 , static_cast <int > ( ( ctrl_gradient - ctrl_velocity_threshold ) * ctrl_velocity_range_fact ) ) );
1521
1524
peak_found = true ;
1522
1525
1523
1526
// reset the history after a detection to suppress multiple detections
0 commit comments