SpectralPeak.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 
00023 // Class SpectralPeak: Processing Data class to store spectral peak data
00025 // Description: 
00026 //  This class holds a basic data structure used for spectral processing: the
00027 //  the Spectral Peak. A Spectral Peak holds information about a particular
00028 //  spectral sample extracted from a Peak Detection Algorithm. Some information
00029 //  such as Frequency and Amplitude is mandatory, other as Phase and BinWidth
00030 //  may be needed for some particular applications and BinPos may be redundant
00031 //  with Frequency but is kept for backwards compatibility.
00033 
00034 
00035 #ifndef _SpectralPeak_
00036 #define _SpectralPeak_
00037 
00038 #include <typeinfo>
00039 
00040 #include "DynamicType.hxx"
00041 #include "Array.hxx"
00042 #include "DataTypes.hxx"
00043 #include "OSDefines.hxx"
00044 #include "Err.hxx"
00045 #include "ProcessingData.hxx"
00046 #include "GlobalEnums.hxx"
00047 #include "CLAM_Math.hxx"
00048 
00049 namespace CLAM{
00050 
00051 
00052 
00062 class SpectralPeak: public ProcessingData
00063 {
00064 public:
00065         DYNAMIC_TYPE_USING_INTERFACE (SpectralPeak, 6, ProcessingData);
00066         DYN_ATTRIBUTE (0, public, EScale, Scale);
00067         DYN_ATTRIBUTE (1, public, TData, Freq);
00068         DYN_ATTRIBUTE (2, public, TData, Mag);
00069         DYN_ATTRIBUTE (3, public, TData, BinPos);
00070         DYN_ATTRIBUTE (4, public, TData, Phase);
00071         DYN_ATTRIBUTE (5, public, int, BinWidth);
00072 
00073 
00074 protected:
00077         void DefaultInit();
00078 
00079 public:
00080 //operators
00081 
00086         TData operator|(const SpectralPeak& a) const
00087         {
00088                 return (Abs(GetFreq()-a.GetFreq()));
00089         }
00097         friend  SpectralPeak operator * (const SpectralPeak& peak,int factor)
00098         {
00099                 SpectralPeak ret;
00100                 ret.SetFreq(peak.GetFreq());
00101                 ret.SetMag(peak.GetMag()*factor);
00102                 ret.SetPhase(peak.GetPhase());
00103                 ret.SetBinPos(peak.GetBinPos());
00104                 ret.SetBinWidth(peak.GetBinWidth());
00105                 ret.SetScale(peak.GetScale());
00106                 return ret;
00107         }
00108 
00109 
00110 };
00111 
00118 inline SpectralPeak Lin(SpectralPeak &inPeak,int scalingFactor)
00119 {
00120         if (inPeak.GetScale()!=EScale::eLinear){
00121                 TData currMag = inPeak.GetMag();
00122                 inPeak.SetMag(CLAM_pow(TData(10),TData(currMag/scalingFactor)));
00123                 inPeak.SetScale(EScale::eLinear);
00124         }
00125         return inPeak;
00126 }
00127 
00128 inline SpectralPeak Lin(SpectralPeak &inPeak)
00129 {
00130         if (inPeak.GetScale()!=EScale::eLinear){
00131                 TData currMag = inPeak.GetMag();
00132                 inPeak.SetMag(log2lin(currMag));
00133                 inPeak.SetScale(EScale::eLinear);
00134         }
00135         return inPeak;
00136 }
00137 
00138 
00144 inline SpectralPeak DB(SpectralPeak& inPeak,int scalingFactor=20)
00145 {
00146         if (inPeak.GetScale()!=EScale::eLog){
00147                 TData currMag = inPeak.GetMag();
00148                 inPeak.SetMag(scalingFactor*CLAM_log10(currMag));
00149                 inPeak.SetScale(EScale::eLog);
00150         }
00151         return inPeak;
00152 }
00153 
00154 };//namespace
00155 
00156 #endif
00157 
Generated by  doxygen 1.6.3