c@225
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
c@225
|
2
|
c@225
|
3 /*
|
c@225
|
4 QM DSP Library
|
c@225
|
5
|
c@225
|
6 Centre for Digital Music, Queen Mary, University of London.
|
c@225
|
7 This file copyright 2006 Martin Gasser.
|
c@309
|
8
|
c@309
|
9 This program is free software; you can redistribute it and/or
|
c@309
|
10 modify it under the terms of the GNU General Public License as
|
c@309
|
11 published by the Free Software Foundation; either version 2 of the
|
c@309
|
12 License, or (at your option) any later version. See the file
|
c@309
|
13 COPYING included with this distribution for more information.
|
c@225
|
14 */
|
c@225
|
15
|
c@225
|
16 #include "TonalEstimator.h"
|
c@225
|
17
|
c@225
|
18 #include <cmath>
|
c@225
|
19 #include <iostream>
|
c@225
|
20
|
c@225
|
21 TonalEstimator::TonalEstimator()
|
c@225
|
22 {
|
cannam@482
|
23 m_Basis.resize(6);
|
c@225
|
24
|
cannam@482
|
25 int i = 0;
|
cannam@482
|
26
|
cannam@482
|
27
|
cannam@482
|
28 // circle of fifths
|
cannam@482
|
29 m_Basis[i].resize(12);
|
cannam@482
|
30 for (int iP = 0; iP < 12; iP++) {
|
cannam@488
|
31 m_Basis[i][iP] = std::sin( (7.0 / 6.0) * iP * M_PI);
|
cannam@482
|
32 }
|
cannam@482
|
33
|
cannam@482
|
34 i++;
|
c@225
|
35
|
cannam@482
|
36 m_Basis[i].resize(12);
|
cannam@482
|
37 for (int iP = 0; iP < 12; iP++) {
|
cannam@488
|
38 m_Basis[i][iP] = std::cos( (7.0 / 6.0) * iP * M_PI);
|
cannam@482
|
39 }
|
cannam@482
|
40
|
cannam@482
|
41 i++;
|
cannam@482
|
42
|
cannam@482
|
43
|
cannam@482
|
44 // circle of major thirds
|
cannam@482
|
45 m_Basis[i].resize(12);
|
cannam@482
|
46 for (int iP = 0; iP < 12; iP++) {
|
cannam@488
|
47 m_Basis[i][iP] = 0.6 * std::sin( (2.0 / 3.0) * iP * M_PI);
|
cannam@482
|
48 }
|
cannam@482
|
49
|
cannam@482
|
50 i++;
|
c@225
|
51
|
cannam@482
|
52 m_Basis[i].resize(12);
|
cannam@482
|
53 for (int iP = 0; iP < 12; iP++) {
|
cannam@488
|
54 m_Basis[i][iP] = 0.6 * std::cos( (2.0 / 3.0) * iP * M_PI);
|
cannam@482
|
55 }
|
c@225
|
56
|
cannam@482
|
57 i++;
|
c@225
|
58
|
c@225
|
59
|
cannam@482
|
60 // circle of minor thirds
|
cannam@482
|
61 m_Basis[i].resize(12);
|
cannam@482
|
62 for (int iP = 0; iP < 12; iP++) {
|
cannam@488
|
63 m_Basis[i][iP] = 1.1 * std::sin( (3.0 / 2.0) * iP * M_PI);
|
cannam@482
|
64 }
|
cannam@482
|
65
|
cannam@482
|
66 i++;
|
c@225
|
67
|
cannam@482
|
68 m_Basis[i].resize(12);
|
cannam@482
|
69 for (int iP = 0; iP < 12; iP++) {
|
cannam@488
|
70 m_Basis[i][iP] = 1.1 * std::cos( (3.0 / 2.0) * iP * M_PI);
|
cannam@482
|
71 }
|
c@225
|
72
|
c@225
|
73 }
|
c@225
|
74
|
c@225
|
75 TonalEstimator::~TonalEstimator()
|
c@225
|
76 {
|
c@225
|
77 }
|
c@225
|
78
|
c@225
|
79 TCSVector TonalEstimator::transform2TCS(const ChromaVector& rVector)
|
c@225
|
80 {
|
cannam@482
|
81 TCSVector vaRetVal;
|
cannam@482
|
82 vaRetVal.resize(6, 0.0);
|
cannam@482
|
83
|
cannam@482
|
84 for (int i = 0; i < 6; i++) {
|
cannam@482
|
85 for (int iP = 0; iP < 12; iP++) {
|
cannam@482
|
86 vaRetVal[i] += m_Basis[i][iP] * rVector[iP];
|
cannam@482
|
87 }
|
cannam@482
|
88 }
|
cannam@482
|
89
|
cannam@482
|
90 return vaRetVal;
|
c@225
|
91 }
|