Filters.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 #ifndef CSL_Filters_H
00028 #define CSL_Filters_H
00029 
00030 #define FILTER_MAX_COEFFICIENTS (16)    // seems reasonable?
00031 
00032 #include "CSL_Core.h"
00033 
00034 namespace csl {
00035 
00036 #ifdef CSL_ENUMS
00037 
00038 typedef enum {
00039     BW_LOW_PASS = 0,
00040     BW_HIGH_PASS,
00041     BW_BAND_PASS,
00042     BW_BAND_STOP
00043 } ButterworthType;
00044 #else
00045     #define BW_LOW_PASS 0
00046     #define BW_HIGH_PASS 1
00047     #define BW_BAND_PASS 2
00048     #define BW_BAND_STOP 3
00049     typedef int ButterworthType;
00050 #endif
00051 
00052 #define CSL_FILTER_FREQUENCY 4
00053 #define CSL_FILTER_AMOUNT 5
00054 
00056 
00057 #define DECLARE_FILTER_CONTROLS                     \
00058     Port * freqPort = mInputs[CSL_FILTER_FREQUENCY];        \
00059     Port * bwPort = mInputs[CSL_FILTER_AMOUNT]
00060 
00062 
00063 #define LOAD_FILTER_CONTROLS                        \
00064     Controllable :: pullInput(freqPort, numFrames);     \
00065     Controllable :: pullInput(bwPort, numFrames)
00066 
00072 
00073 class FrequencyAmount : public virtual Controllable {
00074 public:     
00075     FrequencyAmount();                      
00076 /*  FrequencyAmount(float frequency, float amount = 1.f);   ///< also specify bandwidth/radius/resonance etc.
00077     FrequencyAmount(UnitGenerator & frequency, float amount = 1.f); ///< also specify bandwidth/radius/resonance etc.
00078     FrequencyAmount(UnitGenerator & frequency, UnitGenerator & amount); ///< also specify bandwidth/radius/resonance etc.
00079 */  ~FrequencyAmount();                     
00080     
00081                                     // accessors
00082     void setFrequency(UnitGenerator & frequency);   
00083     void setFrequency(float frequency);
00084 
00085     void setAmount(UnitGenerator & amount);         
00086     void setAmount(float amount);
00087 };
00088 
00090 
00091 class Filter : public Effect, public Scalable, public FrequencyAmount {
00092     
00093 public:
00094     Filter();
00095     Filter(unsigned num_b, unsigned num_a = 1);
00096     Filter(UnitGenerator & in, unsigned num_b = 1, unsigned num_a = 1);
00097     Filter(UnitGenerator & in, sample * bCoeffs, sample * aCoeffs, unsigned num_b, unsigned num_a);
00098     ~Filter();
00099 
00100     void clear(void);                       
00101     virtual void setupCoeffs() {};          
00102 
00103     void setupCoeffs(sample * bCoeffs, sample * aCoeffs, unsigned num_b, unsigned num_a );
00104     
00105     virtual void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException);
00106     
00107     void dump();                                        
00108     
00109 protected:
00110     void     init(unsigned a, unsigned b);                  
00111 
00112     float mBCoeff[FILTER_MAX_COEFFICIENTS];         
00113     float mACoeff[FILTER_MAX_COEFFICIENTS];         
00114     unsigned mBNum;                             
00115     unsigned mANum;                             
00116     Buffer *    mPrevInputs;                            
00117     Buffer *    mPrevOutputs;
00118     float mFrame;                                   
00119 };
00120 
00125 
00126 class Butter : public Filter {
00127     
00128 public:
00129                 // constructors / destructor
00130     Butter ();
00131     Butter (int type, float cutoff);
00132     Butter (int type, float center, float bandwidth);
00133     Butter (UnitGenerator & in, ButterworthType type, float cutoff);
00134     Butter (UnitGenerator & in, ButterworthType type, UnitGenerator & cutoff);
00135     Butter (UnitGenerator & in, ButterworthType type, float center, float bandwidth);
00136     Butter (UnitGenerator & in, ButterworthType type, UnitGenerator & center, UnitGenerator & bandwidth);
00137     
00138                 // Filtering
00139     void setupCoeffs ();
00140 
00141 protected:
00142     int mFilterType;                // flag as to what kind of filter I am
00143 
00144 };
00145 
00152 
00153 class Formant : public Filter {
00154     
00155 public:
00157     Formant (UnitGenerator & in, float center_freq, float radius);
00158     Formant (UnitGenerator & in, UnitGenerator & center_freq, float radius);
00159     ~Formant(void) {};
00160     
00162     void setupCoeffs();
00163     void setNormalize(bool normalize);
00164 
00165 protected:
00166     bool                mNormalize;
00167 };
00168 
00170 
00171 class Notch : public Filter {
00172     
00173 public:
00175     Notch (UnitGenerator & in, float center_freq, float radius);
00176     Notch (UnitGenerator & in, UnitGenerator & center_freq, float radius);
00177     ~Notch(void) {};
00178                 // Filtering
00179     void setupCoeffs ();
00180 
00181 };
00182 
00186 
00187 class Allpass : public Filter {
00188 
00189 public:
00190                 // constructors / destructor
00191     Allpass (UnitGenerator & in, float coeff);
00192     Allpass (UnitGenerator & in, UnitGenerator & coeff);
00193     ~Allpass(void) {};
00194                 // Filtering
00195     void setupCoeffs();
00196     
00197 protected:
00198     UnitGenerator *     mCoeffUGen;
00199     float               mCoeff;
00200     Buffer              mCoeffBuffer;
00201 
00202 
00203 };
00204 
00205 // Moog VCF class
00206 
00207 class Moog : public Filter {
00208 
00209 public:
00210                 // constructors / destructor
00211     Moog (UnitGenerator & in);
00212     Moog (UnitGenerator & in, UnitGenerator & cutoff);
00213     Moog (UnitGenerator & in, UnitGenerator & cutoff, UnitGenerator & resonance);
00214     Moog (UnitGenerator & in, float cutoff);
00215     Moog (UnitGenerator & in, float cutoff, float resonance);
00216     ~Moog (void) {};
00217                 // Filtering
00218     void setupCoeffs ();
00219     
00220     void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException);  
00221 
00222 protected:
00223     float               k, p, r;    // coefficients
00224     float               x, oldx;
00225     float               y1, y2, y3, y4, oldy1, oldy2, oldy3;
00226     bool                debugging;
00227 
00228 };
00229 
00230 }
00231 
00232 #endif

Generated on Fri Apr 6 20:18:13 2007 for CSL by  doxygen 1.4.5-20051010