开发者

Getting decibel from an Android microphone

I have been searching for quite some time now, and I haven't been able to find a way to actually get an SPL/db value from a microphone on Android.

The few threads and articles that I have found that discussed it treated it like something so obvious that anyone should be able to do it, and were more concerned with g开发者_StackOverflow中文版etting their conversion algorithms correct.

Does anyone know how to do this?


While working on other related apps, and doing research, I have come across some information that would be useful to anyone who is looking into something such as this.

You see, the microphone on an Android phone will return a value between 0 and +- 32,400. For the most part, anything over 2,000 is really loud, such as a concert, club, or mechanical noise. "Relative Silence" is around 30. However, these values' meanings are relative, and will differ from phone to phone. Several devices sitting right next to each other will return different values, because of the microphones in them. The values can differ a little, or a lot.

Just testing several different android powered phones in my office, I have found that some devices would return values 10× that of other devices in the same situation. This is why there hasn't been anyone who has just said "Yeah, you can get the decibel value, here's some sample code:" because there is NOT really a reliable (and easy) way TO do it, realistically.

If you uploaded it on one device, you could get, say, 30 dB, but another would return 300dB. Clearly, no human would be in an evironment with 300 dB without massive ear protection. The values have to be taken as relative values; how they relate to each other. "Calibration", whether dynamic or otherwise, is a must if you want to get values that you can use. There has to be an established baseline, that cannot come from you, which has to be compared to a value from you. For example, relative silence, as stated before, should be around 30.

If the phone returns 456 in a relative silence environment, then simply divide yours (30) by theirs (456), and you have a factor that will serve as adjusting the values returned by the phone so that they match what you are expecting to see, and those values can be used for some degree of reliability.

This is just what I have found over the past few months, I hope it helps someone.


You would have to first disable any automatic level control. I assume you either know, or know where to look to find out how to record samples from the microphone without ALC.

From then on, its basically all about the calibration and log magnitude. Essentially you will multiply or convolve by a frequency-dependent calibration and then take 10 * the log magnitude over all or some of the frequency range.

Then you'd have to take some calibration measurements, for example frequency sweeping a lab source of controlled, known spl and recording the resulting amplitude vs frequency (which if you sweep slowly is essentially the same as amplitude vs. time) or you'd hit it with a wideband pseudo impulse (such as an electric spark, starter pistol, whatever) that you are also measuring across frequency with good lab equipment in a radiation-symmetric position, or as a last resort you use some known physical property of the source to estimate the SPL and just hope it's flat enough across frequencies of interest.

You then have two choices for how to apply the correction.

One option is to invert the transfer function, calculate the time domain impulse response, and then use that as a digital filter by convolving it with an input signal to apply a frequency-flatness-correction. You can then take the log magnitude of the result per unit time to determine wideband spl.

Or you can do an FFT on the input data to generate a frequency spectrum, and multiply that by the inverse of your frequency response, and take the log magnitude of whatever (sum of) bin(s) is interesting.

Unfortunately, there's little reason to assume more than crude consistency from device to device, even of the same model.


The open source app NoiseTube does this, including support for device specific calibration. Source code is available here. If you can access it I strongly recommend reading their article Participatory noise mapping works! An evaluation of participatory sensing as an alternative to standard techniques for environmental monitoring (available for pay).

Some highlights from the source:

  • Getting audio samples from the mic

  • Calculating Leq (see LEQ on Wikipedia)

  • A-weighing (see Weighting filter on Wikipedia)

  • Calibration

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜