view include/IirFilter.h @ 151:e9c9404e3d1f ClockSync

Pff partially working. No PID. When setting the audio clock on the bbb to 44098 the master and slave clock keep diverging instead of converging ...
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 22 Sep 2015 04:10:07 +0100
parents 6cd38e261027
children
line wrap: on
line source
/*
 * IirFilter.h
 *
 *  Created on: 17 Sep 2015
 *      Author: giulio
 */

#ifndef IIRFILTER_H_
#define IIRFILTER_H_

#define IIR_FILTER_STAGE_COEFFICIENTS (5)
#define IIR_FILTER_STAGE_STATES (IIR_FILTER_STAGE_COEFFICIENTS - 1)

class IirFilterStage{ //TODO : to save (some) memory we should only store the coefficients pointers here,
						//so that IirFilter can share them among multiple stages if needbe)
private:
	double coefficients[IIR_FILTER_STAGE_COEFFICIENTS]; // these are b0,b1,b2,a1,a2
	double states[IIR_FILTER_STAGE_STATES]; // these are xprev, xprevprev, yprev, yprevprev
public:
	IirFilterStage();
	void setCoefficients(double* newCoefficients);
	void setStates(double* newStates);
	double process(double in);
	void process(double* inout, int length);
	void process(double* in, double* out, int length);
};

class IirFilter{
private:
	struct IirFilterStage** stages;
	int numberOfStages;
	void dealloc();
public:
	IirFilter();
	IirFilter(int newNumberOfStages);
	IirFilter(int newNumberOfStages, double *newCoefficients);
	void setCoefficients(double* newCoefficients);
	void setStates(double* newStates);
	void setNumberOfStages(int newNumberOfStages);
	double process(double in);
	void process(double* inout, int length);
	void process(double* in, double* out, int length);
};

#endif /* IIRFILTER_H_ */