TonalEstimator.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  QM DSP Library
5 
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Martin Gasser.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef QM_DSP_TONALESTIMATOR_H
17 #define QM_DSP_TONALESTIMATOR_H
18 
19 #include <valarray>
20 #include <numeric>
21 #include <algorithm>
22 #include <iostream>
23 
24 class ChromaVector : public std::valarray<double>
25 {
26 public:
27  ChromaVector(size_t uSize = 12) : std::valarray<double>() {
28  resize(uSize, 0.0f);
29  }
30 
31  virtual ~ChromaVector() {};
32 
33  void printDebug() {
34  for (int i = 0; i < int(size()); i++) {
35  std::cout << (*this)[i] << ";";
36  }
37  std::cout << std::endl;
38  }
39 
40  void normalizeL1() {
41  // normalize the chroma vector (L1 norm)
42  double dSum = 0.0;
43 
44  for (size_t i = 0; i < 12; (dSum += std::abs((*this)[i++]))) ;
45  for (size_t i = 0; i < 12; dSum > 0.0000001?((*this)[i] /= dSum):(*this)[i]=0.0, i++) ;
46  }
47 
48  void clear() {
49  for (size_t i = 0; i < 12; ++i) (*this)[i] = 0.0;
50  }
51 };
52 
53 class TCSVector : public std::valarray<double>
54 {
55 public:
56  TCSVector() : std::valarray<double>() {
57  resize(6, 0.0f);
58  }
59 
60  virtual ~TCSVector() {};
61 
62  void printDebug() {
63  for (int i = 0; i < int(size()); i++) {
64  std::cout << (*this)[i] << ";";
65  }
66  std::cout << std::endl;
67  }
68 
69  double magnitude() const {
70  double dMag = 0.0;
71 
72  for (size_t i = 0; i < 6; i++) {
73  dMag += std::pow((*this)[i], 2.0);
74  }
75 
76  return std::sqrt(dMag);
77  }
78 };
79 
81 {
82 public:
84  virtual ~TonalEstimator();
85  TCSVector transform2TCS(const ChromaVector& rVector);
86 
87 protected:
88  std::valarray< std::valarray<double> > m_Basis;
89 };
90 
91 #endif // _TONALESTIMATOR_
virtual ~TCSVector()
virtual ~ChromaVector()
std::valarray< std::valarray< double > > m_Basis
void normalizeL1()
void printDebug()
ChromaVector(size_t uSize=12)
void printDebug()
double magnitude() const