CLAM-Development  1.4.0
SpectralDescriptors.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 __SpectralDescriptors_H__
23 #define __SpectralDescriptors_H__
24 
25 
26 #include "Array.hxx"
27 #include "Descriptor.hxx"
28 #include "Spectrum.hxx"
29 
30 /*
31  * This class holds Descriptors computed from Spectral data
32  *
33  *
34  */
35 
36 namespace CLAM {
37 
39  public:
41 
50  DYN_ATTRIBUTE (0, public, TData, Mean);
63  DYN_ATTRIBUTE (1, public, TData, GeometricMean);
70  DYN_ATTRIBUTE (2, public, TData, Energy);
78  DYN_ATTRIBUTE (3, public, TData, Centroid);
79  DYN_ATTRIBUTE (4, public, TData, Moment2);
80  DYN_ATTRIBUTE (5, public, TData, Moment3);
81  DYN_ATTRIBUTE (6, public, TData, Moment4);
82  DYN_ATTRIBUTE (7, public, TData, Moment5);
83  DYN_ATTRIBUTE (8, public, TData, Moment6);
84  DYN_ATTRIBUTE (9, public, TData, Flatness);
85  DYN_ATTRIBUTE (10,public, TData, MagnitudeKurtosis);
86  DYN_ATTRIBUTE (11,public, Array<TData>, MFCC);
91  DYN_ATTRIBUTE (12,public, TData, MaxMagFreq);
98  DYN_ATTRIBUTE (13,public, TData, LowFreqEnergyRelation);
104  DYN_ATTRIBUTE (14,public, TData, Spread);
105  DYN_ATTRIBUTE (15,public, TData, MagnitudeSkewness);
115  DYN_ATTRIBUTE (16,public, TData, Rolloff);
121  DYN_ATTRIBUTE (17,public, TData, Slope);
131  DYN_ATTRIBUTE (18,public, TData, HighFrequencyContent);
132  DYN_ATTRIBUTE (19,public, Array<SpectralDescriptors>, BandDescriptors);
133 
134  DYN_ATTRIBUTE (20,public, Array<TData>,PCP);
135 
136  public:
137  SpectralDescriptors(Spectrum* pSpectrum);
138  SpectralDescriptors(TData initVal);
139 
140  const Spectrum* GetpSpectrum() const;
141  void SetpSpectrum(Spectrum* pSpectrum);
142  void ConcreteCompute();
143 
144 //XA_C2S private:
145  void DefaultInit();
146  void CopyInit(const SpectralDescriptors & copied);
147 
155 
156  private:
157  const Spectrum* mpSpectrum;
159  double mDeltaFreq; // double because a lot of computations depends on its precission
160 };
161 
167 
168 template<>
170 {
171  SpectralDescriptors tmpD(a);
172  if(a.HasMean() && b.HasMean() )
173  {
174  if(b.GetMean()>a.GetMean())
175  tmpD.SetMean(b.GetMean());
176  }
177  if(a.HasGeometricMean() && b.HasGeometricMean() )
178  {
179  if(b.GetGeometricMean()>a.GetGeometricMean())
180  tmpD.SetGeometricMean(b.GetGeometricMean());
181  }
182  if(a.HasEnergy() && b.HasEnergy() )
183  {
184  if(b.GetEnergy()>a.GetEnergy())
185  tmpD.SetEnergy(b.GetEnergy());
186  }
187  if(a.HasCentroid() && b.HasCentroid() )
188  {
189  if(b.GetCentroid()>a.GetCentroid())
190  tmpD.SetCentroid(b.GetCentroid());
191  }
192  if(a.HasMoment2() && b.HasMoment2() )
193  {
194  if(b.GetMoment2()>a.GetMoment2())
195  tmpD.SetMoment2(b.GetMoment2());
196  }
197  if(a.HasMoment3() && b.HasMoment3() )
198  {
199  if(b.GetMoment3()>a.GetMoment3())
200  tmpD.SetMoment3(b.GetMoment3());
201  }
202  if(a.HasMoment4() && b.HasMoment4() )
203  {
204  if(b.GetMoment4()>a.GetMoment4())
205  tmpD.SetMoment4(b.GetMoment4());
206  }
207  if(a.HasMoment5() && b.HasMoment5())
208  {
209  if(b.GetMoment5()>a.GetMoment5())
210  tmpD.SetMoment5(b.GetMoment5());
211  }
212  if(a.HasMoment6() && b.HasMoment6() )
213  {
214  if(b.GetMoment6()>a.GetMoment6())
215  tmpD.SetMoment6(b.GetMoment6());
216  }
217  if(a.HasFlatness() && b.HasFlatness() )
218  {
219  if(b.GetFlatness()>a.GetFlatness())
220  tmpD.SetFlatness(b.GetFlatness());
221  }
222  if(a.HasMagnitudeKurtosis() && b.HasMagnitudeKurtosis() )
223  {
224  if(b.GetMagnitudeKurtosis()>a.GetMagnitudeKurtosis())
225  tmpD.SetMagnitudeKurtosis(b.GetMagnitudeKurtosis());
226  }
227  if(a.HasMaxMagFreq() && b.HasMaxMagFreq() )
228  {
229  if(b.GetMaxMagFreq()>a.GetMaxMagFreq())
230  tmpD.SetMaxMagFreq(b.GetMaxMagFreq());
231  }
232  if(a.HasLowFreqEnergyRelation() && b.HasLowFreqEnergyRelation() )
233  {
234  if(b.GetLowFreqEnergyRelation()>a.GetLowFreqEnergyRelation())
235  tmpD.SetLowFreqEnergyRelation(b.GetLowFreqEnergyRelation());
236  }
237  if(a.HasSpread() && b.HasSpread() )
238  {
239  if(b.GetSpread()>a.GetSpread())
240  tmpD.SetSpread(b.GetSpread());
241  }
242  if(a.HasMagnitudeSkewness() && b.HasMagnitudeSkewness() )
243  {
244  if(b.GetMagnitudeSkewness()>a.GetMagnitudeSkewness())
245  tmpD.SetMagnitudeSkewness(b.GetMagnitudeSkewness());
246  }
247  if(a.HasRolloff() && b.HasRolloff() )
248  {
249  if(b.GetRolloff()>a.GetRolloff())
250  tmpD.SetRolloff(b.GetRolloff());
251  }
252  if(a.HasSlope() && b.HasSlope() )
253  {
254  if(b.GetSlope()>a.GetSlope())
255  tmpD.SetSlope(b.GetSlope());
256  }
257  if(a.HasHighFrequencyContent() && b.HasHighFrequencyContent() )
258  {
259  if(b.GetHighFrequencyContent()>a.GetHighFrequencyContent())
260  tmpD.SetHighFrequencyContent(b.GetHighFrequencyContent());
261  }
262  if(a.HasBandDescriptors() && b.HasBandDescriptors() )
263  {
264  /* Array does not have these operators
265 
266  if(b.GetBandDescriptors()>a.GetBandDescriptors())
267  tmpD.SetBandDescriptors(b.GetBandDescriptors() );*/
268  }
269  if(a.HasMFCC() && b.HasMFCC() )
270  {
271  /* Array does not have these operators
272  if(b.GetMFCC()>a.GetMFCC())
273  tmpD.SetMFCC(b.GetMFCC());*/
274  }
275  return tmpD;
276 
277 }
278 
279 template<>
281 {
282  SpectralDescriptors tmpD(a);
283  if(a.HasMean() && b.HasMean() )
284  {
285  if(b.GetMean()<a.GetMean())
286  tmpD.SetMean(b.GetMean());
287  }
288  if(a.HasGeometricMean() && b.HasGeometricMean() )
289  {
290  if(b.GetGeometricMean()<a.GetGeometricMean())
291  tmpD.SetGeometricMean(b.GetGeometricMean());
292  }
293  if(a.HasEnergy() && b.HasEnergy() )
294  {
295  if(b.GetEnergy()<a.GetEnergy())
296  tmpD.SetEnergy(b.GetEnergy());
297  }
298  if(a.HasCentroid() && b.HasCentroid() )
299  {
300  if(b.GetCentroid()<a.GetCentroid())
301  tmpD.SetCentroid(b.GetCentroid());
302  }
303  if(a.HasMoment2() && b.HasMoment2() )
304  {
305  if(b.GetMoment2()<a.GetMoment2())
306  tmpD.SetMoment2(b.GetMoment2());
307  }
308  if(a.HasMoment3() && b.HasMoment3() )
309  {
310  if(b.GetMoment3()<a.GetMoment3())
311  tmpD.SetMoment3(b.GetMoment3());
312  }
313  if(a.HasMoment4() && b.HasMoment4() )
314  {
315  if(b.GetMoment4()<a.GetMoment4())
316  tmpD.SetMoment4(b.GetMoment4());
317  }
318  if(a.HasMoment5() && b.HasMoment5())
319  {
320  if(b.GetMoment5()<a.GetMoment5())
321  tmpD.SetMoment5(b.GetMoment5());
322  }
323  if(a.HasMoment6() && b.HasMoment6() )
324  {
325  if(b.GetMoment6()<a.GetMoment6())
326  tmpD.SetMoment6(b.GetMoment6());
327  }
328  if(a.HasFlatness() && b.HasFlatness() )
329  {
330  if(b.GetFlatness()<a.GetFlatness())
331  tmpD.SetFlatness(b.GetFlatness());
332  }
333  if(a.HasMagnitudeKurtosis() && b.HasMagnitudeKurtosis() )
334  {
335  if(b.GetMagnitudeKurtosis()<a.GetMagnitudeKurtosis())
336  tmpD.SetMagnitudeKurtosis(b.GetMagnitudeKurtosis());
337  }
338  if(a.HasMaxMagFreq() && b.HasMaxMagFreq() )
339  {
340  if(b.GetMaxMagFreq()<a.GetMaxMagFreq())
341  tmpD.SetMaxMagFreq(b.GetMaxMagFreq());
342  }
343  if(a.HasLowFreqEnergyRelation() && b.HasLowFreqEnergyRelation() )
344  {
345  if(b.GetLowFreqEnergyRelation()<a.GetLowFreqEnergyRelation())
346  tmpD.SetLowFreqEnergyRelation(b.GetLowFreqEnergyRelation());
347  }
348  if(a.HasSpread() && b.HasSpread() )
349  {
350  if(b.GetSpread()<a.GetSpread())
351  tmpD.SetSpread(b.GetSpread());
352  }
353  if(a.HasMagnitudeSkewness() && b.HasMagnitudeSkewness() )
354  {
355  if(b.GetMagnitudeSkewness()<a.GetMagnitudeSkewness())
356  tmpD.SetMagnitudeSkewness(b.GetMagnitudeSkewness());
357  }
358  if(a.HasRolloff() && b.HasRolloff() )
359  {
360  if(b.GetRolloff()<a.GetRolloff())
361  tmpD.SetRolloff(b.GetRolloff());
362  }
363  if(a.HasSlope() && b.HasSlope() )
364  {
365  if(b.GetSlope()<a.GetSlope())
366  tmpD.SetSlope(b.GetSlope());
367  }
368  if(a.HasHighFrequencyContent() && b.HasHighFrequencyContent() )
369  {
370  if(b.GetHighFrequencyContent()<a.GetHighFrequencyContent())
371  tmpD.SetHighFrequencyContent(b.GetHighFrequencyContent());
372  }
373  if(a.HasBandDescriptors() && b.HasBandDescriptors() )
374  {
375  /* Array does not have these operators
376  if(b.GetBandDescriptors()<a.GetBandDescriptors())
377  tmpD.SetBandDescriptors(b.GetBandDescriptors() );*/
378  }
379  if(a.HasMFCC() && b.HasMFCC() )
380  {
381  /* Array does not have these operators
382  if(b.GetMFCC()<a.GetMFCC())
383  tmpD.SetMFCC(b.GetMFCC());*/
384  }
385 
386  return tmpD;
387 
388 }
389 
390 }
391 
392 #endif /* __SpectralDescriptors_H__ */
393