c06f60a9d010f07a498b9e1654b957a631e53e27
[ardour.git] / libs / qm-dsp / dsp / chromagram / ConstantQ.h
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2
3 /*
4     QM DSP Library
5
6     Centre for Digital Music, Queen Mary, University of London.
7     This file 2005-2006 Christian Landone.
8
9     This program is free software; you can redistribute it and/or
10     modify it under the terms of the GNU General Public License as
11     published by the Free Software Foundation; either version 2 of the
12     License, or (at your option) any later version.  See the file
13     COPYING included with this distribution for more information.
14 */
15
16 #ifndef CONSTANTQ_H
17 #define CONSTANTQ_H
18
19 #include <vector>
20 #include "maths/MathAliases.h"
21 #include "maths/MathUtilities.h"
22
23 struct CQConfig{
24     unsigned int FS;   // samplerate
25     double min;        // minimum frequency
26     double max;        // maximum frequency
27     unsigned int BPO;  // bins per octave
28     double CQThresh;   // threshold
29 };
30
31 class ConstantQ {
32         
33 //public functions incl. sparsekernel so can keep out of loop in main
34 public:
35     void process( const double* FFTRe, const double* FFTIm,
36                   double* CQRe, double* CQIm );
37
38     ConstantQ( CQConfig Config );
39     ~ConstantQ();
40
41     double* process( const double* FFTData );
42
43     void sparsekernel();
44
45     double hamming(int len, int n) {
46         double out = 0.54 - 0.46*cos(2*PI*n/len);
47         return(out);
48     }
49         
50     int getnumwin() { return m_numWin;}
51     double getQ() { return m_dQ;}
52     int getK() {return m_uK ;}
53     int getfftlength() { return m_FFTLength;}
54     int gethop() { return m_hop;}
55
56 private:
57     void initialise( CQConfig Config );
58     void deInitialise();
59         
60     double* m_CQdata;
61     unsigned int m_FS;
62     double m_FMin;
63     double m_FMax;
64     double m_dQ;
65     double m_CQThresh;
66     unsigned int m_numWin;
67     unsigned int m_hop;
68     unsigned int m_BPO;
69     unsigned int m_FFTLength;
70     unsigned int m_uK;
71
72     struct SparseKernel {
73         std::vector<unsigned> is;
74         std::vector<unsigned> js;
75         std::vector<double> imag;
76         std::vector<double> real;
77     };
78
79     SparseKernel *m_sparseKernel;
80 };
81
82
83 #endif//CONSTANTQ_H
84