From fed3b61f43aff0b87f561471528fa9f3bd8f2c67 Mon Sep 17 00:00:00 2001 From: Eric Van Albert Date: Thu, 29 Jun 2023 23:25:18 -0400 Subject: [PATCH] Expose latency compensation on UI --- src/bin/main.rs | 8 ++++++++ src/lib/mir.rs | 8 ++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index 0f4443bb..5f63c0d9 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -518,6 +518,14 @@ pub async fn run() { ); } }); + ui.label("Latency compensation:"); + ui.add( + egui::DragValue::new(&mut mir.latency_compensation) + .speed(0.001) + .fixed_decimals(3) + .suffix("s") + .clamp_range(0. ..=1.), + ); }); let mosaic_response = ui.add(mosaic( diff --git a/src/lib/mir.rs b/src/lib/mir.rs index 7eda3db6..8129b58e 100644 --- a/src/lib/mir.rs +++ b/src/lib/mir.rs @@ -5,8 +5,6 @@ use std::sync::mpsc; use std::time; const MAX_TIME: f32 = 64.; -// Anticipate beats by this many seconds -const LATENCY_COMPENSATION: f32 = 0.10; const DEFAULT_BPM: f32 = 120.; @@ -32,6 +30,7 @@ pub struct Mir { receiver: mpsc::Receiver, last_update: Update, pub global_timescale: f32, + pub latency_compensation: f32, // Anticipate beats by this many seconds } /// Updates sent over a queue @@ -264,6 +263,7 @@ impl Mir { spectrum: [0.; SPECTRUM_LENGTH], }, global_timescale: 1., + latency_compensation: 0.1, } } @@ -282,12 +282,12 @@ impl Mir { let unscaled_time = self .last_update - .t(time::Instant::now() + time::Duration::from_secs_f32(LATENCY_COMPENSATION)) + .t(time::Instant::now() + time::Duration::from_secs_f32(self.latency_compensation)) .rem_euclid(MAX_TIME); let time = (self .last_update - .t(time::Instant::now() + time::Duration::from_secs_f32(LATENCY_COMPENSATION)) + .t(time::Instant::now() + time::Duration::from_secs_f32(self.latency_compensation)) * self.global_timescale) .rem_euclid(MAX_TIME);