iPhone SDK: AVAudioRecorder metering -- how to change peakPowerForChannel from decibel into percentage?
Asked Answered
D

2

9

The AVAudioRecorder in the iPhone SDK can be used to get the peak and average power for a channel, in decibels. The range is between 0db to 160db. What is the calculation used to convert this into a scale between 0 - 10 or something similar that can be used for an audio level meter?

Devondevona answered 17/3, 2010 at 19:44 Comment(0)
C
21

The range is from -160 dB to 0 dB. You probably want to display it in a meter that goes from -90 dB to 0 dB. Displaying it as decibels is actually more useful than as a linear audio level, because the decibels are a logarithmic scale, which means that it more closely approximates how loud we perceive a sound.

That said, you can use this to convert from decibels to linear:

linear = pow (10, decibels / 20);

and the reverse:

decibels = log10 (linear) * 20;

The range for the above decibels is negative infinity to zero, and for linear is 0.0 to 1.0. When the linear value is 0.0, that is -inf dB; linear at 1.0 is 0 dB.

Cementum answered 21/3, 2010 at 16:10 Comment(2)
What exactly is 20 here?Benevolent
When measuring sound intensity in air, the reference value is by convention a sound pressure of 20 micropascals (µPa), the textbook value for the average quietest sound that a healthy young human can hear (at a frequency of 1000 Hz) researchgate.net/post/…Demirelief
P
5

Apple also implemented a dB to linear amplitude conversion class MeterTable.cpp and MeterTable.h Look for it in SpeakHere app example.

You can either use their inline function that calculates the value "on-the-fly"

inline double DbToAmp(double inDb);

OR

create a MeterTable instance to use pre-calculated lookup table. This stores conversion values in memory so your application can reduce number of calculations.

float ValueAt(float inDecibels);

NOTE: lookup table is probably needed if you have a lot of other calculations going on at the same time or you need VERY fast processing.

Pitchman answered 19/6, 2010 at 1:17 Comment(2)
And the DbToAmp function returns: pow(10., 0.05 * inDb);Ignite
Also github.com/warrenburton/MeterTableOC if you don't want the slight hassle of c++ files in your projectMicrohenry

© 2022 - 2024 — McMap. All rights reserved.