fix frame interval
This commit is contained in:
+16
-5
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user