pub struct Frequency(pub f64);Expand description
A positive frequency in hertz.
§Examples
use sim_lib_sound_core::Frequency;
let a4 = Frequency::new(440.0).unwrap();
let a5 = Frequency::new(880.0).unwrap();
assert!((a5.cents_above(a4) - 1200.0).abs() < 1e-9);
assert!(Frequency::new(0.0).is_err());Tuple Fields§
§0: f64Implementations§
Source§impl Frequency
impl Frequency
Sourcepub fn new(hz: f64) -> Result<Self, SoundCoreError>
pub fn new(hz: f64) -> Result<Self, SoundCoreError>
Builds a frequency, returning SoundCoreError::InvalidFrequency when
hz is not a positive, finite value.
Sourcepub fn ratio(self, other: Frequency) -> f64
pub fn ratio(self, other: Frequency) -> f64
Returns the linear ratio of this frequency to other.
Sourcepub fn cents_above(self, other: Frequency) -> f64
pub fn cents_above(self, other: Frequency) -> f64
Returns the interval from other to this frequency, measured in cents.
Sourcepub fn shift_cents(self, cents: f64) -> Frequency
pub fn shift_cents(self, cents: f64) -> Frequency
Returns this frequency shifted by cents (positive raises, negative
lowers).
Trait Implementations§
impl Copy for Frequency
Source§impl PartialOrd for Frequency
impl PartialOrd for Frequency
impl StructuralPartialEq for Frequency
Auto Trait Implementations§
impl Freeze for Frequency
impl RefUnwindSafe for Frequency
impl Send for Frequency
impl Sync for Frequency
impl Unpin for Frequency
impl UnsafeUnpin for Frequency
impl UnwindSafe for Frequency
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more