audio levels to db scale

edited October 2013 in How To...

can anyone explain to me how to take the audio level coming into processing and convert it to a db scale? I was looking at this http://www.indiana.edu/~emusic/acoustics/amplitude.htm and found some code that makes some sense

    float rms = 0.0;     
      for(int i = 0; i < in.bufferSize() - 1; i++)
      {
       rms += level*level;
      }

      rms = sqrt(rms / in.bufferSize());
      float dbScale = 0.5* (2.0 + log10(rms));

but I don't totally understand how they relate

Tagged:

Answers

  • edited October 2013

    Not sure but I think it should be something like:

    float dbScale = 20 * ( (float) Math.log10(rms) );
    
Sign In or Register to comment.