SpectralDelay.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 "SpectralDelay.hxx"
00023 #include "ProcessingFactory.hxx"
00024 
00025 namespace CLAM
00026 {
00027 
00028 namespace Hidden
00029 {
00030         static const char * metadata[] = {
00031                 "key", "SpectralDelay",
00032                 "category", "Spectral Transformations",
00033                 "description", "SpectralDelay",
00034                 0
00035         };
00036         static FactoryRegistrator<ProcessingFactory, SpectralDelay> reg = metadata;
00037 }
00038 
00039 
00040 
00041 bool SpectralDelay::Do(const Spectrum& in, Spectrum& out)
00042 {
00043         if ( !mConfig.GetPreserveOuts() )
00044         {
00045                 out = in; //TODO big cludge for streaming
00046         }
00047         
00048         //first convert from ms to token size
00049         //mFrameSize should  be set somehow in the configuration! It is the difference between one frame center and the next
00050         mFrameSize = 1024;
00051         
00052         
00053         TData lfDelay = mLowDelayCtl.GetLastValue() * in.GetSpectralRange() * 0.002 / mFrameSize;
00054         TData mfDelay = mMidDelayCtl.GetLastValue() * in.GetSpectralRange() * 0.002 / mFrameSize;
00055         TData hfDelay = mHighDelayCtl.GetLastValue() * in.GetSpectralRange() * 0.002 / mFrameSize;
00056         
00057         //these controls could just be connected at the beginning
00058         SendFloatToInControl(mLFDelay,"Delay Control",lfDelay);
00059         SendFloatToInControl(mMFDelay,"Delay Control",mfDelay);
00060         SendFloatToInControl(mHFDelay,"Delay Control",hfDelay);
00061         
00062         //now we are ready to get the appropriate spectrums
00063         mLFDelay.Do(in, mLFSpectrum);
00064         mMFDelay.Do(in, mMFSpectrum);
00065         mHFDelay.Do(in, mHFSpectrum);
00066         
00067         DataArray& hfMag = mHFSpectrum.GetMagBuffer();
00068         DataArray& hfPhase = mHFSpectrum.GetPhaseBuffer();
00069         DataArray& mfMag = mMFSpectrum.GetMagBuffer();
00070         DataArray& mfPhase = mMFSpectrum.GetPhaseBuffer();
00071         DataArray& lfMag = mLFSpectrum.GetMagBuffer();
00072         DataArray& lfPhase = mLFSpectrum.GetPhaseBuffer();
00073         
00074         DataArray& oMag = out.GetMagBuffer();
00075         DataArray& oPhase = out.GetPhaseBuffer();
00076         
00077         int spectrumSize = in.GetSize();
00078         
00079         TData spectralResolution = spectrumSize/in.GetSpectralRange();
00080         
00081         int lowCutoff = Round(mLowCutoffFreqCtl.GetLastValue()* spectralResolution);
00082         int highCutoff = Round(mHighCutoffFreqCtl.GetLastValue()* spectralResolution);
00083 
00084         for(int i = 0; i<spectrumSize; i++)
00085         {
00086                 if(i>highCutoff) 
00087                 {
00088                         oMag[i] = hfMag[i];
00089                         oPhase[i] = hfPhase[i];
00090                 }
00091                 else if(i>lowCutoff)
00092                 {
00093                         oMag[i] = mfMag[i];
00094                         oPhase[i] = mfPhase[i];
00095                 }
00096                 else
00097                 {
00098                         oMag[i] = lfMag[i];
00099                         oPhase[i] = lfPhase[i];
00100                 }
00101         }
00102         return true;
00103 }
00104 
00105 
00106 }
00107 
Generated by  doxygen 1.6.3