views:

502

answers:

1

Hello,

I am trying to make a simple volume meter for the iPhone. I want the volume displayed in dB. When using this turorial, I am only getting measurements up to 78 dB. I've read that that is because the dBFS spectrum for 16 bit audio recordings is only 96 dB.

I tried modifying this piece of code in the init funcyion:

dataFormat.mSampleRate = 44100.0f;
dataFormat.mFormatID = kAudioFormatLinearPCM;
dataFormat.mFramesPerPacket = 1;
dataFormat.mChannelsPerFrame = 1;
dataFormat.mBytesPerFrame = 2;
dataFormat.mBytesPerPacket = 2;
dataFormat.mBitsPerChannel = 16;
dataFormat.mReserved = 0;

I changed the value of mBitsPerChannel, hoping to increase the bit value of the recording.

dataFormat.mBitsPerChannel = 32;

With that variable set to 32, the "mAveragePower" function returns only 0.

So, how can i measure more decibels? All my code is practically the same as in the tutorial i posted above.

Thanks in advance, Thomas

+4  A: 

16 bit audio only has a dynamic range of 96 dB, but I suspect you may be getting confused between dB, which is a relative measurement, and dB SPL, which is an absolute measurement of sound pressure level. To measure dB SPL though you will need to calibrate your microphone and audio hardware with some kind of reference. Once you have your input calibrated then it may well be that your 96 dB of dynamic range translates to an absolute range of, say, 44 dB SPL to 140 dB SPL.

See also my answer to a previous similar question on SO: http://stackoverflow.com/questions/2445756/how-can-i-calculate-audio-db-level

Note: definition of dB SPL is sound pressure level relative to 20 µPa (rms).

Paul R
Ok, thank you for your (quick) answer. If I calibrate the measurements to my iPhone microphone, will the measurements on other iPhones also be correct? I do not care if it is a couple of decibels off, I just want to give an indication of the volume of the sounds picked up by the microphone.
Cyber
I would expect that you'll get a few dB variation between iPhones which are the same model (e.g. 3G) but there may be more variation between different models. Note also though that the frequency response will probably not be flat, so your measurements are going to be approximate. One further point to note, you normally use a weighting filter when measuring dB SPL (e.g. A weighting). Oh, and one more thing: there may be AGC circuitry in some or all iPhone models, which may confound your measurements unless you can disable it.
Paul R