qm-dsp  1.8
TonalEstimator.cpp
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     QM DSP Library
00005 
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2006 Martin Gasser.
00008 
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #include "TonalEstimator.h"
00017 
00018 #include <cmath>
00019 #include <iostream>
00020 
00021 #ifndef PI
00022 #define PI (3.14159265358979232846)
00023 #endif
00024 
00025 TonalEstimator::TonalEstimator()
00026 {
00027         m_Basis.resize(6);
00028 
00029         int i = 0;
00030         
00031         
00032         // circle of fifths
00033         m_Basis[i].resize(12);
00034         for (int iP = 0; iP < 12; iP++)
00035         {
00036                 m_Basis[i][iP] = std::sin( (7.0 / 6.0) * iP * PI);
00037         }
00038         
00039         i++;
00040 
00041         m_Basis[i].resize(12);
00042         for (int iP = 0; iP < 12; iP++)
00043         {
00044                 m_Basis[i][iP] = std::cos( (7.0 / 6.0) * iP * PI);
00045         }
00046         
00047         i++;
00048         
00049         
00050         // circle of major thirds
00051         m_Basis[i].resize(12);
00052         for (int iP = 0; iP < 12; iP++)
00053         {
00054                 m_Basis[i][iP] = 0.6 * std::sin( (2.0 / 3.0) * iP * PI);
00055         }
00056         
00057         i++;
00058 
00059         m_Basis[i].resize(12);
00060         for (int iP = 0; iP < 12; iP++)
00061         {
00062                 m_Basis[i][iP] = 0.6 * std::cos( (2.0 / 3.0) * iP * PI);
00063         }
00064 
00065         i++;
00066 
00067 
00068         // circle of minor thirds
00069         m_Basis[i].resize(12);
00070         for (int iP = 0; iP < 12; iP++)
00071         {
00072                 m_Basis[i][iP] = 1.1 * std::sin( (3.0 / 2.0) * iP * PI);
00073         }
00074         
00075         i++;
00076 
00077         m_Basis[i].resize(12);
00078         for (int iP = 0; iP < 12; iP++)
00079         {
00080                 m_Basis[i][iP] = 1.1 * std::cos( (3.0 / 2.0) * iP * PI);
00081         }
00082 
00083 }
00084 
00085 TonalEstimator::~TonalEstimator()
00086 {
00087 }
00088 
00089 TCSVector TonalEstimator::transform2TCS(const ChromaVector& rVector)
00090 {
00091         TCSVector vaRetVal;
00092         vaRetVal.resize(6, 0.0);
00093                 
00094         for (int i = 0; i < 6; i++)
00095         {
00096                 for (int iP = 0; iP < 12; iP++)
00097                 {
00098                         vaRetVal[i] += m_Basis[i][iP] * rVector[iP];
00099                 }
00100         }
00101         
00102         return vaRetVal;
00103 }