Converting avfoundation's power levels to/from logarithmic and linear scale

When using AVFoundation, you’ll notice that the numbers returned when checking the audio channel power levels may look kind of strange. The audio levels returned to you when calling AVCaptureSession-averagePowerLevel or AVCaptureAudioChannel-averagePowerLevel, etc. are in a logarithmic scale from -160dB to 0dB, similar to how we perceive sound.

But you may want to convert this logarithmic scale to a linear scale from 0.0 to 1.0 to use in an interface or something, here’s how to do it:

CGFloat linearPowerLevel = powf(10.f, decibelPowerLevel / 20.f);

Here’s how to go the other way:

CGFloat decibelPowerLevel = log10f(linearPowerLevel) * 20.f;

Follow me on Twitter to keep up with what I’ve learned building my personal finance tool, Stash.

Subscribe to my mailing list to learn more about technology and business.

Your email will never be shared with anyone else.

Read more posts …
Written: February 8th, 2013
Categories: ios, avfoundation, audio, video, core-audio