Hello!

... and a happy new year!

I'm searching for a IIR implementation for LP, BP and HP filters.  Does CLAM 
already implemented such things?

Currently I'm implementing it via SpectralAnalysis/Synth. Unfortunately this 
implementation consumes much cpu power.

Is there already something available in CLAM?

If not: I tried to implement it with the reference of 

http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt

So far so good. It works. As far as I understand, the only tricky part is to 
calculate the coefficients.

For now, all refers to a LP implementation:

That I have done and it is working.. some how:

I have pushed a rectangle-wave throug the filter to explain:

The result is represented in the attached "biquad_nonzerophase.png"
Here you can see that the right edge of the rectangle is somhow flipped.

In "biquad_zerophase.png" you could see how I would expect the filtered signal 
to be. It was created with a SpectralLowPass in the signal-chain. 

This flipped edge is caused by a nonzero phased filter as I read somewhere.
This nonzero phase behaviour could be erased by applying the same filter 
backwards to the signal.

But if I do this, the result is "biquad_nonzerophase_backwards.png". Some 
weird peaks at the corner of each AudioBuffer occour.

If I apply the same filter forwards, everything is fine, like in 
"biquad_nonzerophase.png". 


The filter-code is:

You apply CLAM::Audio Buffer to the filter class and it does the magic within 
filter() - function:

All variables prefixed with an underscore are class-private variables.
Those with an "_bx*" and "_by*" are variables for the backward filter.

The biquad coefficients are applied, of course.

Has someone an particular idea?

Code below.

Thanks in advance,
Karsten Krispin


Code:

void BiQuadFilter::Generic::filter(CLAM::Audio & buffer)
{
        
        CLAM::TData * buf = buffer.GetBuffer().GetPtr();
        CLAM::TSize bufSize = buffer.GetSize();

        CLAM_ASSERT(buf, "Pointer to AudioBuffer is empty");
        
        /* Forward Filter */
        for(int i = 0; i < bufSize; i++)
        {
                _y = _b0 * buf[i] + _b1*_x1 + _b2*_x2 - _a1*_y1 - _a2*_y2;
                _x2 = _x1;
                _x1 = buf[i];
                _y2 = _y1;
                _y1 = _y;

                buf[i] = _y;
        }
        */
        
        /* Backward Filter */
        for(int i = bufSize-1; i >= 0; i--)
        {
                _by     = _b0*buf[i] + _b1*_bx1 + _b2*_bx2 - _a1*_by1 - 
_a2*_by2;
                
                _bx2    = _bx1;
                _bx1    = buf[i];

                _by2    = _by1;
                _by1    = _by;
                
                buf[i] = _by;
        }
}










<<attachment: biquad_nonzerophase_backwards.png>>

<<attachment: biquad_zerophase.png>>

<<attachment: biquad_nonzerophase.png>>

_______________________________________________
Clam-devel mailing list
[email protected]
https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel

Reply via email to