/******************************************************************************
** iir.h
*******************************************************************************/
#ifndef IIR_H
#define IIR_H

#include <stdio.h>

#define	pi			3.1415926535897932384626433832795

#define IIR_FILTERTYPE_UNKNOWN     0x00000000
#define IIR_FILTERTYPE_LOWPASS     0x00000001
#define IIR_FILTERTYPE_HIGHPASS    0x00000002
#define IIR_FILTERTYPE_BANDPASS    0x00000003
#define IIR_FILTERTYPE_BANDSTOP    0x00000004
#define IIR_FILTERTYPE_PEAKING     0x00000005
#define IIR_FILTERTYPE_LOWSHELF    0x00000006
#define IIR_FILTERTYPE_HIGHSHELF   0x00000007

#if defined(__cplusplus)
extern "C" {
#endif
/******************************************************************************/
typedef struct _sComplex
{
	float pRealData, pImagData;
} Complex;

typedef struct _sIIRCoeff
{

	float ak0, ak1, ak2;
	float bk0, bk1, bk2;
	float xn1, xn2;
	float yn1, yn2;

}IIRCOEFF;

typedef struct _sIIRParam
{
	/* General Params */
	float fg, Qf;
	
	/* for shelving EQs */
	float beta; 
 
	/* for peaking and shelving EQs */
	float A;
}IIRPARAM;

/******************************************************************************/
void IIRInit(struct _sIIRCoeff *pCoeff, unsigned order);
int IIRCalcPartFilterCoeff1(struct _sIIRCoeff *pCoeff, float fa, float fg, float qp, unsigned filterType);
int IIRCalcPartFilterCoeff2(struct _sIIRCoeff *pCoeff, float A, float fa, float fg, float qp, unsigned filterType);
void IIRCalcFilterCoeff(struct _sIIRCoeff *pCoeff, float fa, float fg, float q, unsigned order, unsigned filterType);

float IIRBilTrans(float fg, float fa);
float IIRCalcQp(unsigned p, unsigned N);
void IIR(struct _sIIRCoeff *pCoeff, float *xn, float *yn, unsigned order, unsigned numPoints);
void IIRPrintCoeff(FILE *pFile, struct _sIIRCoeff *pCoeff, unsigned N);
void ScaleCoeff(struct _sIIRCoeff *pCoeff);
float MinMag(float val1, float val2);
float MaxMag(float val1, float val2);

/******************************************************************************/
#if defined(__cplusplus)
}
#endif

#endif /* IIR_H */
