MCPcopy Create free account
hub / github.com/BillyDM/Firewheel / audio_clock

Method audio_clock

crates/firewheel-graph/src/context.rs:624–644  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

622 /// the system's time (`Instant::now`). (Instead it is based on the amount of data
623 /// that has been processed.) For applications where the timing of audio events is
624 /// critical (i.e. a rhythm game), sync the game to this audio clock instead of the
625 /// OS's clock (`Instant::now()`).
626 ///
627 /// Note, calling this method is not super cheap, so avoid calling it many
628 /// times within the same game loop iteration if possible.
629 #[cfg(feature = "scheduled_events")]
630 pub fn audio_clock(&self) -> AudioClock {
631 // Reading the latest value of the clock doesn't meaningfully mutate
632 // state, so treat it as an immutable operation with interior mutability.
633 //
634 // PANIC SAFETY: This struct is the only place this is ever borrowed, so this
635 // will never panic.
636 let mut clock_borrowed = self.shared_clock_output.borrow_mut();
637 let clock = clock_borrowed.read();
638
639 AudioClock {
640 samples: clock.clock_samples,
641 seconds: clock
642 .clock_samples
643 .to_seconds(self.sample_rate, self.sample_rate_recip),
644 #[cfg(feature = "musical_transport")]
645 musical: clock.current_playhead,
646 #[cfg(feature = "musical_transport")]
647 transport_is_playing: clock.transport_is_playing,

Callers

nothing calls this directly

Calls 3

readMethod · 0.80
to_secondsMethod · 0.80
is_activeMethod · 0.45

Tested by

no test coverage detected