qm-dsp  1.8
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 
21 #ifndef PI
22 #define PI (3.14159265358979232846)
23 #endif
24 
26 {
27  m_Basis.resize(6);
28 
29  int i = 0;
30 
31 
32  // circle of fifths
33  m_Basis[i].resize(12);
34  for (int iP = 0; iP < 12; iP++)
35  {
36  m_Basis[i][iP] = std::sin( (7.0 / 6.0) * iP * PI);
37  }
38 
39  i++;
40 
41  m_Basis[i].resize(12);
42  for (int iP = 0; iP < 12; iP++)
43  {
44  m_Basis[i][iP] = std::cos( (7.0 / 6.0) * iP * PI);
45  }
46 
47  i++;
48 
49 
50  // circle of major thirds
51  m_Basis[i].resize(12);
52  for (int iP = 0; iP < 12; iP++)
53  {
54  m_Basis[i][iP] = 0.6 * std::sin( (2.0 / 3.0) * iP * PI);
55  }
56 
57  i++;
58 
59  m_Basis[i].resize(12);
60  for (int iP = 0; iP < 12; iP++)
61  {
62  m_Basis[i][iP] = 0.6 * std::cos( (2.0 / 3.0) * iP * PI);
63  }
64 
65  i++;
66 
67 
68  // circle of minor thirds
69  m_Basis[i].resize(12);
70  for (int iP = 0; iP < 12; iP++)
71  {
72  m_Basis[i][iP] = 1.1 * std::sin( (3.0 / 2.0) * iP * PI);
73  }
74 
75  i++;
76 
77  m_Basis[i].resize(12);
78  for (int iP = 0; iP < 12; iP++)
79  {
80  m_Basis[i][iP] = 1.1 * std::cos( (3.0 / 2.0) * iP * PI);
81  }
82 
83 }
84 
86 {
87 }
88 
90 {
91  TCSVector vaRetVal;
92  vaRetVal.resize(6, 0.0);
93 
94  for (int i = 0; i < 6; i++)
95  {
96  for (int iP = 0; iP < 12; iP++)
97  {
98  vaRetVal[i] += m_Basis[i][iP] * rVector[iP];
99  }
100  }
101 
102  return vaRetVal;
103 }
virtual ~TonalEstimator()
std::valarray< std::valarray< double > > m_Basis
#define PI
TCSVector transform2TCS(const ChromaVector &rVector)