Add 20ms flash latency to compensate for audio buffer (flash was ahead of beat)

This commit is contained in:
ash
2026-07-03 07:53:04 +00:00
parent b859527169
commit df1f678845
+6 -5
View File
@@ -29,6 +29,7 @@ void midi_task(void* parameter) {
// Beat timing fixes for precise beat alignment - sync to real MIDI time, not hardcoded tempo
uint32_t last_beat = 0;
uint32_t flash_start = 0;
const uint32_t FLASH_LATENCY = 20; // ms delay to compensate for audio buffer
while (true) {
midi_transport.update();
@@ -41,20 +42,20 @@ void midi_task(void* parameter) {
if (current_beat != last_beat) {
last_beat = current_beat;
flash_start = now;
flash_start = now + FLASH_LATENCY;
// Beat 1 (every 4th) = RED, others = WHITE
if (current_beat % 4 == 0) {
mux.set_led_color(6, 255, 0, 0);
} else {
mux.set_led_color(6, 255, 255, 255);
}
mux.show();
}
// Beat 1 holds red for 100ms, others snap to dim after 50ms
if (flash_start > 0) {
if (flash_start > 0 && now >= flash_start) {
mux.show();
uint32_t hold = (last_beat % 4 == 0) ? 100 : 50;
if (now - flash_start >= hold) {
uint32_t elapsed = now - flash_start;
if (elapsed >= hold) {
mux.set_led_color(6, 20, 20, 20);
mux.show();
flash_start = 0;