Proportional catch-up: send midpoint per update (fast convergence, rejects ±1 jitter)

This commit is contained in:
ash
2026-07-04 05:17:48 +00:00
parent 1dec81e329
commit f055bad4ac
+5 -5
View File
@@ -40,14 +40,14 @@ void ExpressionPedal::update(UsbMidiTransport& midi) {
uint8_t new_value = adc_to_midi(smoothed_raw); uint8_t new_value = adc_to_midi(smoothed_raw);
current_value = new_value; current_value = new_value;
// Rate-limited send: step ±1 per update when value deviates >1 from last sent. // Proportional catch-up: send midpoint rounded up each update.
// This prevents stationary jitter (adjacent-value dither) while keeping // Rejects ±1 stationary jitter but converges to exact value on movement
// movement smooth (values increment one at a time, faster than any foot). // (e.g., 0→127 converges in ~35ms).
if (current_value > last_sent_value + 1) { 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); midi.send_cc(midi_channel, midi_cc, last_sent_value);
} else if (current_value < last_sent_value - 1) { } 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); midi.send_cc(midi_channel, midi_cc, last_sent_value);
} }
} }