using System;
namespace NAudio.Utils
{
///
/// A util class for conversions
///
public class Decibels
{
// 20 / ln( 10 )
private const double LOG_2_DB = 8.6858896380650365530225783783321;
// ln( 10 ) / 20
private const double DB_2_LOG = 0.11512925464970228420089957273422;
///
/// linear to dB conversion
///
/// linear value
/// decibel value
public static double LinearToDecibels(double lin)
{
return Math.Log(lin) * LOG_2_DB;
}
///
/// dB to linear conversion
///
/// decibel value
/// linear value
public static double DecibelsToLinear(double dB)
{
return Math.Exp(dB * DB_2_LOG);
}
}
}