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.cpp

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.cpp,v $
00026  * Date modified: $Date: 2002/04/14 19:51:29 $
00027  * Version:       $Revision: 1.1 $
00028  * -----------------------------------------------------------------
00029  *
00030  ****************** <SYN heading END do not edit this line> ******************/
00031 #include "syn/Core/SampleBufferRepos.h"
00032 #include "syn/Util/Filter.h"
00033 
00034 #include "syn/Module/FilterModule.h"
00035 
00036 namespace syn
00037 {
00038 
00039    FilterModule::FilterModule(): Module(), 
00040          mWriteBuf( NULL ), mCutoff( 1.0f ), mCutoffLo( 220.0f ), 
00041          mCutoffHi( 44100.0f * 0.5f ), mFilterType( LP )
00042    {
00043       mMonoAudioInput = this->createInput( "mono audio" );
00044       mMonoAudioOutput = this->createOutput( "mono audio" );
00045 
00046       this->setCutoff( mCutoffLo / mCutoffHi );
00047    }
00048    
00049    FilterModule::~FilterModule()
00050    {
00051    }
00052 
00053    bool FilterModule::isOpen() { return true; }
00054 
00055    bool FilterModule::open()
00056    {
00057       // configure the output terminals
00058       mMonoAudioOutput->setHighMark( 2 ); 
00059       mMonoAudioOutput->setLowMark( 1 );
00060 
00061       return true;
00062    }
00063    
00064    void FilterModule::close()
00065    {
00066    }
00067 
00068    void FilterModule::update()
00069    {  
00070       this->setPutCount( 0 );
00071       
00072       // if there is stuff to read...
00073       if (!mMonoAudioInput->empty())
00074       {
00075          SampleBuffer1f* read_buf = mMonoAudioInput->front();
00076          mMonoAudioInput->pop();
00077          
00078          // filter it using the requested filter...
00079          switch (mFilterType)
00080          {
00081          case LP:
00082             {
00083                for (unsigned int x = 0; x < read_buf->size(); ++x)
00084                {
00085                   mSimpleLpFilter.filter( (*read_buf)[x] ); 
00086                }
00087             }
00088             break;
00089          case LP2:
00090             {
00091                for (unsigned int x = 0; x < read_buf->size(); ++x)
00092                {
00093                   mSimpleLP.filter( (*read_buf)[x] ); 
00094                }
00095             }
00096          case HP:
00097             {
00098                for (unsigned int x = 0; x < read_buf->size(); ++x)
00099                {
00100                   mSimpleHpFilter.filter( (*read_buf)[x] ); 
00101                }
00102             }
00103             break;
00104          case LPFIR:
00105             {
00106                for (unsigned int x = 0; x < read_buf->size(); ++x)
00107                {
00108                   mFirFilter.filter( (*read_buf)[x] ); 
00109                }
00110             }
00111             break;
00112          }
00113          
00114          this->setPutCount( read_buf->size() );
00115          mMonoAudioOutput->push( read_buf );
00116       }
00117       
00118       mMonoAudioOutput->setDone( false ); // never done...
00119    }
00120 }// end of namespace.

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