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: f64The linear value that reads as zero decibels, in base units.
factor: f64The log factor: twenty for amplitudes, ten for powers.
Implementations§
Source§impl Decibel
impl Decibel
Sourcepub fn amplitude(reference: f64) -> Self
pub fn amplitude(reference: f64) -> Self
An amplitude scale — factor twenty — against a stated reference.
Sourcepub fn microvolt() -> Self
pub fn microvolt() -> Self
dBµV: amplitude against one microvolt, the electromagnetic-compatibility convention.
Sourcepub fn milliampere() -> Self
pub fn milliampere() -> Self
dBmA: amplitude against one milliampere.
Sourcepub fn microampere() -> Self
pub fn microampere() -> Self
dBµA: amplitude against one microampere.
Sourcepub fn sound_pressure() -> Self
pub fn sound_pressure() -> Self
dB SPL: amplitude against twenty micropascals.
Sourcepub fn to_db(&self, linear: f64) -> f64
pub fn to_db(&self, linear: f64) -> f64
This linear value in decibels. Zero and below read as negative infinity.
Sourcepub fn is_compatible(&self, other: &Self) -> bool
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.
Sourcepub fn offset_from(&self, other: &Self) -> Option<f64>
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.