Skip to main content

Decibel

Struct Decibel 

Source
pub struct Decibel {
    pub reference: f64,
    pub factor: f64,
}
Expand description

A decibel scale: dB = factor · log10(linear / reference).

The factor is the whole difference between an amplitude quantity and a power one — twenty for volts, amperes and pressures, ten for watts — and mixing the two is the mistake this type exists to make unrepresentable.

Fields§

§reference: f64

The linear value that reads as zero decibels, in base units.

§factor: f64

The log factor: twenty for amplitudes, ten for powers.

Implementations§

Source§

impl Decibel

Source

pub fn amplitude(reference: f64) -> Self

An amplitude scale — factor twenty — against a stated reference.

Source

pub fn power(reference: f64) -> Self

A power scale — factor ten — against a stated reference.

Source

pub fn volt() -> Self

dBV: amplitude against one volt.

Source

pub fn millivolt() -> Self

dBmV: amplitude against one millivolt.

Source

pub fn microvolt() -> Self

dBµV: amplitude against one microvolt, the electromagnetic-compatibility convention.

Source

pub fn ampere() -> Self

dBA: amplitude against one ampere.

Source

pub fn milliampere() -> Self

dBmA: amplitude against one milliampere.

Source

pub fn microampere() -> Self

dBµA: amplitude against one microampere.

Source

pub fn sound_pressure() -> Self

dB SPL: amplitude against twenty micropascals.

Source

pub fn watt() -> Self

dBW: power against one watt.

Source

pub fn milliwatt() -> Self

dBm: power against one milliwatt, the radio convention.

Source

pub fn to_db(&self, linear: f64) -> f64

This linear value in decibels. Zero and below read as negative infinity.

Source

pub fn to_linear(&self, db: f64) -> f64

This decibel value back in base units.

Source

pub fn is_compatible(&self, other: &Self) -> bool

Whether two scales measure the same kind of quantity.

Same factor, any reference: dBµV and dBmV are one subtraction apart, dBV and dBm are not comparable at all.

Source

pub fn offset_from(&self, other: &Self) -> Option<f64>

What to add to a value in other to read it in this scale.

Nothing, when the two measure different kinds of quantity.

Trait Implementations§

Source§

impl Clone for Decibel

Source§

fn clone(&self) -> Decibel

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Decibel

Source§

impl Debug for Decibel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Decibel

Source§

fn eq(&self, other: &Decibel) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Decibel

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.