Mercurial > hg > qm-dsp
comparison dsp/tonal/TonalEstimator.cpp @ 225:49844bc8a895
* Queen Mary C++ DSP library
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Wed, 05 Apr 2006 17:35:59 +0000 |
parents | |
children | e5907ae6de17 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 225:49844bc8a895 |
---|---|
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 All rights reserved. | |
9 */ | |
10 | |
11 #include "TonalEstimator.h" | |
12 | |
13 #include <cmath> | |
14 #include <iostream> | |
15 | |
16 #ifndef PI | |
17 #define PI (3.14159265358979232846) | |
18 #endif | |
19 | |
20 TonalEstimator::TonalEstimator() | |
21 { | |
22 m_Basis.resize(6); | |
23 | |
24 int i = 0; | |
25 | |
26 | |
27 // circle of fifths | |
28 m_Basis[i].resize(12); | |
29 for (int iP = 0; iP < 12; iP++) | |
30 { | |
31 m_Basis[i][iP] = std::sin( (7.0 / 6.0) * iP * PI); | |
32 } | |
33 | |
34 i++; | |
35 | |
36 m_Basis[i].resize(12); | |
37 for (int iP = 0; iP < 12; iP++) | |
38 { | |
39 m_Basis[i][iP] = std::cos( (7.0 / 6.0) * iP * PI); | |
40 } | |
41 | |
42 i++; | |
43 | |
44 | |
45 // circle of major thirds | |
46 m_Basis[i].resize(12); | |
47 for (int iP = 0; iP < 12; iP++) | |
48 { | |
49 m_Basis[i][iP] = 0.6 * std::sin( (2.0 / 3.0) * iP * PI); | |
50 } | |
51 | |
52 i++; | |
53 | |
54 m_Basis[i].resize(12); | |
55 for (int iP = 0; iP < 12; iP++) | |
56 { | |
57 m_Basis[i][iP] = 0.6 * std::cos( (2.0 / 3.0) * iP * PI); | |
58 } | |
59 | |
60 i++; | |
61 | |
62 | |
63 // circle of minor thirds | |
64 m_Basis[i].resize(12); | |
65 for (int iP = 0; iP < 12; iP++) | |
66 { | |
67 m_Basis[i][iP] = 1.1 * std::sin( (3.0 / 2.0) * iP * PI); | |
68 } | |
69 | |
70 i++; | |
71 | |
72 m_Basis[i].resize(12); | |
73 for (int iP = 0; iP < 12; iP++) | |
74 { | |
75 m_Basis[i][iP] = 1.1 * std::cos( (3.0 / 2.0) * iP * PI); | |
76 } | |
77 | |
78 } | |
79 | |
80 TonalEstimator::~TonalEstimator() | |
81 { | |
82 } | |
83 | |
84 TCSVector TonalEstimator::transform2TCS(const ChromaVector& rVector) | |
85 { | |
86 TCSVector vaRetVal; | |
87 vaRetVal.resize(6, 0.0); | |
88 | |
89 for (int i = 0; i < 6; i++) | |
90 { | |
91 for (int iP = 0; iP < 12; iP++) | |
92 { | |
93 vaRetVal[i] += m_Basis[i][iP] * rVector[iP]; | |
94 } | |
95 } | |
96 | |
97 return vaRetVal; | |
98 } |