ruohoruotsi / Butterworth-Filter-Design

C++ classes for designing high-order Butterworth IIR & equalization filters
GNU General Public License v3.0
163 stars 42 forks source link

Add audio processing examples using Biquad and Biquad Chain #2

Open ruohoruotsi opened 10 years ago

ruohoruotsi commented 10 years ago

Add audio processing examples using Biquad and Biquad Chain, to make it explicit how to integrate the toolkit into an external signal processing chain.

A fully working pd or Max/MSP external would be ideal.

JoaCHIP commented 6 years ago

I agree. The example on how to initialize a lowpass filter is great, but - as a novice C++ coder - I'm having serious trouble figuring out how to apply the filter. Obviously I have to call either BiquadChain::processBiquad or BiquadChain::processFourthOrderSections (which one?) but I cannot figure out the syntax to do so.

ruohoruotsi commented 6 years ago

Ok let me get some examples posted for you, with real audio flowing through, gimme a couple of days!

yihe1003 commented 3 years ago

Would you please kindlly post me some examples of audio processing examples using Biquad and Biquad Chain? i want to implement a equalizer using BiquadChain, Thank you so much!

ruohoruotsi commented 3 years ago

Hi there, yes I need to get an example going, I haven't been working on this in a while, but I do have some example code, let me test it out and push a PR for you to look at. thanks for your interest!

Xueqc commented 1 year ago

Would you please kindlly post me some examples of audio processing examples also?

Xueqc commented 1 year ago

Could you point out where am I wrong in following code:

define BUFFER_LEN 1024

define MAX_CHANNELS 6

vector \<Biquad> coeffs;
BiquadChain biquad_chan;

static void process_data (double *data, int count, int channels) { biquad_chan.processBiquad(data, data, 1, count, &coeffs[0]); return ; }

static void read_write_file (const char infilename, const char outfilename) { static double data [BUFFER_LEN] ; SNDFILE infile, outfile ; SF_INFO sfinfo ; int readcount ; memset (&sfinfo, 0, sizeof (sfinfo)) ;

if (! (infile = sf_open (infilename, SFM_READ, &sfinfo)))
{
    printf ("Not able to open input file %s.\n", infilename) ;
    puts (sf_strerror (NULL)) ;
    return;
}

if (sfinfo.channels > MAX_CHANNELS)
{   printf ("Not able to process more than %d channels\n", MAX_CHANNELS) ;
    return;
}
if (! (outfile = sf_open (outfilename, SFM_WRITE, &sfinfo)))
{   printf ("Not able to open output file %s.\n", outfilename) ;
    puts (sf_strerror (NULL)) ;
    return;
}

int filterOrder = 8;
double overallGain = 1.0;

Butterworth butterworth;

bool designedCorrectly = butterworth.loPass(44100,  // fs
    500,
    0,
    filterOrder,
    coeffs,
    overallGain);

biquad_chan.resize(coeffs.size());

while \((readcount = sf_read_double (infile, data, BUFFER_LEN))\)
{   process_data (data, readcount, sfinfo.channels) ;
    sf_write_double (outfile, data, readcount) ;
}
sf_close (infile); sf_close (outfile) ;
return;

}

Xueqc commented 1 year ago

The result wav is noise.

ruohoruotsi commented 1 year ago

Okay, this is an old issue that I previously promised to fix. Let me make an example to share w/ you. I'll also have a look at your code to see what possibly went wrong.

What is the test file that you are using?

Xueqc commented 1 year ago

The test file is your sweep_0_20K.wav