Search code examples
c++audiopcm

How do I filter out out-of-hearing-range data from PCM samples using C++?


I have raw 16bit 48khz pcm data. I need to strip all data which is out of the range of human hearing.

For now I'm just doing a sum of all samples and then dividing by the sample count to calculate peak sound level, but I need to reduce false positives.

I have big peak level all the time, speaking and other sounds which I can hear increasing levels just a little, so I need to implement some filtering. I am not familiar with sound processing at all, so currently I am not using any filtering because I do not understand how to create it. My current code looks like this:

for(size_t i = 0; i < buffer.size(); i++)
level += abs(buffer[i]);
level /= buffer.size();

How can I implement this kind of filtering using C++?


Solution

  • Use a band pass filter.

    A band-pass filter is a device that passes frequencies within a certain range and rejects (attenuates) frequencies outside that range.

    This sounds like exactly the sort of filter you are looking for.

    I had a quick google search and found this thread that discusses implementation in C++.