SpectralDescriptors.hxx

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 #ifndef __SpectralDescriptors_H__
00023 #define __SpectralDescriptors_H__
00024 
00025 
00026 #include "Array.hxx"
00027 #include "Descriptor.hxx"
00028 #include "Spectrum.hxx"
00029 
00030 /*
00031  * This class holds Descriptors computed from Spectral data 
00032  * 
00033  *
00034  */
00035 
00036 namespace CLAM {
00037 
00038         class SpectralDescriptors : public Descriptor {
00039         public:
00040                 DYNAMIC_TYPE_USING_INTERFACE (SpectralDescriptors, 21, Descriptor);
00041                 
00050                 DYN_ATTRIBUTE (0, public, TData, Mean);
00063                 DYN_ATTRIBUTE (1, public, TData, GeometricMean);
00070                 DYN_ATTRIBUTE (2, public, TData, Energy);
00078                 DYN_ATTRIBUTE (3, public, TData, Centroid);
00079                 DYN_ATTRIBUTE (4, public, TData, Moment2);
00080                 DYN_ATTRIBUTE (5, public, TData, Moment3);
00081                 DYN_ATTRIBUTE (6, public, TData, Moment4);
00082                 DYN_ATTRIBUTE (7, public, TData, Moment5);
00083                 DYN_ATTRIBUTE (8, public, TData, Moment6);
00084                 DYN_ATTRIBUTE (9, public, TData, Flatness);
00085                 DYN_ATTRIBUTE (10,public, TData, MagnitudeKurtosis);
00086                 DYN_ATTRIBUTE (11,public, Array<TData>, MFCC);
00091                 DYN_ATTRIBUTE (12,public, TData, MaxMagFreq); 
00098                 DYN_ATTRIBUTE (13,public, TData, LowFreqEnergyRelation); 
00104                 DYN_ATTRIBUTE (14,public, TData, Spread);
00105                 DYN_ATTRIBUTE (15,public, TData, MagnitudeSkewness);
00115                 DYN_ATTRIBUTE (16,public, TData, Rolloff); 
00121                 DYN_ATTRIBUTE (17,public, TData, Slope);
00131                 DYN_ATTRIBUTE (18,public, TData, HighFrequencyContent);
00132                 DYN_ATTRIBUTE (19,public, Array<SpectralDescriptors>, BandDescriptors);
00133 
00134                 DYN_ATTRIBUTE (20,public, Array<TData>,PCP);
00135 
00136         public:
00137                 SpectralDescriptors(Spectrum* pSpectrum);
00138                 SpectralDescriptors(TData initVal);
00139 
00140                 const Spectrum* GetpSpectrum() const;
00141                 void SetpSpectrum(Spectrum* pSpectrum);
00142                 void ConcreteCompute();
00143 
00144 //XA_C2S        private:
00145                 void DefaultInit();
00146                 void CopyInit(const SpectralDescriptors & copied);
00147                 
00148                 TData ComputeSpectralFlatness();
00149                 TData ComputeHighFrequencyContent();
00150                 TData ComputeMaxMagFreq();
00151                 TData ComputeLowFreqEnergyRelation();
00152                 TData ComputeRolloff();
00153                 TData ComputeSpread();
00154                 TData ComputeSlope();
00155 
00156         private:
00157                 const Spectrum* mpSpectrum;
00159                 double mDeltaFreq; // double because a lot of computations depends on its precission
00160 };
00161 
00162 SpectralDescriptors operator * (const SpectralDescriptors& a,TData mult);
00163 SpectralDescriptors operator * (TData mult,const SpectralDescriptors& a);
00164 SpectralDescriptors operator / (const SpectralDescriptors& a,TData div);
00165 SpectralDescriptors operator * (const SpectralDescriptors& a,const SpectralDescriptors& b) ;
00166 SpectralDescriptors operator + (const SpectralDescriptors& a, const SpectralDescriptors& b);
00167 
00168 template<>
00169 inline SpectralDescriptors CLAM_max (const SpectralDescriptors& a,const SpectralDescriptors& b)
00170 {
00171         SpectralDescriptors  tmpD(a);
00172         if(a.HasMean() && b.HasMean() )
00173         {
00174                 if(b.GetMean()>a.GetMean())
00175                         tmpD.SetMean(b.GetMean());
00176         }
00177         if(a.HasGeometricMean() && b.HasGeometricMean() )
00178         {
00179                 if(b.GetGeometricMean()>a.GetGeometricMean())
00180                         tmpD.SetGeometricMean(b.GetGeometricMean());
00181         }
00182         if(a.HasEnergy() && b.HasEnergy() )
00183         {
00184                 if(b.GetEnergy()>a.GetEnergy())
00185                         tmpD.SetEnergy(b.GetEnergy());
00186         }
00187         if(a.HasCentroid() && b.HasCentroid() )
00188         {
00189                 if(b.GetCentroid()>a.GetCentroid())
00190                         tmpD.SetCentroid(b.GetCentroid());
00191         }
00192         if(a.HasMoment2() && b.HasMoment2() )
00193         {
00194                 if(b.GetMoment2()>a.GetMoment2())
00195                         tmpD.SetMoment2(b.GetMoment2());
00196         }
00197         if(a.HasMoment3() && b.HasMoment3() )
00198         {
00199                 if(b.GetMoment3()>a.GetMoment3())
00200                         tmpD.SetMoment3(b.GetMoment3());
00201         }
00202         if(a.HasMoment4() && b.HasMoment4() )
00203         {
00204                 if(b.GetMoment4()>a.GetMoment4())
00205                         tmpD.SetMoment4(b.GetMoment4());
00206         }
00207         if(a.HasMoment5() && b.HasMoment5())
00208         {
00209                 if(b.GetMoment5()>a.GetMoment5())
00210                         tmpD.SetMoment5(b.GetMoment5());
00211         }
00212         if(a.HasMoment6() && b.HasMoment6() )
00213         {
00214                 if(b.GetMoment6()>a.GetMoment6())
00215                         tmpD.SetMoment6(b.GetMoment6());
00216         }
00217         if(a.HasFlatness() && b.HasFlatness() )
00218         {
00219                 if(b.GetFlatness()>a.GetFlatness())
00220                         tmpD.SetFlatness(b.GetFlatness());
00221         }
00222         if(a.HasMagnitudeKurtosis() && b.HasMagnitudeKurtosis() )
00223         {
00224                 if(b.GetMagnitudeKurtosis()>a.GetMagnitudeKurtosis())
00225                         tmpD.SetMagnitudeKurtosis(b.GetMagnitudeKurtosis());
00226         }
00227         if(a.HasMaxMagFreq() && b.HasMaxMagFreq() )
00228         {
00229                 if(b.GetMaxMagFreq()>a.GetMaxMagFreq())
00230                         tmpD.SetMaxMagFreq(b.GetMaxMagFreq());
00231         }
00232         if(a.HasLowFreqEnergyRelation() && b.HasLowFreqEnergyRelation() )
00233         {
00234                 if(b.GetLowFreqEnergyRelation()>a.GetLowFreqEnergyRelation())
00235                         tmpD.SetLowFreqEnergyRelation(b.GetLowFreqEnergyRelation());
00236         }
00237         if(a.HasSpread() && b.HasSpread() )
00238         {
00239                 if(b.GetSpread()>a.GetSpread())
00240                         tmpD.SetSpread(b.GetSpread());
00241         }
00242         if(a.HasMagnitudeSkewness() && b.HasMagnitudeSkewness() )
00243         {
00244                 if(b.GetMagnitudeSkewness()>a.GetMagnitudeSkewness())
00245                         tmpD.SetMagnitudeSkewness(b.GetMagnitudeSkewness());
00246         }
00247         if(a.HasRolloff() && b.HasRolloff() )
00248         {
00249                 if(b.GetRolloff()>a.GetRolloff())
00250                         tmpD.SetRolloff(b.GetRolloff());
00251         }
00252         if(a.HasSlope() && b.HasSlope() )
00253         {
00254                 if(b.GetSlope()>a.GetSlope())
00255                         tmpD.SetSlope(b.GetSlope());
00256         }
00257         if(a.HasHighFrequencyContent() && b.HasHighFrequencyContent() )
00258         {
00259                 if(b.GetHighFrequencyContent()>a.GetHighFrequencyContent())
00260                         tmpD.SetHighFrequencyContent(b.GetHighFrequencyContent());
00261         }
00262         if(a.HasBandDescriptors() && b.HasBandDescriptors() )
00263         {
00264                 /* Array does not have these operators
00265                 
00266                   if(b.GetBandDescriptors()>a.GetBandDescriptors())
00267                         tmpD.SetBandDescriptors(b.GetBandDescriptors() );*/
00268         }
00269         if(a.HasMFCC() && b.HasMFCC() )
00270         {
00271                 /* Array does not have these operators
00272                 if(b.GetMFCC()>a.GetMFCC())
00273                         tmpD.SetMFCC(b.GetMFCC());*/
00274         }
00275         return tmpD;
00276 
00277 }
00278 
00279 template<>
00280 inline SpectralDescriptors CLAM_min (const SpectralDescriptors& a,const SpectralDescriptors& b)
00281 {
00282         SpectralDescriptors  tmpD(a);
00283         if(a.HasMean() && b.HasMean() )
00284         {
00285                 if(b.GetMean()<a.GetMean())
00286                         tmpD.SetMean(b.GetMean());
00287         }
00288         if(a.HasGeometricMean() && b.HasGeometricMean() )
00289         {
00290                 if(b.GetGeometricMean()<a.GetGeometricMean())
00291                         tmpD.SetGeometricMean(b.GetGeometricMean());
00292         }
00293         if(a.HasEnergy() && b.HasEnergy() )
00294         {
00295                 if(b.GetEnergy()<a.GetEnergy())
00296                         tmpD.SetEnergy(b.GetEnergy());
00297         }
00298         if(a.HasCentroid() && b.HasCentroid() )
00299         {
00300                 if(b.GetCentroid()<a.GetCentroid())
00301                         tmpD.SetCentroid(b.GetCentroid());
00302         }
00303         if(a.HasMoment2() && b.HasMoment2() )
00304         {
00305                 if(b.GetMoment2()<a.GetMoment2())
00306                         tmpD.SetMoment2(b.GetMoment2());
00307         }
00308         if(a.HasMoment3() && b.HasMoment3() )
00309         {
00310                 if(b.GetMoment3()<a.GetMoment3())
00311                         tmpD.SetMoment3(b.GetMoment3());
00312         }
00313         if(a.HasMoment4() && b.HasMoment4() )
00314         {
00315                 if(b.GetMoment4()<a.GetMoment4())
00316                         tmpD.SetMoment4(b.GetMoment4());
00317         }
00318         if(a.HasMoment5() && b.HasMoment5())
00319         {
00320                 if(b.GetMoment5()<a.GetMoment5())
00321                         tmpD.SetMoment5(b.GetMoment5());
00322         }
00323         if(a.HasMoment6() && b.HasMoment6() )
00324         {
00325                 if(b.GetMoment6()<a.GetMoment6())
00326                         tmpD.SetMoment6(b.GetMoment6());
00327         }
00328         if(a.HasFlatness() && b.HasFlatness() )
00329         {
00330                 if(b.GetFlatness()<a.GetFlatness())
00331                         tmpD.SetFlatness(b.GetFlatness());
00332         }
00333         if(a.HasMagnitudeKurtosis() && b.HasMagnitudeKurtosis() )
00334         {
00335                 if(b.GetMagnitudeKurtosis()<a.GetMagnitudeKurtosis())
00336                         tmpD.SetMagnitudeKurtosis(b.GetMagnitudeKurtosis());
00337         }
00338         if(a.HasMaxMagFreq() && b.HasMaxMagFreq() )
00339         {
00340                 if(b.GetMaxMagFreq()<a.GetMaxMagFreq())
00341                         tmpD.SetMaxMagFreq(b.GetMaxMagFreq());
00342         }
00343         if(a.HasLowFreqEnergyRelation() && b.HasLowFreqEnergyRelation() )
00344         {
00345                 if(b.GetLowFreqEnergyRelation()<a.GetLowFreqEnergyRelation())
00346                         tmpD.SetLowFreqEnergyRelation(b.GetLowFreqEnergyRelation());
00347         }
00348         if(a.HasSpread() && b.HasSpread() )
00349         {
00350                 if(b.GetSpread()<a.GetSpread())
00351                         tmpD.SetSpread(b.GetSpread());
00352         }
00353         if(a.HasMagnitudeSkewness() && b.HasMagnitudeSkewness() )
00354         {
00355                 if(b.GetMagnitudeSkewness()<a.GetMagnitudeSkewness())
00356                         tmpD.SetMagnitudeSkewness(b.GetMagnitudeSkewness());
00357         }
00358         if(a.HasRolloff() && b.HasRolloff() )
00359         {
00360                 if(b.GetRolloff()<a.GetRolloff())
00361                         tmpD.SetRolloff(b.GetRolloff());
00362         }
00363         if(a.HasSlope() && b.HasSlope() )
00364         {
00365                 if(b.GetSlope()<a.GetSlope())
00366                         tmpD.SetSlope(b.GetSlope());
00367         }
00368         if(a.HasHighFrequencyContent() && b.HasHighFrequencyContent() )
00369         {
00370                 if(b.GetHighFrequencyContent()<a.GetHighFrequencyContent())
00371                         tmpD.SetHighFrequencyContent(b.GetHighFrequencyContent());
00372         }
00373         if(a.HasBandDescriptors() && b.HasBandDescriptors() )
00374         {
00375                 /* Array does not have these operators
00376                 if(b.GetBandDescriptors()<a.GetBandDescriptors())
00377                         tmpD.SetBandDescriptors(b.GetBandDescriptors() );*/
00378         }
00379         if(a.HasMFCC() && b.HasMFCC() )
00380         {
00381                 /* Array does not have these operators
00382                 if(b.GetMFCC()<a.GetMFCC())
00383                         tmpD.SetMFCC(b.GetMFCC());*/
00384         }
00385 
00386         return tmpD;
00387 
00388 }
00389 
00390 }
00391 
00392 #endif /* __SpectralDescriptors_H__ */
00393 
Generated by  doxygen 1.6.3