annotate dsp/tonal/TonalEstimator.cpp @ 298:255e431ae3d4

* Key detector: when returning key strengths, use the peak value of the three underlying chromagram correlations (from 36-bin chromagram) corresponding to each key, instead of the mean. Rationale: This is the same method as used when returning the key value, and it's nice to have the same results in both returned value and plot. The peak performed better than the sum with a simple test set of triads, so it seems reasonable to change the plot to match the key output rather than the other way around. * FFT: kiss_fftr returns only the non-conjugate bins, synthesise the rest rather than leaving them (perhaps dangerously) undefined. Fixes an uninitialised data error in chromagram that could cause garbage results from key detector. * Constant Q: remove precalculated values again, I reckon they're not proving such a good tradeoff.
author Chris Cannam <c.cannam@qmul.ac.uk>
date Fri, 05 Jun 2009 15:12:39 +0000
parents 49844bc8a895
children e5907ae6de17
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@225 8 All rights reserved.
c@225 9 */
c@225 10
c@225 11 #include "TonalEstimator.h"
c@225 12
c@225 13 #include <cmath>
c@225 14 #include <iostream>
c@225 15
c@225 16 #ifndef PI
c@225 17 #define PI (3.14159265358979232846)
c@225 18 #endif
c@225 19
c@225 20 TonalEstimator::TonalEstimator()
c@225 21 {
c@225 22 m_Basis.resize(6);
c@225 23
c@225 24 int i = 0;
c@225 25
c@225 26
c@225 27 // circle of fifths
c@225 28 m_Basis[i].resize(12);
c@225 29 for (int iP = 0; iP < 12; iP++)
c@225 30 {
c@225 31 m_Basis[i][iP] = std::sin( (7.0 / 6.0) * iP * PI);
c@225 32 }
c@225 33
c@225 34 i++;
c@225 35
c@225 36 m_Basis[i].resize(12);
c@225 37 for (int iP = 0; iP < 12; iP++)
c@225 38 {
c@225 39 m_Basis[i][iP] = std::cos( (7.0 / 6.0) * iP * PI);
c@225 40 }
c@225 41
c@225 42 i++;
c@225 43
c@225 44
c@225 45 // circle of major thirds
c@225 46 m_Basis[i].resize(12);
c@225 47 for (int iP = 0; iP < 12; iP++)
c@225 48 {
c@225 49 m_Basis[i][iP] = 0.6 * std::sin( (2.0 / 3.0) * iP * PI);
c@225 50 }
c@225 51
c@225 52 i++;
c@225 53
c@225 54 m_Basis[i].resize(12);
c@225 55 for (int iP = 0; iP < 12; iP++)
c@225 56 {
c@225 57 m_Basis[i][iP] = 0.6 * std::cos( (2.0 / 3.0) * iP * PI);
c@225 58 }
c@225 59
c@225 60 i++;
c@225 61
c@225 62
c@225 63 // circle of minor thirds
c@225 64 m_Basis[i].resize(12);
c@225 65 for (int iP = 0; iP < 12; iP++)
c@225 66 {
c@225 67 m_Basis[i][iP] = 1.1 * std::sin( (3.0 / 2.0) * iP * PI);
c@225 68 }
c@225 69
c@225 70 i++;
c@225 71
c@225 72 m_Basis[i].resize(12);
c@225 73 for (int iP = 0; iP < 12; iP++)
c@225 74 {
c@225 75 m_Basis[i][iP] = 1.1 * std::cos( (3.0 / 2.0) * iP * PI);
c@225 76 }
c@225 77
c@225 78 }
c@225 79
c@225 80 TonalEstimator::~TonalEstimator()
c@225 81 {
c@225 82 }
c@225 83
c@225 84 TCSVector TonalEstimator::transform2TCS(const ChromaVector& rVector)
c@225 85 {
c@225 86 TCSVector vaRetVal;
c@225 87 vaRetVal.resize(6, 0.0);
c@225 88
c@225 89 for (int i = 0; i < 6; i++)
c@225 90 {
c@225 91 for (int iP = 0; iP < 12; iP++)
c@225 92 {
c@225 93 vaRetVal[i] += m_Basis[i][iP] * rVector[iP];
c@225 94 }
c@225 95 }
c@225 96
c@225 97 return vaRetVal;
c@225 98 }