FrameDescriptors.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 
00023 
00024 
00025 #include "ProcessingData.hxx"
00026 #include "FrameDescriptors.hxx"
00027 #include "Frame.hxx"
00028 
00029 
00030 namespace CLAM{
00031 
00032 FrameDescriptors::FrameDescriptors(Frame* pFrame): Descriptor(eNumAttr)
00033 {
00034         MandatoryInit();
00035         mpFrame=pFrame;
00036 }
00037 
00038 FrameDescriptors::FrameDescriptors(TData initVal): Descriptor(eNumAttr)
00039 {
00040         MandatoryInit();
00041         AddAll();
00042         UpdateData();
00043         SetSpectralPeakD(SpectralPeakDescriptors(initVal));
00044         SetSpectrumD(SpectralDescriptors(initVal));
00045         SetResidualSpecD(SpectralDescriptors(initVal));
00046         SetSinusoidalSpecD(SpectralDescriptors(initVal));
00047         SetAudioFrameD(AudioDescriptors(initVal));
00048         SetSinusoidalAudioFrameD(AudioDescriptors(initVal));
00049         SetResidualAudioFrameD(AudioDescriptors(initVal));
00050         SetSynthAudioFrameD(AudioDescriptors(initVal));
00051 }
00052 
00053 void FrameDescriptors::DefaultInit() {
00054         mpFrame=0;
00055 }
00056 
00057 void FrameDescriptors::CopyInit(const FrameDescriptors & copied) {
00058         mpFrame=copied.mpFrame;
00059 }
00060 
00061 const Frame* FrameDescriptors::GetpFrame() const {
00062         return mpFrame;
00063 }
00064 
00065 void FrameDescriptors::SetpFrame(const Frame* pFrame){
00066         mpFrame=pFrame;
00067         //first we add dynamic attributes doing a single UpdateData
00068         if(mpFrame->HasSpectrum())
00069                 AddSpectrumD();
00070         if(mpFrame->HasSpectralPeakArray())
00071                 AddSpectralPeakD();
00072         if(mpFrame->HasResidualSpec())
00073                 AddResidualSpecD();
00074         if(mpFrame->HasSinusoidalSpec())
00075                 AddSinusoidalSpecD();
00076         if(mpFrame->HasAudioFrame())
00077                 AddAudioFrameD();
00078         if(mpFrame->HasSinusoidalAudioFrame())
00079                 AddSinusoidalAudioFrameD();
00080         if(mpFrame->HasResidualAudioFrame())
00081                 AddResidualAudioFrameD();
00082         if(mpFrame->HasSynthAudioFrame())
00083                 AddSynthAudioFrameD();
00084         UpdateData();
00085         //now we set the data of each descriptor
00086         if(mpFrame->HasSpectrum())
00087                 GetSpectrumD().SetpSpectrum(&mpFrame->GetSpectrum());
00088         if(mpFrame->HasSpectralPeakArray())
00089                 GetSpectralPeakD().SetpSpectralPeakArray(&mpFrame->GetSpectralPeakArray());
00090         if(mpFrame->HasResidualSpec())
00091                 GetResidualSpecD().SetpSpectrum(&mpFrame->GetResidualSpec());
00092         if(mpFrame->HasSinusoidalSpec())
00093                 GetSinusoidalSpecD().SetpSpectrum(&mpFrame->GetSinusoidalSpec());
00094         if(mpFrame->HasAudioFrame())
00095                 GetAudioFrameD().SetpAudio(&mpFrame->GetAudioFrame());
00096         if(mpFrame->HasSinusoidalAudioFrame())
00097                 GetSinusoidalAudioFrameD().SetpAudio(&mpFrame->GetSinusoidalAudioFrame());
00098         if(mpFrame->HasResidualAudioFrame())
00099                 GetResidualAudioFrameD().SetpAudio(&mpFrame->GetResidualAudioFrame());
00100         if(mpFrame->HasSynthAudioFrame())
00101                 GetSynthAudioFrameD().SetpAudio(&mpFrame->GetSynthAudioFrame());
00102 
00103 }
00104 
00105 void FrameDescriptors::Compute()
00106 {
00107         /*Overriding compute method in base class because right now I don't know
00108         what to do with member statistics.*/
00109         ConcreteCompute();
00110 }
00111 
00112 
00113 void FrameDescriptors::ConcreteCompute()
00114 {
00115         if(mpFrame->HasSpectrum())
00116                 GetSpectrumD().Compute();
00117         if(mpFrame->HasSpectralPeakArray())
00118                 GetSpectralPeakD().Compute();
00119         if(mpFrame->HasResidualSpec())
00120                 GetResidualSpecD().Compute();
00121         if(mpFrame->HasSinusoidalSpec())
00122                 GetSinusoidalSpecD().Compute();
00123         if(mpFrame->HasAudioFrame())
00124                 GetAudioFrameD().Compute();
00125         if(mpFrame->HasSinusoidalAudioFrame())
00126                 GetSinusoidalAudioFrameD().Compute();
00127         if(mpFrame->HasResidualAudioFrame())
00128                 GetResidualAudioFrameD().Compute();
00129         if(mpFrame->HasSynthAudioFrame())
00130                 GetSynthAudioFrameD().Compute();
00131         if(HasCenterTime())
00132                 SetCenterTime(mpFrame->GetCenterTime());        
00133 
00134 
00135 }
00136 
00137 FrameDescriptors operator * (const FrameDescriptors& a,const FrameDescriptors& b)
00138 {
00139         FrameDescriptors tmpD;
00140         if(a.HasSpectralPeakD() && b.HasSpectralPeakD())
00141         {
00142                 tmpD.AddSpectralPeakD();
00143                 tmpD.UpdateData();
00144                 tmpD.SetSpectralPeakD(a.GetSpectralPeakD()*b.GetSpectralPeakD());
00145         }
00146         if(a.HasSpectrumD() && b.HasSpectrumD())
00147         {
00148                 tmpD.AddSpectrumD();
00149                 tmpD.UpdateData();
00150                 tmpD.SetSpectrumD(a.GetSpectrumD()*b.GetSpectrumD());
00151         }
00152         if(a.HasResidualSpecD() && b.HasResidualSpecD() )
00153         {
00154                 tmpD.AddResidualSpecD();
00155                 tmpD.UpdateData();
00156                 tmpD.SetResidualSpecD(a.GetResidualSpecD()*b.GetResidualSpecD());
00157         }
00158         if(a.HasSinusoidalSpecD() && b.HasSinusoidalSpecD())
00159         {
00160                 tmpD.AddSinusoidalSpecD();
00161                 tmpD.UpdateData();
00162                 tmpD.SetSinusoidalSpecD(a.GetSinusoidalSpecD()*b.GetSinusoidalSpecD());
00163         }
00164         if(a.HasAudioFrameD() && b.HasAudioFrameD() )
00165         {
00166                 tmpD.AddAudioFrameD();
00167                 tmpD.UpdateData();
00168                 tmpD.SetAudioFrameD(a.GetAudioFrameD()*b.GetAudioFrameD());
00169         }
00170         if(a.HasSinusoidalAudioFrameD() && b.HasSinusoidalAudioFrameD() )
00171         {
00172                 tmpD.AddSinusoidalAudioFrameD();
00173                 tmpD.UpdateData();
00174                 tmpD.SetSinusoidalAudioFrameD(a.GetSinusoidalAudioFrameD()*b.GetSinusoidalAudioFrameD());
00175         }
00176         if(a.HasResidualAudioFrameD() && b.HasResidualAudioFrameD() )
00177         {
00178                 tmpD.AddResidualAudioFrameD();
00179                 tmpD.UpdateData();
00180                 tmpD.SetResidualAudioFrameD(a.GetResidualAudioFrameD()*b.GetResidualAudioFrameD());
00181         }
00182         if(a.HasSynthAudioFrameD() && b.HasSynthAudioFrameD() )
00183         {
00184                 tmpD.AddSynthAudioFrameD();
00185                 tmpD.UpdateData();
00186                 tmpD.SetSynthAudioFrameD(a.GetSynthAudioFrameD()*b.GetSynthAudioFrameD());
00187         }
00188 
00189         return tmpD;
00190 }
00191 
00192 
00193 FrameDescriptors operator + (const FrameDescriptors& a,const FrameDescriptors& b) 
00194 {
00195         FrameDescriptors tmpD;
00196         if(a.HasSpectralPeakD() && b.HasSpectralPeakD())
00197         {
00198                 tmpD.AddSpectralPeakD();
00199                 tmpD.UpdateData();
00200                 tmpD.SetSpectralPeakD(a.GetSpectralPeakD()+b.GetSpectralPeakD());
00201         }
00202         if(a.HasSpectrumD() && b.HasSpectrumD())
00203         {
00204                 tmpD.AddSpectrumD();
00205                 tmpD.UpdateData();
00206                 tmpD.SetSpectrumD(a.GetSpectrumD()+b.GetSpectrumD());
00207         }
00208         if(a.HasResidualSpecD() && b.HasResidualSpecD() )
00209         {
00210                 tmpD.AddResidualSpecD();
00211                 tmpD.UpdateData();
00212                 tmpD.SetResidualSpecD(a.GetResidualSpecD()+b.GetResidualSpecD());
00213         }
00214         if(a.HasSinusoidalSpecD() && b.HasSinusoidalSpecD())
00215         {
00216                 tmpD.AddSinusoidalSpecD();
00217                 tmpD.UpdateData();
00218                 tmpD.SetSinusoidalSpecD(a.GetSinusoidalSpecD()+b.GetSinusoidalSpecD());
00219         }
00220         if(a.HasAudioFrameD() && b.HasAudioFrameD() )
00221         {
00222                 tmpD.AddAudioFrameD();
00223                 tmpD.UpdateData();
00224                 tmpD.SetAudioFrameD(a.GetAudioFrameD()+b.GetAudioFrameD());
00225         }
00226         if(a.HasSinusoidalAudioFrameD() && b.HasSinusoidalAudioFrameD() )
00227         {
00228                 tmpD.AddSinusoidalAudioFrameD();
00229                 tmpD.UpdateData();
00230                 tmpD.SetSinusoidalAudioFrameD(a.GetSinusoidalAudioFrameD()+b.GetSinusoidalAudioFrameD());
00231         }
00232         if(a.HasResidualAudioFrameD() && b.HasResidualAudioFrameD() )
00233         {
00234                 tmpD.AddResidualAudioFrameD();
00235                 tmpD.UpdateData();
00236                 tmpD.SetResidualAudioFrameD(a.GetResidualAudioFrameD()+b.GetResidualAudioFrameD());
00237         }
00238         if(a.HasSynthAudioFrameD() && b.HasSynthAudioFrameD() )
00239         {
00240                 tmpD.AddSynthAudioFrameD();
00241                 tmpD.UpdateData();
00242                 tmpD.SetSynthAudioFrameD(a.GetSynthAudioFrameD()+b.GetSynthAudioFrameD());
00243         }
00244 
00245         return tmpD;
00246 }
00247 
00248 
00249 FrameDescriptors operator * (const FrameDescriptors& a,TData mult)
00250 {
00251         FrameDescriptors tmpD(a);
00252         if(a.HasSpectralPeakD())
00253         {
00254                 tmpD.SetSpectralPeakD(a.GetSpectralPeakD()*mult);
00255         }
00256         if(a.HasSpectrumD())
00257         {
00258                 tmpD.SetSpectrumD(a.GetSpectrumD()*mult);
00259         }
00260         if(a.HasResidualSpecD())
00261         {
00262                 tmpD.SetResidualSpecD(a.GetResidualSpecD()*mult);
00263         }
00264         if(a.HasSinusoidalSpecD())
00265         {
00266                 tmpD.SetSinusoidalSpecD(a.GetSinusoidalSpecD()*mult);
00267         }
00268         if(a.HasAudioFrameD())
00269         {
00270                 tmpD.SetAudioFrameD(a.GetAudioFrameD()*mult);
00271         }
00272         if(a.HasSinusoidalAudioFrameD())
00273         {
00274                 tmpD.SetSinusoidalAudioFrameD(a.GetSinusoidalAudioFrameD()*mult);
00275         }
00276         if(a.HasResidualAudioFrameD())
00277         {
00278                 tmpD.SetResidualAudioFrameD(a.GetResidualAudioFrameD()*mult);
00279         }
00280         if(a.HasSynthAudioFrameD())
00281         {
00282                 tmpD.SetSynthAudioFrameD(a.GetSynthAudioFrameD()*mult);
00283         }
00284 
00285         return tmpD;
00286 
00287 }
00288 
00289 FrameDescriptors operator * (TData mult,const FrameDescriptors& a)
00290 {
00291         return a*mult;
00292 }
00293 
00294 FrameDescriptors operator - (const FrameDescriptors& a,const FrameDescriptors& b)
00295 {
00296         return a+((-1.0)*b);
00297 }
00298 FrameDescriptors operator / (const FrameDescriptors& a,TData div) 
00299 { 
00300         return a*(1/div);
00301 }
00302 
00303 
00304 }//CLAM
00305 
Generated by  doxygen 1.6.3