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@225: All rights reserved. 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: { c@225: m_Basis.resize(6); c@225: c@225: int i = 0; c@225: c@225: c@225: // circle of fifths c@225: m_Basis[i].resize(12); c@225: for (int iP = 0; iP < 12; iP++) c@225: { c@225: m_Basis[i][iP] = std::sin( (7.0 / 6.0) * iP * PI); c@225: } c@225: c@225: i++; c@225: c@225: m_Basis[i].resize(12); c@225: for (int iP = 0; iP < 12; iP++) c@225: { c@225: m_Basis[i][iP] = std::cos( (7.0 / 6.0) * iP * PI); c@225: } c@225: c@225: i++; c@225: c@225: c@225: // circle of major thirds c@225: m_Basis[i].resize(12); c@225: for (int iP = 0; iP < 12; iP++) c@225: { c@225: m_Basis[i][iP] = 0.6 * std::sin( (2.0 / 3.0) * iP * PI); c@225: } c@225: c@225: i++; c@225: c@225: m_Basis[i].resize(12); c@225: for (int iP = 0; iP < 12; iP++) c@225: { c@225: m_Basis[i][iP] = 0.6 * std::cos( (2.0 / 3.0) * iP * PI); c@225: } c@225: c@225: i++; c@225: c@225: c@225: // circle of minor thirds c@225: m_Basis[i].resize(12); c@225: for (int iP = 0; iP < 12; iP++) c@225: { c@225: m_Basis[i][iP] = 1.1 * std::sin( (3.0 / 2.0) * iP * PI); c@225: } c@225: c@225: i++; c@225: c@225: m_Basis[i].resize(12); c@225: for (int iP = 0; iP < 12; iP++) c@225: { c@225: m_Basis[i][iP] = 1.1 * std::cos( (3.0 / 2.0) * iP * PI); c@225: } 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: { c@225: TCSVector vaRetVal; c@225: vaRetVal.resize(6, 0.0); c@225: c@225: for (int i = 0; i < 6; i++) c@225: { c@225: for (int iP = 0; iP < 12; iP++) c@225: { c@225: vaRetVal[i] += m_Basis[i][iP] * rVector[iP]; c@225: } c@225: } c@225: c@225: return vaRetVal; c@225: }