weighted (or B or C) SPL decibel iOS

How can I calculate A-weighted and C-weighted dB sound levels from the microphone on iOS?

Here is what I have tried, but the reading I get is far below the sound level meter I have next to my iPhone:

  • Using the Novocain library, which I have slightly modified to set the audio session mode to Measurement.
  • Using the Maximilian audio library to run the incoming audio frames through an FFT and converting the amplitudes into dB.
  • Using the Maximilian audio libraries's Octave Analyser to place the FFT output into octave bins from 10hz to 20480hz.
  • For each octave bin I am apply a db gain of the relevant dB-weighing (eg apply -70.f db gain to the db value stored in the 10hz bin to get an A-weighted dB gain).
  • Added the db values of each bin together by reducing each dB bin to an amplitude, and the gain to an an amplitude, making the addition, and converting back to a dB value again.
  • Is this on the correct track, I have my doubts? Can someone outline an approach? Suggest a library and/or other example (I have looked).

    To note – I would like approximate dB(A) and dB(C) values, this does not need to be scientific. Not sure how to compensate for the frequency response of the microphone, could the above technique be correct if it were compensating for the response of the microphone?


    I don't think you can measure physical Sound Pressure Levels from a device. In step 2 you "convert the amplitudes into dB." However the amplitude that you record from the device has arbitrary units. When recording 16-bit audio, the audio is represented as numbers in the range -32768 to +32767. If you are working with floating point data then this is normalised by 32768 so that it has a range of (approximately) -1 to +1.

    The device's microphone has to cope with a wide variety of sound levels. Generally devices will have some form of Automatic Gain Control which adapts to the current average sound level. This means that if you measure a peak value of 1.0 then you have no way of knowing the actual SPL it corresponded to. You can convert a recording to a series of dBs, but this uses a different definition of dB: as a power ratio. This has no correlation with SPL measurements such as dB(A).

    It may be possible to produce an approximate dB(A) measurement if you are able to turn off the AGC and calibrate your device against your sound meter

    EDIT: JASA have published a paper with a detailed comparison of existing SPL measurement apps with stats for the comparison of different generations of iPhone: Evaluation of smartphone sound measurement applications

    链接地址: http://www.djcxy.com/p/33836.html

    上一篇: 输出音频(Windows Audio API)

    下一篇: 加权(或B或C)SPL分贝iOS