pub struct PlayClock { /* private fields */ }Expand description
The play position of one output stream.
Cheap to clone; every clone reads the same stream. Get one from
OutputClass::clock.
let clock = output.clock();
std::thread::spawn(move || loop {
// What the listener hears right now, from the start of the stream.
println!("{:?}", clock.position());
std::thread::sleep(std::time::Duration::from_millis(500));
});Implementations§
Source§impl PlayClock
impl PlayClock
Sourcepub fn position(&self) -> Duration
pub fn position(&self) -> Duration
What is being heard now, measured from the first frame of the stream.
Between callbacks the position moves on with the monotonic clock, so it is smooth rather than stepping a buffer at a time; it never runs more than a buffer past the last callback, so a stalled device freezes it rather than letting it run away. Zero until the stream has started, and it never goes backwards.
Sourcepub fn frames(&self) -> u64
pub fn frames(&self) -> u64
Frames taken from the mixer since the stream was built — its padding
silence included, so this is the stream’s own timeline, the mixer’s
index divided by the channel count. The mixer’s cursor runs one buffer
ahead of it, so scheduling at frames() + buffer is never late.
Sourcepub fn latency(&self) -> Duration
pub fn latency(&self) -> Duration
How long after it is written a buffer reaches the listener, as the device last reported it.
Sourcepub fn sample_rate(&self) -> u32
pub fn sample_rate(&self) -> u32
The stream’s sample rate.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Whether the stream is running: built, not closed, and calling back.
False before the first callback, after close,
and when callbacks stop arriving — a device unplugged mid-show. Anything
following this clock should hold still while it is false.