How to get the reading of deciBels from iOS AVAudioRecorder in a correct scale?
Asked Answered
P

1

11

I'm trying to obtain a noise level in my iOS app, using AVAudioRecorder.

The code I'm using is:

    [self.recorder updateMeters];
    float decibels = [self.recorder averagePowerForChannel:0]; 
    // 160+db here, to scale it from 0 to 160, not -160 to 0. 
    decibels = 160+decibels; 
    NSLog(@"Decibels: %.3f", decibels);

The readings I get, when the phone sits on my desk are at about 90-100dB.

I checked this this link and the table I saw there shows that:

Vacuum Cleaner - 80dB
Large Orchestra - 98dB
Walkman at Maximum Level - 100dB
Front Rows of Rock Concert - 110dB

Now, however my office might seem to be a loud one, it's not near the walkman at maximum level.

Is there something I should do here to get the correct readings? As it seems my iPhone's mic is very sensitive. It's an iPhone4S, if it makes a difference.

Precedence answered 30/9, 2012 at 14:56 Comment(0)
N
4

Forget my previous answer. I figured out a better solution (correct me if I am wrong). I think what both of us want to achieve is the decibel SPL but the averagePowerChannel method gives us the mic's output voltage. The decibel SPL is a logarithmic unit that indicates ratio. We need to convert that output in decibel SPL which is not so easy because for that you need reference values. In other words you need a DB SPL values and the according voltage values to them. You can also try to estimate them by comparing your results with an app like decibel Ultra. To come straight to the point: The formula you need is as follows:

SPL = 20 * log10(referenceLevel * powf(10, (averagePowerForChannel/20)) * range) + offset;

you can set the referenceLevel to 5. That gives me good results on my iPhone. The averagePowerForChannel is the value you gain from the method averagePowerForChannel: method and range indicates the upper limit of the range. I set that to 160. Finally offset is an offset you can add to get into the area you want. I added 50 here.

Still, if anybody got a better solution to this. It would be great!

Nomanomad answered 30/10, 2012 at 9:29 Comment(4)
I think you mean: SPL = 20 * log10(referenceLevel * powf(10, (averagePowerForChannel/20)) * range) + offset; A ")" is missing in your formula.Tell me if I am wrong.Squire
the middle part of your expression is log10( powf( 10, avgPow/20 ) ). Isn't this the same thing as avgPow/20 since the log and pow cancel?Sateia
yeah, you are right. But don't forget the other variables multiplied with the powf() function. You could also write 20 * (log10(referenceLevel) + averagePowerForChannel/20 + log10(range)) + offset which should return the same result.Nomanomad
The formula float linear = pow (10, decibels / 20); works great for me. I found it here: https://mcmap.net/q/1126588/-iphone-sdk-avaudiorecorder-metering-how-to-change-peakpowerforchannel-from-decibel-into-percentageKinslow

© 2022 - 2024 — McMap. All rights reserved.