All pastes #805630 Raw Edit

Mine

public cpp v1 · immutable
·published 2007-12-04 15:06 UTC
rendered paste body
class RcFilter{	public:		RcFilter() {			recalcCoeffs(0.5f);		}			// cutoff given = cutoff in Hz / sampleRate		void recalcCoeffs(float cutoff, bool isHighPass = false) 		{			float	x = expf(-2.0f * M_PI * cutoff);					if(isHighPass) {				a0 = (1.0f + x) * 0.5f;				a1 = -a0;				b1 = x;			} else {				a0 = 1.0f - x;				a1 = 0.0f;				b1 = x;			}		}				void process(float* buffer, unsigned int sampleFrames)		{			while(sampleFrames--) {				float	x0 = *buffer;				float	y0 = a0 * x0 + a1 * x1 + b1 * y1;				y1 = y0; x1 = x0; 				*buffer = y0; 				buffer++;			}		}		private:		float	a0, a1, b1;		float	y1, x1;};