annotate dsp/chromagram/ConstantQ.h @ 73:dcb555b90924

* 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 cannam
date Fri, 05 Jun 2009 15:12:39 +0000
parents 114e833c07ac
children e5907ae6de17
rev   line source
cannam@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@0 2
cannam@0 3 /*
cannam@0 4 QM DSP Library
cannam@0 5
cannam@0 6 Centre for Digital Music, Queen Mary, University of London.
cannam@0 7 This file copyright 2005-2006 Christian Landone.
cannam@0 8 All rights reserved.
cannam@0 9 */
cannam@0 10
cannam@0 11 #ifndef CONSTANTQ_H
cannam@0 12 #define CONSTANTQ_H
cannam@0 13
cannam@0 14 #include <vector>
cannam@16 15 #include "maths/MathAliases.h"
cannam@16 16 #include "maths/MathUtilities.h"
cannam@0 17
cannam@0 18 struct CQConfig{
cannam@20 19 unsigned int FS; // samplerate
cannam@20 20 double min; // minimum frequency
cannam@20 21 double max; // maximum frequency
cannam@20 22 unsigned int BPO; // bins per octave
cannam@20 23 double CQThresh; // threshold
cannam@0 24 };
cannam@0 25
cannam@0 26 class ConstantQ {
cannam@0 27
cannam@0 28 //public functions incl. sparsekernel so can keep out of loop in main
cannam@0 29 public:
cannam@32 30 void process( const double* FFTRe, const double* FFTIm,
cannam@32 31 double* CQRe, double* CQIm );
cannam@0 32
cannam@0 33 ConstantQ( CQConfig Config );
cannam@0 34 ~ConstantQ();
cannam@0 35
cannam@32 36 double* process( const double* FFTData );
cannam@0 37
cannam@0 38 void sparsekernel();
cannam@0 39
cannam@0 40 double hamming(int len, int n) {
cannam@0 41 double out = 0.54 - 0.46*cos(2*PI*n/len);
cannam@0 42 return(out);
cannam@0 43 }
cannam@0 44
cannam@0 45 int getnumwin() { return m_numWin;}
cannam@0 46 double getQ() { return m_dQ;}
cannam@0 47 int getK() {return m_uK ;}
cannam@0 48 int getfftlength() { return m_FFTLength;}
cannam@0 49 int gethop() { return m_hop;}
cannam@0 50
cannam@0 51 private:
cannam@0 52 void initialise( CQConfig Config );
cannam@0 53 void deInitialise();
cannam@0 54
cannam@0 55 double* m_CQdata;
cannam@0 56 unsigned int m_FS;
cannam@0 57 double m_FMin;
cannam@0 58 double m_FMax;
cannam@0 59 double m_dQ;
cannam@0 60 double m_CQThresh;
cannam@0 61 unsigned int m_numWin;
cannam@0 62 unsigned int m_hop;
cannam@0 63 unsigned int m_BPO;
cannam@0 64 unsigned int m_FFTLength;
cannam@0 65 unsigned int m_uK;
cannam@51 66
cannam@51 67 struct SparseKernel {
cannam@51 68 std::vector<unsigned> is;
cannam@51 69 std::vector<unsigned> js;
cannam@51 70 std::vector<double> imag;
cannam@51 71 std::vector<double> real;
cannam@51 72 };
cannam@51 73
cannam@51 74 SparseKernel *m_sparseKernel;
cannam@0 75 };
cannam@0 76
cannam@0 77
cannam@0 78 #endif//CONSTANTQ_H
cannam@0 79