Struct Decibels
pub struct Decibels(/* private fields */);Expand description
A level in decibels: any finite value. A negative value is common, because levels are often relative to a peak.
use sound_to_patch::units::Decibels;
let level = Decibels::new(-6.0)?;
assert!(Decibels::new(f64::NAN).is_err());Implementations§
§impl Decibels
impl Decibels
pub fn to_amplitude_gain(self) -> Result<f64, RangeError>
pub fn to_amplitude_gain(self) -> Result<f64, RangeError>
Returns the amplitude gain 10^(dB / 20), the factor for a
magnitude such as a sample value or a spectral magnitude weight.
use sound_to_patch::units::Decibels;
let gain = Decibels::new(-20.0)?.to_amplitude_gain()?;
assert!((gain - 0.1).abs() < 1e-15);§Errors
Returns a RangeError beyond ±6000 dB, a conservative cap that
keeps the gain finite and nonzero.
pub fn from_amplitude_gain(gain: f64) -> Result<Decibels, RangeError>
pub fn from_amplitude_gain(gain: f64) -> Result<Decibels, RangeError>
Converts an amplitude gain: dB = 20 * log10(gain). The result can
lie beyond the cap of Decibels::to_amplitude_gain.
§Errors
Returns a RangeError for a gain of zero or less, which has no
decibel value, or one that is not finite.
pub fn to_power_ratio(self) -> Result<f64, RangeError>
pub fn to_power_ratio(self) -> Result<f64, RangeError>
Returns the power ratio 10^(dB / 10), the factor for an energy or a
power, such as the share of a frequency band.
§Errors
Returns a RangeError beyond ±3000 dB, a conservative cap that
keeps the ratio finite and nonzero.
pub fn from_power_ratio(ratio: f64) -> Result<Decibels, RangeError>
pub fn from_power_ratio(ratio: f64) -> Result<Decibels, RangeError>
Converts a power ratio: dB = 10 * log10(ratio). The result can lie
beyond the cap of Decibels::to_power_ratio.
§Errors
Returns a RangeError for a ratio of zero or less, or one that is
not finite.
Trait Implementations§
impl Copy for Decibels
§impl<'de> Deserialize<'de> for Decibels
impl<'de> Deserialize<'de> for Decibels
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Decibels, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Decibels, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl FromStr for Decibels
impl FromStr for Decibels
§type Err = ParseUnitError
type Err = ParseUnitError
§impl PartialOrd for Decibels
impl PartialOrd for Decibels
§impl Serialize for Decibels
impl Serialize for Decibels
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Spread for Decibels
impl StructuralPartialEq for Decibels
Auto Trait Implementations§
impl Freeze for Decibels
impl RefUnwindSafe for Decibels
impl Send for Decibels
impl Sync for Decibels
impl Unpin for Decibels
impl UnsafeUnpin for Decibels
impl UnwindSafe for Decibels
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> ClampCast for Twhere
T: PartialOrd + Copy + 'static,
impl<T> ClampCast for Twhere
T: PartialOrd + Copy + 'static,
fn clamp_cast<O>(self) -> O
impl<T> CloneAny for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more