1
0
Fork 0

Add a gain_to_db_fast() with a lower limit

These functions probably need some better organization at some point.
This commit is contained in:
Robbert van der Helm 2023-01-15 17:15:56 +01:00
parent 4b2ba9de12
commit 92ce737000

View file

@ -71,6 +71,14 @@ pub fn gain_to_db_fast(gain: f32) -> f32 {
f32::max(gain, MINUS_INFINITY_GAIN).ln() * CONVERSION_FACTOR
}
/// [`db_to_gain_fast()`], but the minimum gain value is set to [`f32::EPSILON`]instead of
/// [`MINUS_INFINITY_GAIN`]. Useful in conjunction with [`db_to_gain_fast()`].
#[inline]
pub fn gain_to_db_fast_epsilon(gain: f32) -> f32 {
const CONVERSION_FACTOR: f32 = std::f32::consts::LOG10_E * 20.0;
f32::max(gain, MINUS_INFINITY_GAIN).ln() * CONVERSION_FACTOR
}
/// Convert a MIDI note ID to a frequency at A4 = 440 Hz equal temperament and middle C = note 60 =
/// C4.
#[inline]