decibelaudiokit

Why is this decibels calculation /10 instead of /20?


AudioKit supports normalizing an audio file to a given max level in decibels (dB).

My understanding is that these would be field quantities not power quantities.

Thus, shouldn't this be / 20.0 instead of / 10.0?

let gainFactor = Float( pow(10.0, newMaxLevel / 10.0) / pow(10.0, level / 10.0))

and shouldn't this be 20 * instead of 10 *?

return 10 * log10(maxLev)

Code in question:

https://github.com/AudioKit/AudioKit/blob/9ae8641551bc5f7b4c9b4c887aa327155fac83b5/AudioKit/Common/Internals/Audio%20File/AKAudioFile%2BProcessing.swift#L42

https://github.com/AudioKit/AudioKit/blob/9ae8641551bc5f7b4c9b4c887aa327155fac83b5/AudioKit/Common/Internals/Audio%20File/AKAudioFile.swift#L294

Reference:

http://www.sengpielaudio.com/calculator-db.htm

https://en.wikipedia.org/wiki/Field,_power,_and_root-power_quantities

Thanks!


Solution

  • This is a common misunderstanding among electrical engineering students when learning about power gain and voltage/current gain on a log scale, I'm surprised you've encountered it here.

    In my field log scale graphs are used most often to represent the power gain of a system over a given frequency range. In this case a 10 db rise in power corresponds with a 10 fold increase in power. However the same isn't true for voltages and currents; if a signal's voltage or current increases 10 fold then the signal's increase in power will not be 10 fold, it will be 100 fold. This is because power increases proportionally with the square of voltage and current.

    Thus when we take the log of an equation for a signal's power over frequency we will find something like this; (for a resistor)

    log(P(ω)) = log(V(ω)^2 / R) = 2log(V(ω)) - log(R)
    

    Multiply both sides by 10 to convert Bels to Decibels;

    10log(P(ω)) = 20log(V(ω)) - 10log(R)
    

    The relationship between the amplitude and power of a sound wave is similar to the relationship between the amplitude and power of an electrical signal AFAIK. The decibels are defined on power, so 20 dB of amplitude increase is whatever amount will increase the power output by 100 fold. That amount is 10 fold so a 10 fold increase in amplitude is an increase of 20 dB.

    P.S. To answer your question you need to determine if the levels are a unit of power or a unit of amplitude. You know more about the units the function uses than I do as my experience with audio files is highly limited, but my instinct is that an audio file is a representation of amplitude, in which case you would be correct; the conversion factors would need to be 20, not 10.