Proportional catch-up: send midpoint per update (fast convergence, rejects ±1 jitter)
This commit is contained in:
@@ -40,14 +40,14 @@ void ExpressionPedal::update(UsbMidiTransport& midi) {
|
||||
uint8_t new_value = adc_to_midi(smoothed_raw);
|
||||
current_value = new_value;
|
||||
|
||||
// Rate-limited send: step ±1 per update when value deviates >1 from last sent.
|
||||
// This prevents stationary jitter (adjacent-value dither) while keeping
|
||||
// movement smooth (values increment one at a time, faster than any foot).
|
||||
// Proportional catch-up: send midpoint rounded up each update.
|
||||
// Rejects ±1 stationary jitter but converges to exact value on movement
|
||||
// (e.g., 0→127 converges in ~35ms).
|
||||
if (current_value > last_sent_value + 1) {
|
||||
last_sent_value++;
|
||||
last_sent_value = (last_sent_value + current_value + 1) / 2;
|
||||
midi.send_cc(midi_channel, midi_cc, last_sent_value);
|
||||
} else if (current_value < last_sent_value - 1) {
|
||||
last_sent_value--;
|
||||
last_sent_value = (last_sent_value + current_value) / 2;
|
||||
midi.send_cc(midi_channel, midi_cc, last_sent_value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user