c@225: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ c@225: c@225: /* c@225: QM DSP Library c@225: c@225: Centre for Digital Music, Queen Mary, University of London. c@225: This file copyright 2006 Martin Gasser. c@309: c@309: This program is free software; you can redistribute it and/or c@309: modify it under the terms of the GNU General Public License as c@309: published by the Free Software Foundation; either version 2 of the c@309: License, or (at your option) any later version. See the file c@309: COPYING included with this distribution for more information. c@225: */ c@225: c@225: #include "TonalEstimator.h" c@225: c@225: #include c@225: #include c@225: c@225: #ifndef PI c@225: #define PI (3.14159265358979232846) c@225: #endif c@225: c@225: TonalEstimator::TonalEstimator() c@225: { cannam@482: m_Basis.resize(6); c@225: cannam@482: int i = 0; cannam@482: cannam@482: cannam@482: // circle of fifths cannam@482: m_Basis[i].resize(12); cannam@482: for (int iP = 0; iP < 12; iP++) { cannam@482: m_Basis[i][iP] = std::sin( (7.0 / 6.0) * iP * PI); cannam@482: } cannam@482: cannam@482: i++; c@225: cannam@482: m_Basis[i].resize(12); cannam@482: for (int iP = 0; iP < 12; iP++) { cannam@482: m_Basis[i][iP] = std::cos( (7.0 / 6.0) * iP * PI); cannam@482: } cannam@482: cannam@482: i++; cannam@482: cannam@482: cannam@482: // circle of major thirds cannam@482: m_Basis[i].resize(12); cannam@482: for (int iP = 0; iP < 12; iP++) { cannam@482: m_Basis[i][iP] = 0.6 * std::sin( (2.0 / 3.0) * iP * PI); cannam@482: } cannam@482: cannam@482: i++; c@225: cannam@482: m_Basis[i].resize(12); cannam@482: for (int iP = 0; iP < 12; iP++) { cannam@482: m_Basis[i][iP] = 0.6 * std::cos( (2.0 / 3.0) * iP * PI); cannam@482: } c@225: cannam@482: i++; c@225: c@225: cannam@482: // circle of minor thirds cannam@482: m_Basis[i].resize(12); cannam@482: for (int iP = 0; iP < 12; iP++) { cannam@482: m_Basis[i][iP] = 1.1 * std::sin( (3.0 / 2.0) * iP * PI); cannam@482: } cannam@482: cannam@482: i++; c@225: cannam@482: m_Basis[i].resize(12); cannam@482: for (int iP = 0; iP < 12; iP++) { cannam@482: m_Basis[i][iP] = 1.1 * std::cos( (3.0 / 2.0) * iP * PI); cannam@482: } c@225: c@225: } c@225: c@225: TonalEstimator::~TonalEstimator() c@225: { c@225: } c@225: c@225: TCSVector TonalEstimator::transform2TCS(const ChromaVector& rVector) c@225: { cannam@482: TCSVector vaRetVal; cannam@482: vaRetVal.resize(6, 0.0); cannam@482: cannam@482: for (int i = 0; i < 6; i++) { cannam@482: for (int iP = 0; iP < 12; iP++) { cannam@482: vaRetVal[i] += m_Basis[i][iP] * rVector[iP]; cannam@482: } cannam@482: } cannam@482: cannam@482: return vaRetVal; c@225: }