fix frame interval

This commit is contained in:
Bendik Aagaard Lynghaug
2026-03-07 18:31:08 +01:00
parent 6ff7fe8af2
commit 09a954ef18
4 changed files with 60 additions and 18 deletions
+16 -5
View File
@@ -79,6 +79,9 @@ struct DeckState {
sample_rate: u32,
read_pos: usize, // byte index into pcm (always even)
cue_pos: usize,
/// Track last VU update time to rate-limit updates
last_vu_update: std::time::Instant,
}
impl DeckState {
@@ -90,6 +93,7 @@ impl DeckState {
sample_rate: 44100,
read_pos: 0,
cue_pos: 0,
last_vu_update: std::time::Instant::now(),
}
}
}
@@ -220,11 +224,18 @@ fn engine_thread(cmd_rx: Receiver<AudioCmd>, status_tx: Sender<AudioStatus>) ->
deck: ds.id,
position: pos,
});
let _ = status_tx_cb.try_send(AudioStatus::Vu {
deck: ds.id,
l: vu_l,
r: vu_r,
});
// Rate-limit VU updates to ~60Hz (16ms) to reduce CPU usage
// while still providing smooth updates during playback
let now = std::time::Instant::now();
if now.duration_since(ds.last_vu_update) >= std::time::Duration::from_millis(16) {
let _ = status_tx_cb.try_send(AudioStatus::Vu {
deck: ds.id,
l: vu_l,
r: vu_r,
});
ds.last_vu_update = now;
}
}
})
.register()?; // Connect the stream with F32LE stereo format