CLAM-Development  1.4.0
AudioDescriptors.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 
22 #ifndef __AUDIODescriptors_H__
23 #define __AUDIODescriptors_H__
24 
25 #include <typeinfo>
26 #include "Descriptor.hxx"
27 #include "DataTypes.hxx"
28 /*
29  * This class holds Descriptors computed from Audio data
30  *
31  *
32  */
33 
34 namespace CLAM {
35 
36  class Audio;
37 
39  public:
41 
46  DYN_ATTRIBUTE (0, public, TData, Mean);
51  DYN_ATTRIBUTE (1, public, TData, Variance);
61  DYN_ATTRIBUTE (2, public, TData, TemporalCentroid);
62 
68  DYN_ATTRIBUTE (3, public, TData, LogAttackTime);
69 
76  DYN_ATTRIBUTE (4, public, TData, Energy);
77 
83  DYN_ATTRIBUTE (5, public, TData, ZeroCrossingRate);
84 
91  DYN_ATTRIBUTE (6, public, TData, RiseTime);
92 
98  DYN_ATTRIBUTE (7, public, TData, Decrease);
99 
100  public:
101 
102  AudioDescriptors(Audio* pAudio);
103  AudioDescriptors(TData initVal);
104 
105  const Audio* GetpAudio() const;
106  void SetpAudio(Audio* pAudio);
107  void ConcreteCompute();
108 
109  private:
110  void DefaultInit();
111  void CopyInit(const AudioDescriptors & copied);
112 
113  TData ComputeZeroCrossingRate();
114  TData ComputeAttackTime();
115  TData ComputeLogAttackTime();
116  TData ComputeDecrease();
117 
118 
119  private:
120  const Audio* mpAudio;
121  static const TData mEpsilon;
122 
123  bool mIsAttackTimeComputed;
124  TData mComputedAttackTime;
125  };
126 
127 
128 
135 
136 template<>
138 {
139  AudioDescriptors tmpD(a);
140 
141  if (a.HasMean() && b.HasMean() )
142  {
143  if(b.GetMean()<a.GetMean())
144  tmpD.SetMean(b.GetMean() );
145  }
146  if (a.HasTemporalCentroid() && b.HasTemporalCentroid() )
147  {
148  if(b.GetTemporalCentroid()<a.GetTemporalCentroid())
149  tmpD.SetTemporalCentroid(b.GetTemporalCentroid() );
150  }
151  if (a.HasEnergy() && b.HasEnergy() )
152  {
153  if(b.GetEnergy()<a.GetEnergy())
154  tmpD.SetEnergy(b.GetEnergy() );
155  }
156  if(a.HasVariance() && b.HasVariance() )
157  {
158  if(b.GetVariance()<a.GetVariance())
159  tmpD.SetVariance(b.GetVariance() );
160  }
161  if(a.HasZeroCrossingRate() && b.HasZeroCrossingRate() )
162  {
163  if(b.GetZeroCrossingRate()<a.GetZeroCrossingRate())
164  tmpD.SetZeroCrossingRate(b.GetZeroCrossingRate() );
165  }
166  if(a.HasRiseTime() && b.HasRiseTime() )
167  {
168  if(b.GetRiseTime()<a.GetRiseTime())
169  tmpD.SetRiseTime(b.GetRiseTime() );
170  }
171  if(a.HasLogAttackTime() && b.HasLogAttackTime() )
172  {
173  if(b.GetLogAttackTime()<a.GetLogAttackTime())
174  tmpD.SetLogAttackTime(b.GetLogAttackTime() );
175  }
176  if(a.HasDecrease() && b.HasDecrease() )
177  {
178  if(b.GetDecrease()<a.GetDecrease())
179  tmpD.SetDecrease(b.GetDecrease() );
180  }
181  return tmpD;
182 
183 
184 }
185 
186 template<>
188 {
189  AudioDescriptors tmpD(a);
190 
191  if (a.HasMean() && b.HasMean() )
192  {
193  if(b.GetMean()>a.GetMean())
194  tmpD.SetMean(b.GetMean() );
195  }
196  if (a.HasTemporalCentroid() && b.HasTemporalCentroid() )
197  {
198  if(b.GetTemporalCentroid()>a.GetTemporalCentroid())
199  tmpD.SetTemporalCentroid(b.GetTemporalCentroid() );
200  }
201  if (a.HasEnergy() && b.HasEnergy() )
202  {
203  if(b.GetEnergy()>a.GetEnergy())
204  tmpD.SetEnergy(b.GetEnergy() );
205  }
206  if(a.HasVariance() && b.HasVariance() )
207  {
208  if(b.GetVariance()>a.GetVariance())
209  tmpD.SetVariance(b.GetVariance() );
210  }
211  if(a.HasZeroCrossingRate() && b.HasZeroCrossingRate() )
212  {
213  if(b.GetZeroCrossingRate()>a.GetZeroCrossingRate())
214  tmpD.SetZeroCrossingRate(b.GetZeroCrossingRate() );
215  }
216  if(a.HasRiseTime() && b.HasRiseTime() )
217  {
218  if(b.GetRiseTime()>a.GetRiseTime())
219  tmpD.SetRiseTime(b.GetRiseTime() );
220  }
221  if(a.HasLogAttackTime() && b.HasLogAttackTime() )
222  {
223  if(b.GetLogAttackTime()>a.GetLogAttackTime())
224  tmpD.SetLogAttackTime(b.GetLogAttackTime() );
225  }
226  if(a.HasDecrease() && b.HasDecrease() )
227  {
228  if(b.GetDecrease()>a.GetDecrease())
229  tmpD.SetDecrease(b.GetDecrease() );
230  }
231  return tmpD;
232 
233 }
234 
235 
236 };
237 
238 
239 #endif /* __AUDIODescriptors_H__ */
240