AudioDescriptors.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 __AUDIODescriptors_H__
00023 #define __AUDIODescriptors_H__
00024 
00025 #include <typeinfo>
00026 #include "Descriptor.hxx"
00027 #include "DataTypes.hxx"
00028 /*
00029  * This class holds Descriptors computed from Audio data
00030  *
00031  *
00032  */
00033 
00034 namespace CLAM {
00035 
00036         class Audio;
00037 
00038         class AudioDescriptors : public DescriptorAbs {
00039         public:
00040                 DYNAMIC_TYPE_USING_INTERFACE (AudioDescriptors, 8, DescriptorAbs);
00041                 
00046                 DYN_ATTRIBUTE (0, public, TData, Mean);
00051                 DYN_ATTRIBUTE (1, public, TData, Variance);
00061                 DYN_ATTRIBUTE (2, public, TData, TemporalCentroid);
00062                 
00068                 DYN_ATTRIBUTE (3, public, TData, LogAttackTime);
00069 
00076                 DYN_ATTRIBUTE (4, public, TData, Energy);
00077 
00083                 DYN_ATTRIBUTE (5, public, TData, ZeroCrossingRate);
00084 
00091                 DYN_ATTRIBUTE (6, public, TData, RiseTime);
00092 
00098                 DYN_ATTRIBUTE (7, public, TData, Decrease);
00099 
00100         public:
00101 
00102                 AudioDescriptors(Audio* pAudio);
00103                 AudioDescriptors(TData initVal);
00104 
00105                 const Audio* GetpAudio() const;
00106                 void SetpAudio(Audio* pAudio);
00107                 void ConcreteCompute();
00108 
00109         private:
00110                 void DefaultInit();
00111                 void CopyInit(const AudioDescriptors & copied);
00112                 
00113                 TData ComputeZeroCrossingRate();
00114                 TData ComputeAttackTime();
00115                 TData ComputeLogAttackTime();
00116                 TData ComputeDecrease();
00117 
00118                 
00119         private:
00120                 const Audio* mpAudio;
00121                 static const TData mEpsilon;
00122                 
00123                 bool mIsAttackTimeComputed;
00124                 TData mComputedAttackTime;
00125         };
00126 
00127         
00128 
00129 AudioDescriptors operator * (const AudioDescriptors& a,TData mult) ;
00130 AudioDescriptors operator * (TData mult, const AudioDescriptors& a) ;
00131 AudioDescriptors operator * (const AudioDescriptors& a,const AudioDescriptors& b) ;
00132 AudioDescriptors operator + (const AudioDescriptors& a,const AudioDescriptors& b) ;
00133 AudioDescriptors operator - (const AudioDescriptors& a,const AudioDescriptors& b) ;
00134 AudioDescriptors operator / (const AudioDescriptors& a,TData div);
00135 
00136 template<>
00137 inline AudioDescriptors CLAM_min (const AudioDescriptors & a,const AudioDescriptors & b)
00138 {
00139         AudioDescriptors tmpD(a);
00140 
00141         if (a.HasMean() && b.HasMean() )
00142         {
00143                 if(b.GetMean()<a.GetMean())
00144                         tmpD.SetMean(b.GetMean() );
00145         }
00146         if (a.HasTemporalCentroid() && b.HasTemporalCentroid() )
00147         {
00148                 if(b.GetTemporalCentroid()<a.GetTemporalCentroid())
00149                         tmpD.SetTemporalCentroid(b.GetTemporalCentroid() );
00150         }
00151         if (a.HasEnergy() && b.HasEnergy() )
00152         {
00153                 if(b.GetEnergy()<a.GetEnergy())
00154                         tmpD.SetEnergy(b.GetEnergy() );
00155         }
00156         if(a.HasVariance() && b.HasVariance() )
00157         {
00158                 if(b.GetVariance()<a.GetVariance())
00159                         tmpD.SetVariance(b.GetVariance() );
00160         }
00161         if(a.HasZeroCrossingRate() && b.HasZeroCrossingRate() )
00162         {
00163                 if(b.GetZeroCrossingRate()<a.GetZeroCrossingRate())
00164                         tmpD.SetZeroCrossingRate(b.GetZeroCrossingRate() );
00165         }
00166         if(a.HasRiseTime() && b.HasRiseTime() )
00167         {
00168                 if(b.GetRiseTime()<a.GetRiseTime())
00169                         tmpD.SetRiseTime(b.GetRiseTime() );
00170         }
00171         if(a.HasLogAttackTime() && b.HasLogAttackTime() )
00172         {
00173                 if(b.GetLogAttackTime()<a.GetLogAttackTime())
00174                         tmpD.SetLogAttackTime(b.GetLogAttackTime() );
00175         }
00176         if(a.HasDecrease() && b.HasDecrease() )
00177         {
00178                 if(b.GetDecrease()<a.GetDecrease())
00179                         tmpD.SetDecrease(b.GetDecrease() );
00180         }
00181         return tmpD;
00182 
00183 
00184 }
00185 
00186 template<>
00187 inline AudioDescriptors CLAM_max (const AudioDescriptors & a,const AudioDescriptors & b)
00188 {
00189         AudioDescriptors tmpD(a);
00190 
00191         if (a.HasMean() && b.HasMean() )
00192         {
00193                 if(b.GetMean()>a.GetMean())
00194                         tmpD.SetMean(b.GetMean() );
00195         }
00196         if (a.HasTemporalCentroid() && b.HasTemporalCentroid() )
00197         {
00198                 if(b.GetTemporalCentroid()>a.GetTemporalCentroid())
00199                         tmpD.SetTemporalCentroid(b.GetTemporalCentroid() );
00200         }
00201         if (a.HasEnergy() && b.HasEnergy() )
00202         {
00203                 if(b.GetEnergy()>a.GetEnergy())
00204                         tmpD.SetEnergy(b.GetEnergy() );
00205         }
00206         if(a.HasVariance() && b.HasVariance() )
00207         {
00208                 if(b.GetVariance()>a.GetVariance())
00209                         tmpD.SetVariance(b.GetVariance() );
00210         }
00211         if(a.HasZeroCrossingRate() && b.HasZeroCrossingRate() )
00212         {
00213                 if(b.GetZeroCrossingRate()>a.GetZeroCrossingRate())
00214                         tmpD.SetZeroCrossingRate(b.GetZeroCrossingRate() );
00215         }
00216         if(a.HasRiseTime() && b.HasRiseTime() )
00217         {
00218                 if(b.GetRiseTime()>a.GetRiseTime())
00219                         tmpD.SetRiseTime(b.GetRiseTime() );
00220         }
00221         if(a.HasLogAttackTime() && b.HasLogAttackTime() )
00222         {
00223                 if(b.GetLogAttackTime()>a.GetLogAttackTime())
00224                         tmpD.SetLogAttackTime(b.GetLogAttackTime() );
00225         }
00226         if(a.HasDecrease() && b.HasDecrease() )
00227         {
00228                 if(b.GetDecrease()>a.GetDecrease())
00229                         tmpD.SetDecrease(b.GetDecrease() );
00230         }
00231         return tmpD;
00232 
00233 }
00234 
00235 
00236 };
00237 
00238 
00239 #endif /* __AUDIODescriptors_H__ */
00240 
Generated by  doxygen 1.6.3