1 /* SpiralSynth 2 * Copyleft (C) 2000 David Griffiths <dave@pawfal.org> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 */ 18 19 /* 20 Resonant low pass filter source code. 21 This code was originally written by baltrax@hotmail.com 22 23 See <http://www.harmony-central.com/Computer/Programming/resonant-lp-filter.c> 24 for the full version with explanatory comments, and the maths! 25 */ 26 27 28 #include <stdlib.h> 29 #include <stdio.h> 30 #include <math.h> 31 32 33 #ifndef _IIR_FILTER 34 #define _IIR_FILTER 35 36 /* FILTER INFORMATION STRUCTURE FOR FILTER ROUTINES */ 37 38 class FILTER{ 39 public: 40 FILTER() {history=coef=NULL;} 41 unsigned int length; /* size of filter */ 42 float *history; /* pointer to history in filter */ 43 float *coef; /* pointer to coefficients of filter */ 44 }; 45 46 #define FILTER_SECTIONS 2 /* 2 filter sections for 24 db/oct filter */ 47 48 typedef struct { 49 double a0, a1, a2; /* numerator coefficients */ 50 double b0, b1, b2; /* denominator coefficients */ 51 } BIQUAD; 52 53 extern BIQUAD ProtoCoef[FILTER_SECTIONS]; /* Filter prototype coefficients, 54 1 for each filter section */ 55 56 float iir_filter(float input,FILTER *iir); 57 58 void szxform( 59 double *a0, double *a1, double *a2, /* numerator coefficients */ 60 double *b0, double *b1, double *b2, /* denominator coefficients */ 61 double fc, /* Filter cutoff frequency */ 62 double fs, /* sampling rate */ 63 double *k, /* overall gain factor */ 64 float *coef); /* pointer to 4 iir coefficients */ 65 66 void prewarp(double *a0, double *a1, double *a2, double fc, double fs); 67 68 void bilinear( 69 double a0, double a1, double a2, /* numerator coefficients */ 70 double b0, double b1, double b2, /* denominator coefficients */ 71 double *k, /* overall gain factor */ 72 double fs, /* sampling rate */ 73 float *coef); 74 75 #endif 76