CircularShift.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 "Audio.hxx"
00023 #include "Spectrum.hxx"
00024 #include "Complex.hxx"
00025 #include "CircularShift.hxx"
00026 
00027 namespace CLAM {
00028 
00029         /* Processing  object Method  implementations */
00030 
00031         CircularShift::CircularShift()
00032                 : mInput( "Input samples", this ),
00033                   mOutput( "Shifted samples", this ),
00034                   mSteps( "Shift Steps", this )
00035         {
00036                 Configure(CircularShiftConfig());
00037         }
00038 
00039         CircularShift::CircularShift(const CircularShiftConfig &c)
00040                 : mInput( "Input samples", this ),
00041                   mOutput( "Shifted samples", this ),
00042                   mSteps("Shift Steps",this)
00043         {
00044                 Configure(c);
00045         }
00046 
00047         CircularShift::~CircularShift()
00048         {}
00049 
00050 
00051         /* Configure the Processing Object according to the Config object */
00052 
00053         bool CircularShift::ConcreteConfigure(const ProcessingConfig& c)
00054         {
00055                 CopyAsConcreteConfig(mConfig, c);
00056                 mSteps.DoControl(TData(mConfig.GetAmount()));
00057 
00058                 return true;
00059         }
00060 
00061         /* Setting Prototypes for faster processing */
00062 
00063         bool CircularShift::SetPrototypes(Spectrum& inputs,const Spectrum& out)
00064         {
00065                 return false;
00066         }
00067 
00068         bool CircularShift::SetPrototypes()
00069         {
00070                 return false;
00071         }
00072 
00073         bool CircularShift::UnsetPrototypes()
00074         {
00075                 return false;
00076         }
00077 
00078         /* The supervised Do() function */
00079 
00080         bool CircularShift::Do(void)
00081         {
00082                 return Do( mInput.GetAudio(), mOutput.GetAudio() );
00083                 mInput.Consume();
00084                 mOutput.Produce();
00085 
00086         }
00087 
00088         /* The  unsupervised Do() function */
00089 
00090         bool CircularShift::Do( const DataArray& in, DataArray& out)
00091         {
00092 
00093                 int i;
00094                 TData amount = mSteps.GetLastValue();
00095                 int size = in.Size();
00096                 const TData* inp = in.GetPtr();
00097                 TData* outp = out.GetPtr();
00098                 TData* tmp;
00099 
00100                 CLAM_ASSERT(size == out.Size(),
00101                         "CircularShift::Do(): input and output vectors do not  match");
00102 
00103                 if (amount > 0) {
00104                         int ia = (int)amount;
00105                         tmp = new TData[ia];
00106                         for (i=0;i<ia;i++)
00107                                 tmp[i] = inp[size - ia + i];
00108                         for (i=size-ia-1;i>= 0;i--)
00109                                 outp[i + ia] = inp[i];
00110                         for (i=0;i< ia;i++)
00111                                 outp[i] = tmp[i];
00112                 }
00113                 else {
00114                         int ia = (int)-amount;
00115                         tmp = new TData[ia];
00116                         for (i=0;i<ia;i++)
00117                                 tmp[i] = inp[i];
00118                         for (i=0;i< (size - ia);i++)
00119                                 outp[i] = inp[i+ia];
00120                         for (i=0;i< ia;i++)
00121                                 outp[i+size-ia] = tmp[i];
00122                 }
00123                 delete[] tmp;
00124                 return true;
00125         }
00126 
00127         bool CircularShift::Do(Spectrum& in, Spectrum& out)
00128         {
00129                 CLAM_ASSERT(!in.HasMagBuffer(),
00130                         "CircularShift::Do(): only implemented for Spectrums with MagBuffer");
00131 
00132                 return Do(in.GetMagBuffer(),out.GetMagBuffer());
00133         }
00134 
00135         bool CircularShift::Do( const Audio& in, Audio& out)
00136         {
00137                 Do(in.GetBuffer(),out.GetBuffer());
00138                 return true;
00139         }
00140 
00141 
00142 }
00143 
Generated by  doxygen 1.6.3