zynaddsubfx

ZynAddSubFX open source synthesizer
Log | Files | Refs | Submodules | LICENSE

SVFilter.h (2164B)


      1 /*
      2   ZynAddSubFX - a software synthesizer
      3 
      4   SV Filter.h - Several state-variable filters
      5   Copyright (C) 2002-2005 Nasca Octavian Paul
      6   Author: Nasca Octavian Paul
      7 
      8   This program is free software; you can redistribute it and/or
      9   modify it under the terms of the GNU General Public License
     10   as published by the Free Software Foundation; either version 2
     11   of the License, or (at your option) any later version.
     12 */
     13 
     14 #ifndef SV_FILTER_H
     15 #define SV_FILTER_H
     16 
     17 #include "../globals.h"
     18 #include "Filter.h"
     19 #include "Value_Smoothing_Filter.h"
     20 
     21 namespace zyn {
     22 
     23 class SVFilter:public Filter
     24 {
     25     public:
     26         SVFilter(unsigned char Ftype,
     27                  float Ffreq,
     28                  float Fq,
     29                  unsigned char Fstages,
     30                  unsigned int srate, int bufsize);
     31         ~SVFilter();
     32         void filterout(float *smp);
     33         void setfreq(float frequency);
     34         void setfreq_and_q(float frequency, float q_);
     35         void setq(float q_);
     36 
     37         void settype(int type_);
     38         void setgain(float dBgain);
     39         void setstages(int stages_);
     40         void cleanup();
     41 
     42         struct response {
     43             response(float b0, float b1, float b2,
     44                      float a0, float a1 ,float a2);
     45             float a[3];
     46             float b[3];
     47         };
     48         static response computeResponse(int type,
     49                 float freq, float pq, int stages, float g, float fs);
     50 
     51     private:
     52         struct fstage {
     53             float low, high, band, notch;
     54         } st[MAX_FILTER_STAGES + 1];
     55 
     56         struct parameters {
     57             float f, q, q_sqrt;
     58         } par;
     59 
     60         float *getfilteroutfortype(SVFilter::fstage &x);
     61     void singlefilterout(float *smp, fstage &x, parameters &par, int buffersize );
     62 
     63     void computefiltercoefs(void);
     64         int   type;    // The type of the filter (LPF1,HPF1,LPF2,HPF2...)
     65         int   stages;  // how many times the filter is applied (0->1,1->2,etc.)
     66         float freq; // Frequency given in Hz
     67         float q;    // Q factor (resonance or Q factor)
     68         float gain; // the gain of the filter (if are shelf/peak) filters
     69 
     70     Value_Smoothing_Filter freq_smoothing;
     71 };
     72 
     73 }
     74 
     75 #endif