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 #include <math.h> 20 #include "NoteTable.h" 21 #include "SpiralInfo.h" 22 #include "iir_filter.h" 23 24 #ifndef _FILTER 25 #define _FILTER 26 27 28 class Filter 29 { 30 public: 31 Filter(); 32 ~Filter(); 33 34 void GetOutput(int V, short *data); 35 void Reset(); 36 void SetupCoeffs(); 37 SetCutoff(double s)38 void SetCutoff(double s) {fc=s;} SetResonance(double s)39 void SetResonance(double s) {Q=s;} SetRevCutoffMod(bool s)40 void SetRevCutoffMod(bool s) {m_RevCutoffMod=s;} SetRevResonanceMod(bool s)41 void SetRevResonanceMod(bool s) {m_RevResonanceMod=s;} FilterBypass(bool s)42 void FilterBypass(bool s) {m_FilterBypass=s;} GetCutoff()43 double GetCutoff() {return fc;} GetResonance()44 double GetResonance() {return Q;} GetRevCutoffMod()45 bool GetRevCutoffMod() {return m_RevCutoffMod;} GetRevResonanceMod()46 bool GetRevResonanceMod() {return m_RevResonanceMod;} 47 48 void ModulateCutoff(short *data); 49 void ModulateResonance(short *data); 50 void Randomise(); 51 52 private: 53 54 // Voice specifics 55 FILTER *iir; 56 57 // Voice independant 58 float *coef; 59 double fs, fc; // Sampling frequency, cutoff frequency 60 double Q; // Resonance > 1.0 < 1000 61 unsigned nInd; 62 double a0, a1, a2, b0, b1, b2; 63 double k; // overall gain factor 64 bool m_RevCutoffMod; 65 bool m_RevResonanceMod; 66 bool m_FilterBypass; 67 68 short *m_CutoffModBuf; 69 short *m_ResonanceModBuf; 70 71 friend istream &operator>>(istream &s, Filter &o); 72 friend ostream &operator<<(ostream &s, Filter &o); 73 }; 74 75 istream &operator>>(istream &s, Filter &o); 76 ostream &operator<<(ostream &s, Filter &o); 77 78 #endif 79