pub struct SubframeTimestamp {
pub timecode: Timecode,
pub sample: u32,
pub sample_rate: u32,
}Expand description
A timecode extended with a sub-frame audio sample offset.
Fields§
§timecode: TimecodeThe integer-frame SMPTE timecode.
sample: u32Zero-based sample offset within the current frame.
sample_rate: u32Audio sample rate in Hz (e.g. 48000, 44100).
Implementations§
Source§impl SubframeTimestamp
impl SubframeTimestamp
Sourcepub fn new(tc: Timecode, sample: u32, sample_rate: u32) -> Self
pub fn new(tc: Timecode, sample: u32, sample_rate: u32) -> Self
Create a new SubframeTimestamp.
sample is the zero-based sample index within the frame identified by
tc. sample_rate must be > 0.
§Errors
Returns TimecodeError::InvalidConfiguration if sample_rate is 0.
Sourcepub fn to_nanos(&self) -> u64
pub fn to_nanos(&self) -> u64
Convert to an absolute nanosecond offset from timecode midnight (00:00:00:00).
The calculation is:
tc_nanos = timecode.to_frames() * 1_000_000_000 / frame_rate
sub_nanos = sample * 1_000_000_000 / sample_rate
total_nanos = tc_nanos + sub_nanosInteger arithmetic is used throughout to avoid floating-point error.
For drop-frame rates, timecode.to_frames() already accounts for the
frame drops.
Sourcepub fn subframe_fraction(&self) -> f64
pub fn subframe_fraction(&self) -> f64
Return the sub-frame offset as a fraction in [0.0, 1.0) of one frame.
fraction = sample / (sample_rate / frame_rate)
= sample * frame_rate / sample_rateSourcepub fn to_seconds_f64(&self) -> f64
pub fn to_seconds_f64(&self) -> f64
Convert back to floating-point seconds from midnight.
Sourcepub fn advance_samples(&self, samples: u32) -> Result<Self, TimecodeError>
pub fn advance_samples(&self, samples: u32) -> Result<Self, TimecodeError>
Advance by samples audio samples, wrapping timecode frames as needed.
Returns Err if timecode increment fails (e.g. wrapping past 23:59:59:xx).
Trait Implementations§
Source§impl Clone for SubframeTimestamp
impl Clone for SubframeTimestamp
Source§fn clone(&self) -> SubframeTimestamp
fn clone(&self) -> SubframeTimestamp
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more