SpectralSpread.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 "SpectralSpread.hxx"
00023 #include "ProcessingFactory.hxx"
00024 
00025 namespace CLAM
00026 {
00027 namespace Hidden
00028 {
00029         static const char * metadata[] = {
00030                 "key", "SpectralSpread",
00031         //      "category", "Spectral Transformations",
00032         //      "description", "SpectralSpread",
00033                 0
00034         };
00035         static FactoryRegistrator<ProcessingFactory, SpectralSpread> reg = metadata;
00036 }
00037 
00038 bool SpectralSpread::Do(const Spectrum& 
00039                         inSpec,Spectrum& outSpec)
00040 {
00041 
00042         if (!mConfig.GetPreserveOuts())
00043         {
00044                 outSpec = inSpec; //TODO big cludge for streaming
00045         }
00046         
00047         int spectrumSize = inSpec.GetSize();
00048         TData spectralResolution = spectrumSize/inSpec.GetSpectralRange();
00049         
00050         int centerPoint = Round (mCenterFreqCtl.GetLastValue()*spectralResolution);
00051         int amount= Round(mAmount.GetLastValue()*spectralResolution);
00052         
00053         mBPFSpectrum.SetSize(spectrumSize);
00054         
00055         
00056         //Shift spectral shape
00057         Array<Point>& magBPF=mBPFSpectrum.GetMagBPF().GetPointArray();
00058         //magBPF.SetIntpType(EInterpolation::eLinear);
00059         Array<Point>& phaseBPF=mBPFSpectrum.GetPhaseBPF().GetPointArray();
00060         //phaseBPF.SetIntpType(EInterpolation::eLinear);
00061         
00062         magBPF.SetSize(0);
00063         phaseBPF.SetSize(0);
00064         
00065         DataArray& inMag = inSpec.GetMagBuffer();
00066         DataArray& inPhase = inSpec.GetPhaseBuffer();
00067         
00068         TData binWidth = 1./spectralResolution;
00069         int i;
00070         TData freq = 0;
00071         TData mag;
00072         TData phase;
00073         int nPoints = 0;
00074         for (i=0; i<centerPoint-amount; i++)
00075         {
00076                 mag = inMag[i+amount]; 
00077                 phase = inPhase[i+amount];
00078                 magBPF.AddElem(Point(freq,mag));
00079                 phaseBPF.AddElem(Point(freq, phase));
00080                 freq += binWidth;
00081                 nPoints++;
00082         }
00083         
00084         freq = centerPoint * binWidth;
00085         magBPF.AddElem(Point(freq, inMag[centerPoint]));
00086         phaseBPF.AddElem(Point(freq, inPhase[centerPoint]));
00087         nPoints++;
00088         
00089         freq = (centerPoint+amount)*binWidth;
00090         
00091         for (i=centerPoint+amount ; i<spectrumSize; i++)
00092         {
00093                 mag = inMag[i-amount]; 
00094                 phase = inPhase[i-amount];
00095                 magBPF.AddElem(Point(freq,mag));
00096                 phaseBPF.AddElem(Point(freq, phase));
00097                 freq += binWidth;
00098                 nPoints++;
00099         }
00100         
00101         mBPFSpectrum.SetBPFSize(nPoints);
00102         mBPFSpectrum.SynchronizeTo(mFlag);
00103         outSpec.SetMagBuffer(mBPFSpectrum.GetMagBuffer());
00104         outSpec.SetPhaseBuffer(mBPFSpectrum.GetPhaseBuffer());
00105         
00106         return true;
00107 }
00108 
00109 
00110 }
00111 
Generated by  doxygen 1.6.3