CLAM-Development  1.4.0
ConstantQFolder.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2006 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 #include <iostream>
23 #include <cmath>
24 #include "ConstantQFolder.hxx"
25 
26 namespace Simac
27 {
28 
32 static double complexModule(const double & real, const double & imag)
33 {
34  return std::sqrt(real*real + imag*imag);
35 }
36 
37 ConstantQFolder::ConstantQFolder(unsigned nConstantQBins, int binsPerOctave)
38  : _binsPerOctave(binsPerOctave)
39  , _nConstantQBins(nConstantQBins)
40 {
41  _chromadata.resize(_binsPerOctave);
42 }
43 
45 {
46 }
47 
48 void ConstantQFolder::doIt(const std::vector<double> & constantQData)
49 {
50  //initialise _chromadata to 0
51  for (unsigned i=0; i<_binsPerOctave; i++) _chromadata[i]=0;
52 
53  // add each octave of cq data into chromagram
54  const unsigned nOctaves = (int)floor(double(_nConstantQBins/_binsPerOctave))-1;
55  unsigned constantQBin = 0;
56  for (unsigned octave=0; octave<=nOctaves; octave++) {
57  for (unsigned i=0; i<_binsPerOctave; i++) {
58  const double & real = constantQData[constantQBin++];
59  const double & imag = constantQData[constantQBin++];
60  _chromadata[i] += complexModule(real, imag);
61  }
62  }
63 }
64 
65 }
66