Work around panic in time::Instant subtraction

Also, reduced the maximum lag measure. 5 Frames lag should be enough.
This commit is contained in:
Thomas Kolb 2021-04-08 20:49:32 +02:00
parent c08f24f8dc
commit c1202bb41c

View file

@ -81,7 +81,7 @@ fn main()
let block_period = Duration::from_nanos((0.95 * (config::SAMPLES_PER_UPDATE as f32) * 1e9 / config::SAMP_RATE) as u64); let block_period = Duration::from_nanos((0.95 * (config::SAMPLES_PER_UPDATE as f32) * 1e9 / config::SAMP_RATE) as u64);
let send_period = Duration::from_nanos(1000000000 / 60); let send_period = Duration::from_nanos(1000000000 / 60);
let max_lag = Duration::from_millis(1000); let max_lag = 5*send_period;
let mut next_block_instant = Instant::now() + block_period; let mut next_block_instant = Instant::now() + block_period;
let mut next_send_instant = Instant::now() + send_period; let mut next_send_instant = Instant::now() + send_period;
@ -169,7 +169,7 @@ fn main()
} }
let now = Instant::now(); let now = Instant::now();
if now - next_send_instant > max_lag { if now > (next_send_instant + max_lag) {
println!("Warning! Lag exceeds {:?}. Resetting sender timing.", max_lag); println!("Warning! Lag exceeds {:?}. Resetting sender timing.", max_lag);
next_send_instant = now + send_period; next_send_instant = now + send_period;
} else { } else {