views:

465

answers:

2

Hi,

What is the difference between peakPowerForChannel and averagePowerForChannel methods of AVAudioRecorder?

And why is the value returned is negative? Isn't it supposed to be 0 for no sound and go up when the amplitude of sound rises? How can I convert to a more "readable" format?

Thanks.

+1  A: 

While I've not looked at those values, since it's related to audio volume, I'd guess that it's measured as a change in decibels.

0 would be maximum loudness and anything quieter than that could be expressed as a drop in decibels.

Positive and negative don't matter. Just remember that it's a logarithmic scale where you're measuring the difference in loudness (or perceived loudness).

Nosredna
+2  A: 

Peak power means taking the maximum value of all the absolute values of all the samples. It's useful for preventing clipping of the audio.

Average power is the RMS (root-mean-square) of the samples. This is useful to determine how loud the audio sounds to human ears.

The value is negative because it is expressed in decibels, where 0 dB is equal to the maximum value of the audio system. It's a log10 scale, and the formula for conversion is:

db = 10 * log10 (level);

where db is decibels and level is the scalar value ranging from 0.0 to 1.0. So when the level is 0.0 (silent), the result is negative infinity.

If you want a "readable" format, you can use a level meter (UIProgressView or your own) where the max is 0.0 and the min is -60.0 (you can adjust depending on the noise floor). Once you're used to decibels, they make more sense than linear levels.

lucius