Lowpass Filter C/C++

Hi, at the beginning i need to say, that im not familiar with DSP/Sound/Nyquist programming but i want to try some of that in my application. I code in C++ with QT an application to detect bass hits and i have a problem with filtering low frequencies from captured audio. As i said, im not familiar with DSP, so i just took a few of implementations of low pass filters and tried apply that on captured audio. That worked, but anyway i couldn’t achieve smooth signal as it would be filtered in Audacity. I did some digging and found out that the source code is available online so i wanted to try that in my app. I looked at code and noticed that for low pass filter with 48db attenuation i need to use ‘lowpass8’ which use functions from Nyquist library written in c. And here is my question: is there any possibility to use that filter in my application? Is there any port or could i rewrite this for my use? If not, what is the other way to achieve so smooth filtered signal? Thanks in advance!

Did you get what you wanted with the pre-baked Audacity filters and effects? I only ask that because what you want isn’t particularly easy.

Detecting the presence of bass notes is different from the “hit” at the beginning. The hit kills you in processing because that sound is shared by other instruments. So you can get sloppy, badly defined, isolated bass notes, or you can get a snappy clear bass note with leakage from other instruments.

This effect is what prevents software from separating instruments from each other in a mixed performance. No, it’s not just find the notes and you’re done.


Yes, Audacity filter do the job much better than other filters i tested, and i just want to receive that smooth signal in my app for further analysis. And i should be more precise… i dont want just to get bass notes and by bass hits i mean melodic bass and percussion kicks/snares (just sounds < ~300hz). I want to detect whether there was a hit or not in example by calculating differences in average volume and volume in current analyzed block of samples.

Yes, Audacity filter do the job much better than other filters i tested

I didn’t want you going into a long code research project with the wrong or unmanageable goal.

If you work on the forum enough, you learn to “read into” postings more than what the words say.


Will your application be open source?

Will your application be open source?

Ofcourse, i wanted to share the code anyway if the application would work.

The “lowpass8” function that you refer to is, as you say, part of the Nyquist library. I believe that it would be possible to use the Nyquist library within a c++ / QT application , though if you are just wanting to use a few filters then it is probably overkill to do so. Basic IIR filters like Nyquist’s “lowpass” and “highpass” filters are not very difficult to implement directly in C++.

Take a look at the code for the “Bass and Treble” effect, in particular the functions EffectBassTreble::ProcessBlock, EffectBassTreble::Coefficents and EffectBassTreble::DoFilter. The Bass and Treble effect implements a low-shelf filter and a high-shelf filter.

Also look at ScienFilter.cpp (this is a set of filters that are not currently included in Audacity, but may be built by un-commenting the define in Experimental.h (then rebuild Audacity).


There is an excellent free on-line book called “The Scientist and Engineer’s Guide to Digital Signal Processing” By Steven W. Smith. http://www.dspguide.com/pdfbook.htm

Very thanks for Your comprehensive answer Steve. I’ll try some things you mentioned and maybe try to rewrite Nyquist’s filters if it would be needed. If i’ll make some progress or need some help i’ll post here. Once again, thanks.