TonalEstimator.cpp
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 #include "TonalEstimator.h"
17 
18 #include <cmath>
19 #include <iostream>
20 
22 {
23  m_Basis.resize(6);
24 
25  int i = 0;
26 
27 
28  // circle of fifths
29  m_Basis[i].resize(12);
30  for (int iP = 0; iP < 12; iP++) {
31  m_Basis[i][iP] = std::sin( (7.0 / 6.0) * iP * M_PI);
32  }
33 
34  i++;
35 
36  m_Basis[i].resize(12);
37  for (int iP = 0; iP < 12; iP++) {
38  m_Basis[i][iP] = std::cos( (7.0 / 6.0) * iP * M_PI);
39  }
40 
41  i++;
42 
43 
44  // circle of major thirds
45  m_Basis[i].resize(12);
46  for (int iP = 0; iP < 12; iP++) {
47  m_Basis[i][iP] = 0.6 * std::sin( (2.0 / 3.0) * iP * M_PI);
48  }
49 
50  i++;
51 
52  m_Basis[i].resize(12);
53  for (int iP = 0; iP < 12; iP++) {
54  m_Basis[i][iP] = 0.6 * std::cos( (2.0 / 3.0) * iP * M_PI);
55  }
56 
57  i++;
58 
59 
60  // circle of minor thirds
61  m_Basis[i].resize(12);
62  for (int iP = 0; iP < 12; iP++) {
63  m_Basis[i][iP] = 1.1 * std::sin( (3.0 / 2.0) * iP * M_PI);
64  }
65 
66  i++;
67 
68  m_Basis[i].resize(12);
69  for (int iP = 0; iP < 12; iP++) {
70  m_Basis[i][iP] = 1.1 * std::cos( (3.0 / 2.0) * iP * M_PI);
71  }
72 
73 }
74 
76 {
77 }
78 
80 {
81  TCSVector vaRetVal;
82  vaRetVal.resize(6, 0.0);
83 
84  for (int i = 0; i < 6; i++) {
85  for (int iP = 0; iP < 12; iP++) {
86  vaRetVal[i] += m_Basis[i][iP] * rVector[iP];
87  }
88  }
89 
90  return vaRetVal;
91 }
virtual ~TonalEstimator()
std::valarray< std::valarray< double > > m_Basis
TCSVector transform2TCS(const ChromaVector &rVector)