decibels, logarithms, etc.

Hey guys,

I'm trying to reverse engineer some sound effects and come up with a way to generate them algorithmically, and what I'm currently trying to do is recreate the way the volume of the sound effect changes versus time and speed. To do this, I have been analyzing the sounds in Sound Forge and recording the mininum and maximum decibels at various points. But after that, I'm stuck because I don't know how to convert decibels into a form which is useful to me in my code.

I know for example that -20 decibels may be 10-20x louder than -30 decibels, but I don't know how to convert those into an amplitude I can use. Sound Forge says the equation it uses to convert amplitude to decibels is db = 20 log (amplitude/32768). Now I assume the 32768 is there because the sound is 16bit internally, but the rest of the equation confuses me. I don't know much about logarithms, but I know there are different kinds, with different bases. And I'm not sure if that 10 log(x) is 10 * log(x) or whether it's telling me the log(x) is in base 10 or what.

Once I have that cleared up, I then need to know how to convert from the logarithm into real values which I can easily compare to see how large they are relative to one another. Ie, convert -10db to .1 and -20db to .01... so I can see that -20db is really 10x smaller than 10db. (This is easy with numbers like that, but when I'm working with -13db and -27db, I can't easily compare them.)

Of course I could just do all this stuff by ear and just fudge it, but then I wouldn't learn how the heck to convert to decibels and back. :-)

with different bases

You use log to the base 10 for audio work.

but the rest of the equation confuses me.

in what way? A Bell is simply the log (to the base 10) of the ratio of two numbers, measured over maximum. It is a relative measure. A deciBell is simply one tenth of a Bell.

The problem you will have with what you are doing is that the range of numbers you use in your program is tiny in comparison to the range you need. Every 3dBs doubles the number you need to express it.

Try reading:- http://en.wikipedia.org/wiki/Logarithm

I did read the wiki article. I didn't understand it.

but the rest of the equation confuses me.

in what way?

I'm confused about what DB = 10 LOG (amplitude/32768) means. What's the 10 there for? Is it multiplying LOG (amplitude/32768) by 10? Or is that some mathematical notation which lets me know the log is in base 10?

The logarithm of x to the base b is written logb(x) such as log10(1000) = 3

That's what the wiki article says. But the sound forge docs list no base after the logarith. Here's what they say:

The standard method for digital metering is to use the maximum possible sample value as a reference point. This value is referred to as 0 dB. Decibels are used to represent fractions logarithmically. In this case, the fraction is: sample amplitude divided by the maximum possible amplitude. The actual equation used to convert to decibels is: dB = 20 log (amplitude/32,768)

To illustrate this, consider a sine wave with a peak amplitude of 50% of full scale. Inserting the values in the appropriate places yields 20 log (0.50) = -6.0 dB. In fact, each time a signal's amplitude is divided by two, its dB value is decreased by 6 dB. Likewise, doubling the amplitude of a signal increases its dB value by 6 dB. Dividing the sine wave until its peak amplitude is equal to 1 produces lowest peak dB possible, -90.3 dB.

Why are dBs used when talking about audio? Decibels are typically used when dealing with sound pressure levels because of the vast range of sound (about 120 dB) that the human ear can perceive. It's also easier to say -90 dB than 0.000030 (1/32,768).

But the Wikipedia article on decibels has this equation:

Which shows clearly what base each log is in. So perhaps the sound forge docs simply omitted an important part of the equation?

The problem you will have with what you are doing is that the range of numbers you use in your program is tiny in comparison to the range you need. Every 3dBs doubles the number you need to express it.

All I'm trying to do is figure out: "Is sound effect B twice as loud as sound effect A?" "Is sound effect C ten times as loud as sound effect B?"

If I know this, and I know I am playing sound effect C at full volume, then I can calculate how loud to make sound effects B and A relative to it.

I can also ask "Is the beginning of sound effect A half as loud as the end of it?" so I can decide how much to ramp the volume up and down over the course of it.

But if I only have the decibels to go with, I can't do this, because I have no idea how loud -34 decibels is relative to -36 decibels.

One more thing…

I tend to shy away from the math in Wikipedia articles because it’s almost all written in calculus, and I don’t know calculus.

But now that I think I undertsand that 10 log (blah) really is multiplying log10(blah) by 10, and isn’t some funky calculus notation, and I look over the logarithm page on wikipedia again… I think maybe I’m starting to grasp it.

Wikipedia says b^x = y, where b is the base of the logarithm, x is the value returned by the logarithm, and y is the number you are taking the logarithm of.

So… if I have decibels, which are a number in log10 multipled by 20, then I think I can get the original value in the parentheses of that sound forge equation back by dividing decibels by 20, and then plugging the result into x in that equation, and setting b to 10, like so:

y = 10^(decibels/20)

So for a value of -31db, I get y = 10^(-31/20) = 10^-1.55 = 0.0282

Which looks like a reasonable value to me, though I don’t know if it is correct.