annotate dsp/tonal/TonalEstimator.cpp @ 482:cbe668c7d724

Untabify, indent, tidy
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 31 May 2019 11:02:28 +0100
parents d5014ab8b0e5
children 7992d0923626
rev   line source
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 #ifndef PI
c@225 22 #define PI (3.14159265358979232846)
c@225 23 #endif
c@225 24
c@225 25 TonalEstimator::TonalEstimator()
c@225 26 {
cannam@482 27 m_Basis.resize(6);
c@225 28
cannam@482 29 int i = 0;
cannam@482 30
cannam@482 31
cannam@482 32 // circle of fifths
cannam@482 33 m_Basis[i].resize(12);
cannam@482 34 for (int iP = 0; iP < 12; iP++) {
cannam@482 35 m_Basis[i][iP] = std::sin( (7.0 / 6.0) * iP * PI);
cannam@482 36 }
cannam@482 37
cannam@482 38 i++;
c@225 39
cannam@482 40 m_Basis[i].resize(12);
cannam@482 41 for (int iP = 0; iP < 12; iP++) {
cannam@482 42 m_Basis[i][iP] = std::cos( (7.0 / 6.0) * iP * PI);
cannam@482 43 }
cannam@482 44
cannam@482 45 i++;
cannam@482 46
cannam@482 47
cannam@482 48 // circle of major thirds
cannam@482 49 m_Basis[i].resize(12);
cannam@482 50 for (int iP = 0; iP < 12; iP++) {
cannam@482 51 m_Basis[i][iP] = 0.6 * std::sin( (2.0 / 3.0) * iP * PI);
cannam@482 52 }
cannam@482 53
cannam@482 54 i++;
c@225 55
cannam@482 56 m_Basis[i].resize(12);
cannam@482 57 for (int iP = 0; iP < 12; iP++) {
cannam@482 58 m_Basis[i][iP] = 0.6 * std::cos( (2.0 / 3.0) * iP * PI);
cannam@482 59 }
c@225 60
cannam@482 61 i++;
c@225 62
c@225 63
cannam@482 64 // circle of minor thirds
cannam@482 65 m_Basis[i].resize(12);
cannam@482 66 for (int iP = 0; iP < 12; iP++) {
cannam@482 67 m_Basis[i][iP] = 1.1 * std::sin( (3.0 / 2.0) * iP * PI);
cannam@482 68 }
cannam@482 69
cannam@482 70 i++;
c@225 71
cannam@482 72 m_Basis[i].resize(12);
cannam@482 73 for (int iP = 0; iP < 12; iP++) {
cannam@482 74 m_Basis[i][iP] = 1.1 * std::cos( (3.0 / 2.0) * iP * PI);
cannam@482 75 }
c@225 76
c@225 77 }
c@225 78
c@225 79 TonalEstimator::~TonalEstimator()
c@225 80 {
c@225 81 }
c@225 82
c@225 83 TCSVector TonalEstimator::transform2TCS(const ChromaVector& rVector)
c@225 84 {
cannam@482 85 TCSVector vaRetVal;
cannam@482 86 vaRetVal.resize(6, 0.0);
cannam@482 87
cannam@482 88 for (int i = 0; i < 6; i++) {
cannam@482 89 for (int iP = 0; iP < 12; iP++) {
cannam@482 90 vaRetVal[i] += m_Basis[i][iP] * rVector[iP];
cannam@482 91 }
cannam@482 92 }
cannam@482 93
cannam@482 94 return vaRetVal;
c@225 95 }