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 
00028 
00029 #ifndef CSL_Filters_H
00030 #define CSL_Filters_H
00031 
00032 #define FILTER_MAX_COEFFICIENTS (16)            // seems reasonable?
00033 
00034 #include "CSL_Core.h"
00035 
00036 namespace csl {
00037 
00038 #ifdef CSL_ENUMS
00039 
00040 typedef enum {
00041     BW_LOW_PASS = 0,
00042     BW_HIGH_PASS,
00043     BW_BAND_PASS,
00044     BW_BAND_STOP
00045 } ButterworthType;
00046 #else
00047     #define BW_LOW_PASS 0
00048     #define BW_HIGH_PASS 1
00049     #define BW_BAND_PASS 2
00050     #define BW_BAND_STOP 3
00051     typedef int ButterworthType;
00052 #endif
00053 
00055 
00056 #define DECLARE_FILTER_CONTROLS                                     \
00057     Port * freqPort = mInputs[CSL_FILTER_FREQUENCY];                \
00058     Port * bwPort = mInputs[CSL_FILTER_AMOUNT]
00059 
00061 
00062 #define LOAD_FILTER_CONTROLS                                        \
00063     if (freqPort) Controllable::pullInput(freqPort, numFrames);     \
00064     if (bwPort) Controllable::pullInput(bwPort, numFrames)
00065 
00069 
00070 class FrequencyAmount : public virtual Controllable {
00071 public:     
00072     FrequencyAmount();                              
00073 /*  FrequencyAmount(float frequency, float amount = 1.f);       ///< also specify bandwidth/radius/resonance etc.
00074     FrequencyAmount(UnitGenerator & frequency, float amount = 1.f); 
00075     FrequencyAmount(UnitGenerator & frequency, UnitGenerator & amount);
00076 */  ~FrequencyAmount();                             
00077     
00078                                                     // accessors
00079     void setFrequency(UnitGenerator & frequency);   
00080     void setFrequency(float frequency);
00081 
00082     void setAmount(UnitGenerator & amount);         
00083     void setAmount(float amount);
00084 };
00085 
00087 
00088 class Filter : public Effect, public Scalable, public FrequencyAmount {
00089     
00090 public:
00091     Filter();
00092     Filter(unsigned num_b, unsigned num_a = 1);
00093     Filter(UnitGenerator & in, unsigned num_b = 1, unsigned num_a = 1);
00094     Filter(UnitGenerator & in, SampleBuffer bCoeffs, SampleBuffer aCoeffs, unsigned num_b, unsigned num_a);
00095     ~Filter();
00096 
00097     void clear(void);                               
00098     virtual void setupCoeffs() { };                 
00099 
00100     void setupCoeffs(SampleBuffer bCoeffs, SampleBuffer aCoeffs, unsigned num_b, unsigned num_a );
00101     
00102     virtual void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException);
00103     
00104     void dump();                                    
00105     
00106 protected:
00107     void     init(unsigned a, unsigned b);          
00108 
00109     float mBCoeff[FILTER_MAX_COEFFICIENTS];         
00110     float mACoeff[FILTER_MAX_COEFFICIENTS];         
00111     unsigned mBNum;                                 
00112     unsigned mANum;                                 
00113     Buffer *    mPrevInputs;                        
00114     Buffer *    mPrevOutputs;
00115     float mFrame;                                   
00116 };
00117 
00122 
00123 class Butter : public Filter {
00124     
00125 public:
00126                 // constructors / destructor
00127     Butter ();
00128     Butter (ButterworthType type, float cutoff);
00129     Butter (ButterworthType type, float center, float bandwidth);
00130     Butter (UnitGenerator & in, ButterworthType type, float cutoff);
00131     Butter (UnitGenerator & in, ButterworthType type, UnitGenerator & cutoff);
00132     Butter (UnitGenerator & in, ButterworthType type, float center, float bandwidth);
00133     Butter (UnitGenerator & in, ButterworthType type, UnitGenerator & center, UnitGenerator & bandwidth);
00134                 // Filtering
00135     void setupCoeffs ();
00136 
00137 protected:
00138     int mFilterType;                // flag as to what kind of filter I am
00139 
00140 };
00141 
00148 
00149 class Formant : public Filter {
00150     
00151 public:
00153     Formant (UnitGenerator & in, float center_freq, float radius);
00154     Formant (UnitGenerator & in, UnitGenerator & center_freq, float radius);
00155     ~Formant(void) { };
00156     
00158     void setupCoeffs();
00159     void setNormalize(bool normalize);
00160 
00161 protected:
00162     bool                mNormalize;
00163 };
00164 
00166 
00167 class Notch : public Filter {
00168     
00169 public:
00171     Notch (UnitGenerator & in, float center_freq, float radius);
00172     Notch (UnitGenerator & in, UnitGenerator & center_freq, float radius);
00173     ~Notch(void) { };
00174                 // Filtering
00175     void setupCoeffs ();
00176 
00177 };
00178 
00182 
00183 class Allpass : public Filter {
00184 
00185 public:
00186                 // constructors / destructor
00187     Allpass (UnitGenerator & in, float coeff);
00188     Allpass (UnitGenerator & in, UnitGenerator & coeff);
00189     ~Allpass(void) { };
00190                 // Filtering
00191     void setupCoeffs();
00192     
00193 protected:
00194     UnitGenerator *     mCoeffUGen;
00195     float               mCoeff;
00196     Buffer              mCoeffBuffer;
00197 };
00198 
00200 
00201 class Moog : public Filter {
00202 
00203 public:
00204                 // constructors / destructor
00205     Moog (UnitGenerator & in);
00206     Moog (UnitGenerator & in, UnitGenerator & cutoff);
00207     Moog (UnitGenerator & in, UnitGenerator & cutoff, UnitGenerator & resonance);
00208     Moog (UnitGenerator & in, float cutoff);
00209     Moog (UnitGenerator & in, float cutoff, float resonance);
00210     ~Moog (void) { };
00211                 // Filtering
00212     void setupCoeffs ();
00213     
00214     void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException);  
00215 
00216 protected:
00217     float               k, p, r;    // coefficients
00218     float               x, oldx;
00219     float               y1, y2, y3, y4, oldy1, oldy2, oldy3;
00220     bool                debugging;
00221 };
00222 
00223 }
00224 
00225 #endif

Generated on Thu Sep 17 23:14:15 2009 for CSL by  doxygen 1.5.8