annotate dsp/tonal/TonalEstimator.h @ 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 c88fb48790d9
children 769da847732b
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 #ifndef _TONALESTIMATOR_
c@225 12 #define _TONALESTIMATOR_
c@225 13
c@225 14
c@225 15 #include <valarray>
c@225 16 #include <numeric>
c@225 17 #include <algorithm>
c@225 18 #include <iostream>
c@225 19
c@225 20 class ChromaVector : public std::valarray<double>
c@225 21 {
c@225 22 public:
c@225 23 ChromaVector(size_t uSize = 12) : std::valarray<double>()
c@225 24 { resize(uSize, 0.0f); }
c@225 25
c@225 26 virtual ~ChromaVector() {};
c@225 27
c@225 28 void printDebug()
c@225 29 {
c@225 30 for (int i = 0; i < size(); i++)
c@225 31 {
c@225 32 std::cout << (*this)[i] << ";";
c@225 33 }
c@225 34
c@225 35 std::cout << std::endl;
c@225 36 }
c@225 37
c@225 38 void normalizeL1()
c@225 39 {
c@225 40 // normalize the chroma vector (L1 norm)
c@225 41 double dSum = 0.0;
c@225 42
c@285 43 for (size_t i = 0; i < 12; (dSum += std::abs((*this)[i++]))) ;
c@285 44 for (size_t i = 0; i < 12; dSum > 0.0000001?((*this)[i] /= dSum):(*this)[i]=0.0, i++) ;
c@225 45
c@225 46 }
c@225 47
c@225 48 };
c@225 49
c@225 50 class TCSVector : public std::valarray<double>
c@225 51 {
c@225 52 public:
c@225 53 TCSVector() : std::valarray<double>()
c@225 54 { resize(6, 0.0f); }
c@225 55
c@225 56 virtual ~TCSVector() {};
c@225 57
c@225 58 void printDebug()
c@225 59 {
c@225 60 for (int i = 0; i < size(); i++)
c@225 61 {
c@225 62 std::cout << (*this)[i] << ";";
c@225 63 }
c@225 64
c@225 65 std::cout << std::endl;
c@225 66 }
c@225 67
c@225 68 double magnitude() const
c@225 69 {
c@225 70 double dMag = 0.0;
c@225 71
c@225 72 for (size_t i = 0; i < 6; i++)
c@225 73 {
c@225 74 dMag += std::pow((*this)[i], 2.0);
c@225 75 }
c@225 76
c@225 77 return std::sqrt(dMag);
c@225 78 }
c@225 79
c@225 80 };
c@225 81
c@225 82
c@225 83
c@225 84 class TonalEstimator
c@225 85 {
c@225 86 public:
c@225 87 TonalEstimator();
c@225 88 virtual ~TonalEstimator();
c@225 89 TCSVector transform2TCS(const ChromaVector& rVector);
c@225 90 protected:
c@225 91 std::valarray< std::valarray<double> > m_Basis;
c@225 92 };
c@225 93
c@225 94 #endif // _TONALESTIMATOR_