Add 20ms flash latency to compensate for audio buffer (flash was ahead of beat)
This commit is contained in:
+6
-5
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user