Function linear_to_db

Source
pub fn linear_to_db(linear: f32) -> f32
Expand description

Converts linear amplitude scale to decibels.

This function converts a linear amplitude value to its corresponding decibel value using the formula: decibels = 20 * log10(linear) for amplitude.

§Arguments

  • linear - The linear amplitude value to convert. Must be positive for meaningful results:
    • 1.0 = 0 dB (no change)
    • Values > 1.0 represent amplification (positive dB)
    • Values < 1.0 represent attenuation (negative dB)
    • 0.0 results in negative infinity
    • Negative values are not physically meaningful for amplitude

§Returns

The decibel value corresponding to the input linear amplitude.

§Performance

This implementation is optimized for speed, being faster than the standard 20.0 * linear.log10() approach while maintaining high precision.

§Special Cases

  • linear_to_db(0.0) returns negative infinity
  • Very small positive values approach negative infinity
  • Negative values return NaN (not physically meaningful for amplitude)