add queen mary DSP library
[ardour2.git] / libs / qm-dsp / dsp / tonal / TonalEstimator.cpp
blob16d1aa89956f8a827db2f0a4fce9401ccce990a0
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
3 /*
4 QM DSP Library
6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006 Martin Gasser.
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.
16 #include "TonalEstimator.h"
18 #include <cmath>
19 #include <iostream>
21 #ifndef PI
22 #define PI (3.14159265358979232846)
23 #endif
25 TonalEstimator::TonalEstimator()
27 m_Basis.resize(6);
29 int i = 0;
32 // circle of fifths
33 m_Basis[i].resize(12);
34 for (int iP = 0; iP < 12; iP++)
36 m_Basis[i][iP] = std::sin( (7.0 / 6.0) * iP * PI);
39 i++;
41 m_Basis[i].resize(12);
42 for (int iP = 0; iP < 12; iP++)
44 m_Basis[i][iP] = std::cos( (7.0 / 6.0) * iP * PI);
47 i++;
50 // circle of major thirds
51 m_Basis[i].resize(12);
52 for (int iP = 0; iP < 12; iP++)
54 m_Basis[i][iP] = 0.6 * std::sin( (2.0 / 3.0) * iP * PI);
57 i++;
59 m_Basis[i].resize(12);
60 for (int iP = 0; iP < 12; iP++)
62 m_Basis[i][iP] = 0.6 * std::cos( (2.0 / 3.0) * iP * PI);
65 i++;
68 // circle of minor thirds
69 m_Basis[i].resize(12);
70 for (int iP = 0; iP < 12; iP++)
72 m_Basis[i][iP] = 1.1 * std::sin( (3.0 / 2.0) * iP * PI);
75 i++;
77 m_Basis[i].resize(12);
78 for (int iP = 0; iP < 12; iP++)
80 m_Basis[i][iP] = 1.1 * std::cos( (3.0 / 2.0) * iP * PI);
85 TonalEstimator::~TonalEstimator()
89 TCSVector TonalEstimator::transform2TCS(const ChromaVector& rVector)
91 TCSVector vaRetVal;
92 vaRetVal.resize(6, 0.0);
94 for (int i = 0; i < 6; i++)
96 for (int iP = 0; iP < 12; iP++)
98 vaRetVal[i] += m_Basis[i][iP] * rVector[iP];
102 return vaRetVal;