Menu

What it takes to turn an iPhone microphone into a decibel meter
📰

What it takes to turn an iPhone microphone into a decibel meter

DEV Community: swift·Johnny Nguyen·2 days ago
#LGpLWfmu
#devtoswift#devto#dev#level#meter
Reading 0:00
15s threshold

I work on Noise Meter at W Lab. It is an iPhone app that shows the sound level in decibels and logs a whole night of it, so someone with a noisy neighbour can show when it was loud. This post is about the measuring part: what happens between the microphone and the number on screen, and the places where I had to be honest about what a phone can't do.

Getting clean samples

iOS processes microphone input by default: automatic gain, noise suppression, EQ. All of that is exactly what a meter must not have, because a quiet room would be boosted and a loud one pulled down. The audio session mode that turns it off is .measurement :

try session . setCategory ( . record , mode : . measurement ) try session . setPreferredSampleRate ( 48_000 )

Enter fullscreen mode

Exit fullscreen mode

From there it is an AVAudioEngine input tap with a 4800-frame buffer, which is 100 ms at 48 kHz. I ask for 48 kHz but build the analyzer for whatever rate the hardware returns.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.