Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

/root/src/subsynth/syn/Module/FilterModule.h

Go to the documentation of this file.
00001 
00002 /****************** <SYN heading BEGIN do not edit this line> *****************
00003  *
00004  * subsynth - modular audio synthesizer
00005  * subsynth is (C) Copyright 2001-2002 by Kevin Meinert
00006  *
00007  * Original Author: Kevin Meinert
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Library General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Library General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Library General Public
00020  * License along with this library; if not, write to the
00021  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00022  * Boston, MA 02111-1307, USA.
00023  *
00024  * -----------------------------------------------------------------
00025  * File:          $RCSfile: FilterModule.h,v $
00026  * Date modified: $Date: 2002/04/15 07:28:46 $
00027  * Version:       $Revision: 1.6 $
00028  * -----------------------------------------------------------------
00029  *
00030  ****************** <SYN heading END do not edit this line> ******************/
00031 
00032 #ifndef SUBSYNTH_FILTER_MODULE_H
00033 #define SUBSYNTH_FILTER_MODULE_H
00034 
00035 #include <map>
00036 #include "syn/Core/SampleBuffer.h"
00037 #include "syn/Core/SampleBufferQueue.h"
00038 #include "syn/Core/Module.h"
00039 #include "syn/Core/Terminal.h"
00040 
00041 #include "syn/Util/Filter.h" // for the filter
00042 
00043 namespace syn
00044 {
00052    class FilterModule : public Module
00053    {
00054    public:
00056       FilterModule();
00057    
00059       virtual ~FilterModule();
00060 
00062       virtual void update();
00063 
00065       virtual bool open();
00066 
00068       virtual bool isOpen();
00069      
00071       virtual void close();
00072 
00074       virtual Module* clone() const
00075       {
00076          FilterModule* mod = new FilterModule;
00077          mod->setFilterType( this->filterType() );
00078          mod->setCutoff( this->cutoff() );
00079          mod->setCutoffLo( this->cutoffLo() );
00080          mod->setCutoffHi( this->cutoffHi() );
00081          return mod;
00082       }
00083 
00084    public:
00085          
00086       enum FilterType
00087       {
00088          NONE, LP, LP2, HP, LPFIR
00089       };
00090       void setFilterType( FilterType t )
00091       {
00092          mFilterType = t;
00093          this->setCutoff( mCutoff );
00094       }
00095       FilterType filterType() const { return mFilterType; }
00096       
00106       void setCutoff( float value = 1.0f )
00107       {
00108          mCutoff = Math::abs( value );
00109          if (mCutoff > 1.0f) mCutoff = 1.0f;
00110          float lerpedHz = mCutoffLo + ((mCutoffHi - mCutoffLo) * mCutoff);
00111          //std::cout<<"cutoff freq: "<<lerpedHz<<" Fc: "<<lerpedHz/44100.0f<<std::endl;
00112          
00113          switch (mFilterType)
00114          {
00115          case LP:
00116             mSimpleLpFilter.setCutoff( lerpedHz, 44100.0f );
00117             break;
00118          case LP2:
00119             mSimpleLP.setCutoff( lerpedHz, 44100.0f );
00120             break;
00121          case HP:
00122             mSimpleHpFilter.setCutoff( lerpedHz, 44100.0f );
00123             break;
00124          case LPFIR:
00125             mFirFilter.setCutoff( lerpedHz, 44100.0f );
00126             break;
00127          }
00128       }
00129 
00136       void setCutoffLo( float hz = 220.0f )
00137       {
00138          mCutoffLo = Math::abs( hz );
00139          this->setCutoff( mCutoff ); // refresh
00140       }
00141 
00148       void setCutoffHi( float hz = 22050.0f )
00149       {
00150          mCutoffHi = Math::abs( hz );
00151          this->setCutoff( mCutoff ); // refresh
00152       }            
00153       
00154       float cutoff() const { return mCutoff; }
00155       float cutoffLo() const { return mCutoffLo; }
00156       float cutoffHi() const { return mCutoffHi; }
00157       
00161       virtual void getParam( const std::string& key, MultivariateType& value )
00162       {
00163          if (key == "cutoff")
00164             value.setValue<float>( this->cutoff() );
00165          else if (key == "cutoffLo")
00166             value.setValue<float>( this->cutoffLo() );
00167          else if (key == "cutoffHi")
00168             value.setValue<float>( this->cutoffHi() );
00169          else if (key == "filter")
00170             value.setValue<unsigned int>( this->filterType() );
00171       }
00172 
00174       virtual void setParam( const std::string& key, const MultivariateType& value )
00175       {
00176          if (key == "cutoff")
00177             this->setCutoff( value.getValue<float>() );
00178          else if (key == "cutoffLo")
00179             this->setCutoffLo( value.getValue<float>() );
00180          else if (key == "cutoffHi")
00181             this->setCutoffHi( value.getValue<float>() );
00182          else if (key == "filter")
00183             this->setFilterType( (FilterType)value.getValue<unsigned int>() );
00184       }
00186       
00187    private:
00188       TerminalPtr mMonoAudioInput;
00189       TerminalPtr mMonoAudioOutput;
00190 
00191       SampleBuffer1f* mWriteBuf;
00192       
00193       FirFilter mFirFilter;
00194       SimpleLowPass mSimpleLpFilter;
00195       SimpleHighPass mSimpleHpFilter;
00196       SimpleLP mSimpleLP;
00197       
00199       float mCutoff, mCutoffLo, mCutoffHi;
00200       FilterType mFilterType;
00201       
00202 
00203 
00205       /*#  Terminal lnkTerminal; */
00206 
00208       /*#  Terminal lnkTerminal; */
00209    };  
00210 }
00211 #endif

Generated at Mon Apr 15 09:26:07 2002 for subsynth by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001