show buffer size and latency

This commit is contained in:
🪞👃🪞 2024-11-27 01:30:40 +01:00
parent 763063f4ed
commit 51889d4b43
5 changed files with 33 additions and 14 deletions

View file

@ -47,17 +47,23 @@ pub struct ClockModel {
pub quant: Arc<Quantize>,
/// Launch quantization factor
pub sync: Arc<LaunchSync>,
/// Size of buffer in samples
pub chunk: Arc<AtomicUsize>,
}
impl From<&Arc<Transport>> for ClockModel {
fn from (transport: &Arc<Transport>) -> Self {
impl From<&Arc<RwLock<JackClient>>> for ClockModel {
fn from (jack: &Arc<RwLock<JackClient>>) -> Self {
let jack = jack.read().unwrap();
let chunk = jack.client().buffer_size();
let transport = jack.client().transport();
Self {
playing: RwLock::new(None).into(),
started: RwLock::new(None).into(),
current: Instant::default().into(),
quant: Arc::new(24.into()),
sync: Arc::new(384.into()),
transport: transport.clone(),
transport: Arc::new(transport),
chunk: Arc::new((chunk as usize).into()),
}
}
}
@ -137,11 +143,18 @@ pub struct ClockAudio<'a, T: HasClock>(pub &'a mut T);
impl<'a, T: HasClock> Audio for ClockAudio<'a, T> {
#[inline] fn process (&mut self, _: &Client, scope: &ProcessScope) -> Control {
let state = self.0.clock();
let times = scope.cycle_times().unwrap();
let CycleTimes { current_frames, current_usecs, next_usecs: _, period_usecs: _ } = times;
let _chunk_size = scope.n_frames() as usize;
// Update chunk size
state.chunk.store(scope.n_frames() as usize, Ordering::Relaxed);
// Query transport state
let transport = state.transport.query().unwrap();
// FIXME duplicated
state.current.sample.set(transport.pos.frame() as f64);
// Update play/pause state and starting point
let CycleTimes { current_frames, current_usecs, .. } = scope.cycle_times().unwrap();
let mut playing = state.playing.write().unwrap();
let mut started = state.started.write().unwrap();
if *playing != Some(transport.state) {
@ -159,10 +172,13 @@ impl<'a, T: HasClock> Audio for ClockAudio<'a, T> {
if *playing == Some(TransportState::Stopped) {
*started = None;
}
// FIXME duplicated
state.current.update_from_usec(match *started {
Some((_, usecs)) => current_usecs as f64 - usecs as f64,
None => 0.
});
Control::Continue
}
}