Float to decibel conversion


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?


No worries:

float LinearToDecibel(float linear)
   float db;

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

   return db;


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.