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