(&self)
| 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, |
nothing calls this directly
no test coverage detected