Mercurial > hg > qm-dsp
view 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 |
line wrap: on
line source
/* -*- 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. All rights reserved. */ #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; }