annotate dsp/rhythm/BeatSpectrum.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 43943a4382ef
children e5907ae6de17
rev   line source
c@256 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
c@256 2
c@256 3 /*
c@256 4 QM DSP Library
c@256 5
c@256 6 Centre for Digital Music, Queen Mary, University of London.
c@256 7 This file copyright 2008 Kurt Jacobson and QMUL.
c@256 8 All rights reserved.
c@256 9 */
c@256 10
c@256 11 #include "BeatSpectrum.h"
c@256 12
c@256 13 #include "maths/CosineDistance.h"
c@256 14
c@256 15 using std::vector;
c@256 16
c@256 17 vector<double> BeatSpectrum::process(const vector<vector<double> > &m)
c@256 18 {
c@256 19 int origin = 0;
c@256 20 int sz = m.size()/2;
c@256 21
c@256 22 int i, j, k;
c@256 23
c@256 24 vector<double> v(sz);
c@256 25 for (i = 0; i < sz; ++i) v[i] = 0.0;
c@256 26
c@256 27 CosineDistance cd;
c@256 28
c@256 29 for (i = origin; i < origin + sz; ++i) {
c@256 30
c@256 31 k = 0;
c@256 32
c@256 33 for (j = i + 1; j < i + sz + 1; ++j) {
c@256 34
c@256 35 v[k++] += cd.distance(m[i], m[j]);
c@256 36 }
c@256 37 }
c@256 38
c@256 39 // normalize
c@256 40
c@256 41 double max = 0.0;
c@256 42
c@256 43 for (i = 0; i < sz; ++i) {
c@256 44 if (v[i] > max) max = v[i];
c@256 45 }
c@256 46
c@256 47 if (max > 0.0) {
c@256 48 for (i = 0; i < sz; ++i) {
c@256 49 v[i] /= max;
c@256 50 }
c@256 51 }
c@256 52
c@256 53 return v;
c@256 54 }
c@256 55