CLAM-Development  1.4.0
SpectralPeak.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
23 // Class SpectralPeak: Processing Data class to store spectral peak data
25 // Description:
26 // This class holds a basic data structure used for spectral processing: the
27 // the Spectral Peak. A Spectral Peak holds information about a particular
28 // spectral sample extracted from a Peak Detection Algorithm. Some information
29 // such as Frequency and Amplitude is mandatory, other as Phase and BinWidth
30 // may be needed for some particular applications and BinPos may be redundant
31 // with Frequency but is kept for backwards compatibility.
33 
34 
35 #ifndef _SpectralPeak_
36 #define _SpectralPeak_
37 
38 #include <typeinfo>
39 
40 #include "DynamicType.hxx"
41 #include "Array.hxx"
42 #include "DataTypes.hxx"
43 #include "OSDefines.hxx"
44 #include "Err.hxx"
45 #include "ProcessingData.hxx"
46 #include "GlobalEnums.hxx"
47 #include "CLAM_Math.hxx"
48 
49 namespace CLAM{
50 
51 
52 
63 {
64 public:
66  DYN_ATTRIBUTE (0, public, EScale, Scale);
67  DYN_ATTRIBUTE (1, public, TData, Freq);
68  DYN_ATTRIBUTE (2, public, TData, Mag);
69  DYN_ATTRIBUTE (3, public, TData, BinPos);
70  DYN_ATTRIBUTE (4, public, TData, Phase);
71  DYN_ATTRIBUTE (5, public, int, BinWidth);
72 
73 
74 protected:
77  void DefaultInit();
78 
79 public:
80 //operators
81 
86  TData operator|(const SpectralPeak& a) const
87  {
88  return (Abs(GetFreq()-a.GetFreq()));
89  }
97  friend SpectralPeak operator * (const SpectralPeak& peak,int factor)
98  {
99  SpectralPeak ret;
100  ret.SetFreq(peak.GetFreq());
101  ret.SetMag(peak.GetMag()*factor);
102  ret.SetPhase(peak.GetPhase());
103  ret.SetBinPos(peak.GetBinPos());
104  ret.SetBinWidth(peak.GetBinWidth());
105  ret.SetScale(peak.GetScale());
106  return ret;
107  }
108 
109 
110 };
111 
118 inline SpectralPeak Lin(SpectralPeak &inPeak,int scalingFactor)
119 {
120  if (inPeak.GetScale()!=EScale::eLinear){
121  TData currMag = inPeak.GetMag();
122  inPeak.SetMag(CLAM_pow(TData(10),TData(currMag/scalingFactor)));
123  inPeak.SetScale(EScale::eLinear);
124  }
125  return inPeak;
126 }
127 
129 {
130  if (inPeak.GetScale()!=EScale::eLinear){
131  TData currMag = inPeak.GetMag();
132  inPeak.SetMag(log2lin(currMag));
133  inPeak.SetScale(EScale::eLinear);
134  }
135  return inPeak;
136 }
137 
138 
144 inline SpectralPeak DB(SpectralPeak& inPeak,int scalingFactor=20)
145 {
146  if (inPeak.GetScale()!=EScale::eLog){
147  TData currMag = inPeak.GetMag();
148  inPeak.SetMag(scalingFactor*CLAM_log10(currMag));
149  inPeak.SetScale(EScale::eLog);
150  }
151  return inPeak;
152 }
153 
154 };//namespace
155 
156 #endif
157