DSP C++ 音频滤波器
This repo contains some DSP biquad filters used in audio. I've extracted those
filters from the Designing Audio Effect Plug-Ins in C++: With Digital Audio Signal Processing Theory
book that you can find here.
I've also implemented a real-time testing on a Cortex-M4 MCU, using the on-chip ADC and DAC. You can find the post here.
This is the formula I'm using for the digital biquad filter in the source code:
y(n) = a0*x(n) + a1*x(n-1) + a2*x(n-2) - b*y(n-1) + b2*y(n-2)All the filters are now header files and they are located in the lib/ folder.
In order to use them just copy the lib/ folder (and rename it if needed) into
your project folder. There's an example how to build later in the README.
You can use cmake to build the tests. On Linux, you can just run this:
./build_tests.shThe above command will build the tests and run them.
Note: Tests are a bit naive in this case, since it doesn't make much sense for testing using unit-tests, but anyways, I've added them
The filters can be used in your C++ code in the part where the audio sample is about to be processed. You need to include the filter_common.h and filter_includes.h files and the create an object with filter(s) you want to apply and calculate the coefficients with the calculate_coeffs() function. Then in the sample processing function run the filter() function with the current sample as a parameter.
I've used RackAFX to test these filters.
For example, to use the so-LPF filter then first create a main.cpp file
in the top directory of this repo.
touch main.cppThen add this code inside:
…Now to build the file run:
g++ main.cpp -I./libAnd then run the executable:
./a.outThis is will print the filter coefficients and then will process
a sample with the value 0.303. You should see an output similar
to this:
Coeffs:
a0: 0.0228608
a1: 0.0457215
a2: 0.0228608
b1: -1.63163
b2: 0.723069
yn: 0.00692681暂无开放 Issues,或尚未同步最近议题。