Expand description
Clock synchronization and timestamp conversion for real-time audio.
This crate provides the ClockSource trait — the single contract a host
application uses to map between an audio sample index and a wall-clock
PTP timestamp (nanoseconds since the PTP epoch). It is the glue that
lets an audio engine timestamp its samples for distributed playback
(e.g. AES67/PTP-aligned streaming) or for offline alignment.
§Threading model
A ClockSource is not a real-time-thread primitive: polling an NTP
daemon or a PTP hardware clock, and running the drift-compensation loop, are
blocking operations. A concrete clock is intended to live on a separate
thread (or be polled periodically from a worker); the cheap, allocation-free
ClockSource::sample_to_ptp / ClockSource::ptp_to_sample conversions
may then be called from anywhere, including the RT audio thread.
§Backends
NtpClock— the default fallback, anchored to the system monotonic/wall clock viastd::time. Always available.PtpClock— aPTPv2(IEEE 1588-2008) interface. FreeBSD hardware PTP timestamping support is hardware-dependent, so the concrete implementation reads PTP time from an injectablePtpTimeProvider(e.g. a daemon-polling thread) and degrades to aClockError::Unavailablestub when none is present.
§Dependency licensing
This crate depends on audio-core-bsd (BSD-2-Clause) and
thiserror (MIT OR Apache-2.0). It links no system library, so it
builds and tests anywhere.
Re-exports§
pub use clock::ClockAnchor;pub use clock::ClockSource;pub use error::ClockError;pub use error::Result;pub use ntp::NtpClock;pub use ptp::PtpClock;pub use ptp::PtpTimeProvider;
Modules§
- clock
- The
ClockSourcetrait and the anchor-based sample↔timestamp conversion. - error
- Crate error types and the
Resultalias. - ntp
NtpClock— the default system-clock fallback forClockSource.- ptp
PtpClock— aPTPv2(IEEE 1588-2008)ClockSourcebackend.