Float to decibel conversion


#1

I’m having a hell of a time trying to find the formula for converting a normalized (0.0 to 1.0) float to a decibel value. It’s not a particularly search-friendly phrase. Can anyone help me out here?


#2

No worries:


float LinearToDecibel(float linear)
{
   float db;

   if (linear != 0.0f)
     db = 20.0f * log10(linear);
   else
     db = -144.0f;  // effectively minus infinity

   return db;
}

#3

That’ll do. I saw so many different formulas, I was confusing myself. And I could have sworn that Juce has this defined somewhere, but maybe it doesn’t.


#4