mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
This commit is contained in:
parent
2c3bfe4ebb
commit
ef81b085a0
106 changed files with 6866 additions and 7106 deletions
23
engine/time/time_sample_rate.rs
Normal file
23
engine/time/time_sample_rate.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue