Faster dbv/linear conversions, separate safe functions for when the extra safety (0/inf handling) is needed

This commit is contained in:
Vesa
2014-12-26 19:31:16 +02:00
parent 56ba799404
commit 1a5c085aa2

View File

@@ -239,10 +239,10 @@ static inline float linearToLogScale( float min, float max, float value )
//! @brief Converts linear amplitude (0-1.0) to dBV scale.
//! @brief Converts linear amplitude (0-1.0) to dBV scale. Handles zeroes as -inf.
//! @param amp Linear amplitude, where 1.0 = 0dBV.
//! @return Amplitude in dBV. -inf for 0 amplitude.
static inline float ampToDbv( float amp )
static inline float safeAmpToDbv( float amp )
{
return amp == 0.0f
? -INFINITY
@@ -250,10 +250,10 @@ static inline float ampToDbv( float amp )
}
//! @brief Converts dBV-scale to linear amplitude with 0dBV = 1.0
//! @brief Converts dBV-scale to linear amplitude with 0dBV = 1.0. Handles infinity as zero.
//! @param dbv The dBV value to convert: all infinites are treated as -inf and result in 0
//! @return Linear amplitude
static inline float dbvToAmp( float dbv )
static inline float safeDbvToAmp( float dbv )
{
return isinff( dbv )
? 0.0f
@@ -261,6 +261,24 @@ static inline float dbvToAmp( float dbv )
}
//! @brief Converts linear amplitude (>0-1.0) to dBV scale.
//! @param amp Linear amplitude, where 1.0 = 0dBV. ** Must be larger than zero! **
//! @return Amplitude in dBV.
static inline float ampToDbv( float amp )
{
return log10f( amp ) * 20.0f;
}
//! @brief Converts dBV-scale to linear amplitude with 0dBV = 1.0
//! @param dbv The dBV value to convert. ** Must be a real number - not inf/nan! **
//! @return Linear amplitude
static inline float dbvToAmp( float dbv )
{
return exp10f( dbv * 0.05f );
}
//! returns 1.0f if val >= 0.0f, -1.0 else
static inline float sign( float val )