Main Archive Specials Wiki | FAQ Links Submit Forum


1 pole LPF for smooth parameter changes

Type : 1-pole LPF class
References : Posted by zioguido@gmail.com

Notes :
This is a very simple class that I'm using in my plugins for smoothing parameter changes that directly affect audio stream.
It's a 1-pole LPF, very easy on CPU.

Change the value of variable "a" (0~1) for slower or a faster response.

Of course you can also use it as a lowpass filter for audio signals.


Code :
class CParamSmooth
{
public:
CParamSmooth() { a = 0.99f; b = 1.f - a; z = 0; };
~CParamSmooth();
inline float Process(float in) { z = (in * b) + (z * a); return z; }
private:
float a, b, z;
};



Comments


Added on : 30/09/11 by metabogy[ AT ]yahoo[ DOT ]com
Comment :
I've used this a lot, but here's an important thing: it won't work the same for multiple sample rates, so if you set a to 0.9995 for example, this will be lower if the sample rate is higher than you intended. I fix it by doing this:

/*must compensate this factor for sample rate change*/

float srCompensate;
srCompensate = sr/44100.0f;
float compensated_a;
compensated_a = powf(a, (1.0f/srCompensate));
        b = 1.0f-compensated_a;

Then if you start with a built in value (or range) designed for 44100hz, it will scale up with the sample rate so you will get the same amount of smoothing. I'm not sure if this is mathematically correct, but I came up with it very quickly and it works a charm for me.

Good work, very useful and easy to use filter.




Added on : 30/09/11 by metabogy[ AT ]yahoo[ DOT ]com
Comment :
*edit, a won't be LOWER if the sample rate changes, but it won't have the same effect.



Added on : 12/05/12 by jintodarkmage[ AT ]gmail[ DOT ]com
Comment :
You, sir, have relieved so much stress with this program. This is the first thing I have been able to find that makes total sense and is still functional.

Thank you for making my research pay off!




Added on : 09/07/14 by thithisad[ AT ]yahoo[ DOT ]com
Comment :
This is a really interesting contents and useful. Thank you for sharing to us! http://www.a10online.com



Added on : 16/12/14 by alexirae[ AT ]gmail[ DOT ]com
Comment :
New version, now you can specify the speed response of the parameter in ms. and sampling rate:

class CParamSmooth
{
public:
    CParamSmooth(float smoothingTimeInMs, float samplingRate)
    {
        const float c_twoPi = 6.283185307179586476925286766559f;
        
        a = exp(-c_twoPi / (smoothingTimeInMs * 0.001f * samplingRate));
        b = 1.0f - a;
        z = 0.0f;
    }

    ~CParamSmooth()
    {
        
    }

    inline float process(float in)
    {
        z = (in * b) + (z * a);
        return z;
    }

private:
    float a;
    float b;
    float z;
};




Add your own comment
Comments are displayed in fixed width, no HTML code allowed!
Email:

Comment:

Are you human?



Site created and maintained by Bram
Graphic design by line.out | Server sponsered by fxpansion