SpectralEnvelopeApply.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 "Complex.hxx"
00023 #include "SpectralEnvelopeApply.hxx"
00024 
00025 #define CLASS "SpectralEnvelopeApply"
00026 
00027 namespace CLAM {
00028 
00029         /* Processing  object Method  implementations */
00030 
00031         SpectralEnvelopeApply::SpectralEnvelopeApply()
00032         {
00033                 Configure(SpectralEnvelopeApplyConfig());
00034         }
00035 
00036         SpectralEnvelopeApply::SpectralEnvelopeApply(const SpectralEnvelopeApplyConfig &c = SpectralEnvelopeApplyConfig())
00037         {
00038                 Configure(c);
00039         }
00040 
00041         SpectralEnvelopeApply::~SpectralEnvelopeApply()
00042         {}
00043 
00044 
00045         /* Configure the Processing Object according to the Config object */
00046 
00047         bool SpectralEnvelopeApply::ConcreteConfigure(const ProcessingConfig& c)
00048         {
00049 
00050                 CopyAsConcreteConfig(mConfig, c);
00051                 return true;
00052         }
00053 
00054         /* Setting Prototypes for faster processing */
00055 
00056         bool SpectralEnvelopeApply::SetPrototypes(const SpectralPeakArray& input,Spectrum& output)
00057         {
00058                 return true;
00059         }
00060 
00061         bool SpectralEnvelopeApply::SetPrototypes()
00062         {
00063                 return true;
00064         }
00065         
00066         bool SpectralEnvelopeApply::UnsetPrototypes()
00067         {
00068                 return true;
00069         }
00070 
00071         /* The supervised Do() function */
00072 
00073         bool  SpectralEnvelopeApply::Do(void) 
00074         {
00075                 CLAM_ASSERT(false,CLASS"::Do(): Supervised mode not implemented");
00076                 return false;
00077         }
00078 
00079         /* The  unsupervised Do() function */
00080         bool  SpectralEnvelopeApply::Do(const SpectralPeakArray& input, const Spectrum& spectralEnvelope, SpectralPeakArray& output)
00081         {
00082                 output.SetScale(input.GetScale());
00083                 CLAM_ASSERT(input.GetScale()==spectralEnvelope.GetScale(),"You are trying to apply an envelope that has a different scale");
00084                                 
00085                 TSize nPeaks=input.GetnPeaks();
00086                 //Unused variable: DataArray& imagBuffer=input.GetMagBuffer();
00087                 DataArray& iphaseBuffer=input.GetPhaseBuffer();
00088                 DataArray& ifreqBuffer=input.GetFreqBuffer();
00089 
00090                 if(output.GetnMaxPeaks()!=input.GetnMaxPeaks())
00091                         output.SetnMaxPeaks(input.GetnMaxPeaks());
00092                 if(output.GetnPeaks()!=input.GetnPeaks())
00093                         output.SetnPeaks(input.GetnPeaks());
00094                 
00095                 DataArray& omagBuffer=output.GetMagBuffer();
00096                 DataArray& ophaseBuffer=output.GetPhaseBuffer();
00097                 DataArray& ofreqBuffer=output.GetFreqBuffer();
00098 
00099                 int i;
00100                 
00101                 BPF& env = spectralEnvelope.GetMagBPF();
00102                 for(i=0;i<nPeaks;i++)
00103                 {
00104                         ophaseBuffer[i]=iphaseBuffer[i];
00105                         omagBuffer[i]=env.GetValue(ifreqBuffer[i]);
00106                         ofreqBuffer[i]=ifreqBuffer[i];
00107                 }
00108                 
00109                 return true;
00110         }
00111 
00112         /* The  unsupervised Do() function */
00113         bool  SpectralEnvelopeApply::Do(const Spectrum& input, const Spectrum& spectralEnvelope, Spectrum& output)
00114         {
00115                 output.SetScale(input.GetScale());
00116                 CLAM_ASSERT(input.GetScale()==spectralEnvelope.GetScale(),"You are trying to apply an envelope that has a different scale");
00117                 
00118                 output=input;
00119                 
00120                 int spectrumSize=input.GetSize();
00121                 
00122                 int i;
00123                 TData delta = input.GetSpectralRange()/(spectrumSize-1);
00124                 DataArray& outMag = output.GetMagBuffer();
00125                 BPF& env = spectralEnvelope.GetMagBPF();
00126                 
00127                 TData currentFreq = 0.;
00128                 for(i=0;i<spectrumSize;i++, currentFreq+=delta)
00129                 //for(i=0;currentFreq<10000;i++, currentFreq+=delta)
00130                 {
00131                         //std::cout<<outMag[i] << " will be " << env.GetValue(currentFreq) <<std::endl;
00132                         outMag[i] = env.GetValue(currentFreq);
00133                         
00134                         //output.SetMag(i,spectralEnvelope.GetMag((TData)i*delta));
00135                 }
00136 
00137 
00138                 return true;
00139         }
00140 
00141 
00142 };//namespace CLAM
00143 
Generated by  doxygen 1.6.3