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     float getFrequency();
00082 
00083     void setAmount(UnitGenerator & amount);         
00084     void setAmount(float amount);
00085 };
00086 
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, SampleBuffer bCoeffs, SampleBuffer aCoeffs, unsigned num_b, unsigned num_a);
00098     ~Filter();
00099 
00100     void clear(void);                               
00101     virtual void setupCoeffs() { };                 
00102 
00103     void setupCoeffs(SampleBuffer bCoeffs, SampleBuffer 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 (ButterworthType type, float cutoff);
00132     Butter (ButterworthType 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                 // Filtering
00138     void setupCoeffs ();
00139 
00140 protected:
00141     int mFilterType;                // flag as to what kind of filter I am
00142 
00143 };
00144 
00151 
00152 class Formant : public Filter {
00153     
00154 public:
00156     Formant (UnitGenerator & in, float center_freq, float radius);
00157     Formant (UnitGenerator & in, UnitGenerator & center_freq, float radius);
00158     ~Formant(void) { };
00159     
00161     void setupCoeffs();
00162     void setNormalize(bool normalize);
00163 
00164 protected:
00165     bool                mNormalize;
00166 };
00167 
00169 
00170 class Notch : public Filter {
00171     
00172 public:
00174     Notch (UnitGenerator & in, float center_freq, float radius);
00175     Notch (UnitGenerator & in, UnitGenerator & center_freq, float radius);
00176     ~Notch(void) { };
00177                 // Filtering
00178     void setupCoeffs ();
00179 
00180 };
00181 
00185 
00186 class Allpass : public Filter {
00187 
00188 public:
00189                 // constructors / destructor
00190     Allpass (UnitGenerator & in, float coeff);
00191     Allpass (UnitGenerator & in, UnitGenerator & coeff);
00192     ~Allpass(void) { };
00193                 // Filtering
00194     void setupCoeffs();
00195     
00196 protected:
00197     UnitGenerator *     mCoeffUGen;
00198     float               mCoeff;
00199     Buffer              mCoeffBuffer;
00200 };
00201 
00203 
00204 class Moog : public Filter {
00205 
00206 public:
00207                 // constructors / destructor
00208     Moog (UnitGenerator & in);
00209     Moog (UnitGenerator & in, UnitGenerator & cutoff);
00210     Moog (UnitGenerator & in, UnitGenerator & cutoff, UnitGenerator & resonance);
00211     Moog (UnitGenerator & in, float cutoff);
00212     Moog (UnitGenerator & in, float cutoff, float resonance);
00213     ~Moog (void) { };
00214                 // Filtering
00215     void setupCoeffs ();
00216     
00217     void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException);  
00218 
00219 protected:
00220     float               k, p, r;    // coefficients
00221     float               x, oldx;
00222     float               y1, y2, y3, y4, oldy1, oldy2, oldy3;
00223     bool                debugging;
00224 };
00225 
00226 }
00227 
00228 #endif

Generated on Sat Oct 17 14:12:31 2009 for CSL by  doxygen 1.4.5-20051010