Search code examples
c++audiopcmaudio-processing

detect sound level in raw pcm data


I writing small program which need to detect sound level and write it if level higher than set in settings, i done sound capturing via portaudio, compressing via libvorbis, but one part of program has unfinished and i stuck on it, i need to detect sound level of raw pcm data, i have bad understanding of what pcm data is and does not know any audio analyzing/processing algorithm, is we have existing c/c++ library which can do it ?, or is some simple algorithm which can be implemented in c/c++ exists ?


Solution

  • Look into the Speex and WebRTC libraries... they both have voice-activity-detectors in them. If you're looking for a measure of sound level, you'll need to decide on linear or logarithmic level indicator. A common format for PCM is -32768 to 32767 range (16-bit short)... one simple thing you can do is simply sum up the absolute values of the samples in a period and divide by the number of samples to get an average level for the period.