OverlapAdd.cxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 #include "OverlapAdd.hxx"
00023 #include "ProcessingFactory.hxx"
00024 
00025 namespace CLAM
00026 {
00027 
00028 namespace Hidden 
00029 {
00030         static const char * metadata[] = {
00031                 "key", "OverlapAdd",
00032                 "category", "Synthesis",
00033                 "description", "OverlapAdd",
00034                 0
00035         };
00036         static FactoryRegistrator<ProcessingFactory, OverlapAdd> reg = metadata;
00037 }
00038 
00039 /* processing object method implementations */
00040 
00041 OverlapAdd::OverlapAdd(const OverlapAddConfig &c)
00042         : mInput( "Audio Input", this ),
00043           mOutput( "Audio Output", this )
00044 {
00045         Configure(c);
00046 }
00047 
00048 OverlapAdd::~OverlapAdd()
00049 {
00050 }
00051 
00052 
00053 /* configure the processing object according to the config object */
00054 
00055 bool OverlapAdd::ConcreteConfigure(const ProcessingConfig& c)
00056 {
00057         CopyAsConcreteConfig(mConfig, c);
00058 
00059 
00060         int frameSize=mConfig.GetFrameSize();
00061 
00062         mInput.SetSize( frameSize*2 );
00063         mInput.SetHop( frameSize*2 );
00064 
00065         mOutput.SetSize( frameSize );
00066         mOutput.SetHop( frameSize );
00067 
00068         mTmp.SetSize( frameSize*2 +1  );
00069 
00070         for(int i=0;i<mTmp.GetSize();i++)
00071                 mTmp.GetBuffer()[i]=0.0f;
00072         
00073         return true;
00074 }
00075 
00076 /* the supervised Do() function */
00077 
00078 bool OverlapAdd::Do(void)
00079 {
00080         bool result = Do( mInput.GetAudio(), mOutput.GetAudio() );
00081         mInput.Consume();
00082         mOutput.Produce();
00083         return result;
00084 }
00085 
00086 bool OverlapAdd::Do( const Audio &in, Audio & out)
00087 {
00088         //xamat: testing
00089   /*    std::cout<<"***OverlapAdd Configuration: "<<std::endl;
00090         std::cout<<"FrameSize: "<<mConfig.GetFrameSize()<<std::endl;
00091         std::cout<<"Input Audio Size: "<<in.GetSize()<<std::endl;
00092         std::cout<<"Output Audio Size: "<<out.GetSize()<<std::endl;
00093   */
00094   // TODO: refactor
00095         int halfSize = in.GetSize()/2;
00096         CLAM_DEBUG_ASSERT( out.GetSize() == halfSize, "OverlapAdd::Do - Audio Out size must be half the input size" );
00097         CLAM_DEBUG_ASSERT( mConfig.GetFrameSize() == halfSize, "OverlapAdd::Do - Config FrameSize must be half the input size" );
00098         
00099         CLAM::DataArray & inBuffer = in.GetBuffer();
00100         CLAM::DataArray & outBuffer = out.GetBuffer();
00101         CLAM::DataArray & tmpBuffer = mTmp.GetBuffer();
00102         const TSize outSize = out.GetSize();
00103         const TSize inSize = in.GetSize();
00104         
00105         
00106         for( int i=0;i<halfSize;i++)
00107         {
00108                 tmpBuffer[i] = tmpBuffer[i+halfSize] + inBuffer[i];
00109         }
00110         
00111         for( int i=halfSize;i<inSize;i++)
00112         {
00113                 tmpBuffer[i] = inBuffer[i];
00114         }
00115         
00116         for( int i=0;i<outSize;i++)
00117         {
00118                 outBuffer[i] = tmpBuffer[i];
00119         }
00120         
00121         return true;
00122 } 
00123 
00124 
00125 } // namespace CLAM
00126 
Generated by  doxygen 1.6.3