diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2011-03-02 12:37:39 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2011-03-02 12:37:39 +0000 |
commit | 3deba1921bcf5bddd8bea9846a203c92b6c9239d (patch) | |
tree | 8b2e00405337396918ff28e282df14e958b84bb9 /libs/qm-dsp/dsp/tonal/TonalEstimator.cpp | |
parent | fa41cfef580b2c8c04adec5b47d6cfa415ca6251 (diff) |
add queen mary DSP library
git-svn-id: svn://localhost/ardour2/branches/3.0@9029 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/qm-dsp/dsp/tonal/TonalEstimator.cpp')
-rw-r--r-- | libs/qm-dsp/dsp/tonal/TonalEstimator.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/libs/qm-dsp/dsp/tonal/TonalEstimator.cpp b/libs/qm-dsp/dsp/tonal/TonalEstimator.cpp new file mode 100644 index 0000000000..16d1aa8995 --- /dev/null +++ b/libs/qm-dsp/dsp/tonal/TonalEstimator.cpp @@ -0,0 +1,103 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + QM DSP Library + + Centre for Digital Music, Queen Mary, University of London. + This file copyright 2006 Martin Gasser. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#include "TonalEstimator.h" + +#include <cmath> +#include <iostream> + +#ifndef PI +#define PI (3.14159265358979232846) +#endif + +TonalEstimator::TonalEstimator() +{ + m_Basis.resize(6); + + int i = 0; + + + // circle of fifths + m_Basis[i].resize(12); + for (int iP = 0; iP < 12; iP++) + { + m_Basis[i][iP] = std::sin( (7.0 / 6.0) * iP * PI); + } + + i++; + + m_Basis[i].resize(12); + for (int iP = 0; iP < 12; iP++) + { + m_Basis[i][iP] = std::cos( (7.0 / 6.0) * iP * PI); + } + + i++; + + + // circle of major thirds + m_Basis[i].resize(12); + for (int iP = 0; iP < 12; iP++) + { + m_Basis[i][iP] = 0.6 * std::sin( (2.0 / 3.0) * iP * PI); + } + + i++; + + m_Basis[i].resize(12); + for (int iP = 0; iP < 12; iP++) + { + m_Basis[i][iP] = 0.6 * std::cos( (2.0 / 3.0) * iP * PI); + } + + i++; + + + // circle of minor thirds + m_Basis[i].resize(12); + for (int iP = 0; iP < 12; iP++) + { + m_Basis[i][iP] = 1.1 * std::sin( (3.0 / 2.0) * iP * PI); + } + + i++; + + m_Basis[i].resize(12); + for (int iP = 0; iP < 12; iP++) + { + m_Basis[i][iP] = 1.1 * std::cos( (3.0 / 2.0) * iP * PI); + } + +} + +TonalEstimator::~TonalEstimator() +{ +} + +TCSVector TonalEstimator::transform2TCS(const ChromaVector& rVector) +{ + TCSVector vaRetVal; + vaRetVal.resize(6, 0.0); + + for (int i = 0; i < 6; i++) + { + for (int iP = 0; iP < 12; iP++) + { + vaRetVal[i] += m_Basis[i][iP] * rVector[iP]; + } + } + + return vaRetVal; +} |