mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
23 lines
849 B
Rust
23 lines
849 B
Rust
use crate::*;
|
|
|
|
/// Audio sample rate in Hz (samples per second)
|
|
#[derive(Debug, Default)] pub struct SampleRate(AtomicF64);
|
|
impl_time_unit!(SampleRate);
|
|
impl SampleRate {
|
|
/// Return the duration of a sample in microseconds (floating)
|
|
#[inline] pub fn usec_per_sample (&self) -> f64 {
|
|
1_000_000f64 / self.get()
|
|
}
|
|
/// Return the duration of a sample in microseconds (floating)
|
|
#[inline] pub fn sample_per_usec (&self) -> f64 {
|
|
self.get() / 1_000_000f64
|
|
}
|
|
/// Convert a number of samples to microseconds (floating)
|
|
#[inline] pub fn samples_to_usec (&self, samples: f64) -> f64 {
|
|
self.usec_per_sample() * samples
|
|
}
|
|
/// Convert a number of microseconds to samples (floating)
|
|
#[inline] pub fn usecs_to_sample (&self, usecs: f64) -> f64 {
|
|
self.sample_per_usec() * usecs
|
|
}
|
|
}
|