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 (e.g. 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?