Lowpass Filter C/C++

Using Nyquist scripts in Audacity.
Post and download new plug-ins.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
Post Reply
Patrulek
Posts: 8
Joined: Thu Dec 24, 2015 10:09 pm
Operating System: Please select

Lowpass Filter C/C++

Post by Patrulek » Thu Dec 24, 2015 11:15 pm

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!

kozikowski
Forum Staff
Posts: 69374
Joined: Thu Aug 02, 2007 5:57 pm
Operating System: macOS 10.13 High Sierra

Re: Lowpass Filter C/C++

Post by kozikowski » Fri Dec 25, 2015 12:05 am

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.

Koz

Patrulek
Posts: 8
Joined: Thu Dec 24, 2015 10:09 pm
Operating System: Please select

Re: Lowpass Filter C/C++

Post by Patrulek » Fri Dec 25, 2015 12:57 am

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.

kozikowski
Forum Staff
Posts: 69374
Joined: Thu Aug 02, 2007 5:57 pm
Operating System: macOS 10.13 High Sierra

Re: Lowpass Filter C/C++

Post by kozikowski » Fri Dec 25, 2015 1:25 am

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.

Koz

steve
Site Admin
Posts: 81627
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Lowpass Filter C/C++

Post by steve » Fri Dec 25, 2015 2:11 am

Patrulek wrote: is there any possibility to use that filter in my application?
Will your application be open source?
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Patrulek
Posts: 8
Joined: Thu Dec 24, 2015 10:09 pm
Operating System: Please select

Re: Lowpass Filter C/C++

Post by Patrulek » Fri Dec 25, 2015 2:42 pm

Will your application be open source?
Ofcourse, i wanted to share the code anyway if the application would work.

steve
Site Admin
Posts: 81627
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Lowpass Filter C/C++

Post by steve » Fri Dec 25, 2015 9:13 pm

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).

Code: Select all

#define EXPERIMENTAL_SCIENCE_FILTERS
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
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Patrulek
Posts: 8
Joined: Thu Dec 24, 2015 10:09 pm
Operating System: Please select

Re: Lowpass Filter C/C++

Post by Patrulek » Sat Dec 26, 2015 8:23 pm

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.

Post Reply