Merge branch 'windows' of git.ardour.org:ardour/ardour into windows
[ardour.git] / libs / qm-dsp / dsp / tempotracking / TempoTrack.h
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */\r
2 \r
3 /*\r
4     QM DSP Library\r
5 \r
6     Centre for Digital Music, Queen Mary, University of London.\r
7     This file 2005-2006 Christian Landone.\r
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.\r
14 */\r
15 \r
16 #ifndef TEMPOTRACK_H\r
17 #define TEMPOTRACK_H\r
18 \r
19 \r
20 #include <stdio.h>\r
21 #include <vector>\r
22 \r
23 #include "dsp/signalconditioning/DFProcess.h"\r
24 #include "maths/Correlation.h"\r
25 #include "dsp/signalconditioning/Framer.h"\r
26 \r
27 \r
28 \r
29 using std::vector;\r
30 \r
31 struct WinThresh\r
32 {\r
33     unsigned int pre;\r
34     unsigned int  post;\r
35 };\r
36 \r
37 struct TTParams\r
38 {\r
39     unsigned int winLength; //Analysis window length\r
40     unsigned int lagLength; //Lag & Stride size\r
41     unsigned int alpha; //alpha-norm parameter\r
42     unsigned int LPOrd; // low-pass Filter order\r
43     double* LPACoeffs; //low pass Filter den coefficients\r
44     double* LPBCoeffs; //low pass Filter num coefficients\r
45     WinThresh WinT;//window size in frames for adaptive thresholding [pre post]:\r
46 };\r
47 \r
48 \r
49 class TempoTrack  \r
50 {\r
51 public:\r
52     TempoTrack( TTParams Params );\r
53     virtual ~TempoTrack();\r
54 \r
55     vector<int> process( vector <double> DF, vector <double> *tempoReturn = 0);\r
56 \r
57         \r
58 private:\r
59     void initialise( TTParams Params );\r
60     void deInitialise();\r
61 \r
62     int beatPredict( unsigned int FSP, double alignment, double period, unsigned int step);\r
63     int phaseMM( double* DF, double* weighting, unsigned int winLength, double period );\r
64     void createPhaseExtractor( double* Filter, unsigned int winLength,  double period,  unsigned int fsp, unsigned int lastBeat );\r
65     int findMeter( double* ACF,  unsigned int len, double period );\r
66     void constDetect( double* periodP, int currentIdx, int* flag );\r
67     void stepDetect( double* periodP, double* periodG, int currentIdx, int* flag );\r
68     void createCombFilter( double* Filter, unsigned int winLength, unsigned int TSig, double beatLag );\r
69     double tempoMM( double* ACF, double* weight, int sig );\r
70         \r
71     unsigned int m_dataLength;\r
72     unsigned int m_winLength;\r
73     unsigned int m_lagLength;\r
74 \r
75     double               m_rayparam;\r
76     double               m_sigma;\r
77     double               m_DFWVNnorm;\r
78 \r
79     vector<int>  m_beats; // Vector of detected beats\r
80 \r
81     double m_lockedTempo;\r
82 \r
83     double* m_tempoScratch;\r
84     double* m_smoothRCF; // Smoothed Output of Comb Filterbank (m_tempoScratch)\r
85         \r
86     // Processing Buffers \r
87     double* m_rawDFFrame; // Original Detection Function Analysis Frame\r
88     double* m_smoothDFFrame; // Smoothed Detection Function Analysis Frame\r
89     double* m_frameACF; // AutoCorrelation of Smoothed Detection Function \r
90 \r
91     //Low Pass Coefficients for DF Smoothing\r
92     double* m_ACoeffs;\r
93     double* m_BCoeffs;\r
94         \r
95     // Objetcs/operators declaration\r
96     Framer m_DFFramer;\r
97     DFProcess* m_DFConditioning;\r
98     Correlation m_correlator;\r
99     // Config structure for DFProcess\r
100     DFProcConfig m_DFPParams;\r
101 \r
102         // also want to smooth m_tempoScratch \r
103     DFProcess* m_RCFConditioning;\r
104     // Config structure for RCFProcess\r
105     DFProcConfig m_RCFPParams;\r
106 \r
107 \r
108 \r
109 };\r
110 \r
111 #endif\r