cannam@52
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
cannam@52
|
2
|
cannam@52
|
3 /*
|
cannam@52
|
4 QM DSP Library
|
cannam@52
|
5
|
cannam@52
|
6 Centre for Digital Music, Queen Mary, University of London.
|
cannam@52
|
7 This file copyright 2008-2009 Matthew Davies and QMUL.
|
Chris@84
|
8
|
Chris@84
|
9 This program is free software; you can redistribute it and/or
|
Chris@84
|
10 modify it under the terms of the GNU General Public License as
|
Chris@84
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@84
|
12 License, or (at your option) any later version. See the file
|
Chris@84
|
13 COPYING included with this distribution for more information.
|
cannam@52
|
14 */
|
cannam@52
|
15
|
cannam@52
|
16
|
cannam@52
|
17 #ifndef TEMPOTRACKV2_H
|
cannam@52
|
18 #define TEMPOTRACKV2_H
|
cannam@52
|
19
|
cannam@52
|
20 #include <vector>
|
luis@100
|
21 using namespace std;
|
cannam@52
|
22
|
cannam@54
|
23 //!!! Question: how far is this actually sample rate dependent? I
|
cannam@54
|
24 // think it does produce plausible results for e.g. 48000 as well as
|
cannam@54
|
25 // 44100, but surely the fixed window sizes and comb filtering will
|
cannam@54
|
26 // make it prefer double or half time when run at e.g. 96000?
|
cannam@54
|
27
|
luis@100
|
28 class TempoTrackV2
|
cannam@52
|
29 {
|
cannam@52
|
30 public:
|
cannam@54
|
31 /**
|
cannam@54
|
32 * Construct a tempo tracker that will operate on beat detection
|
cannam@54
|
33 * function data calculated from audio at the given sample rate
|
cannam@54
|
34 * with the given frame increment.
|
cannam@54
|
35 *
|
cannam@54
|
36 * Currently the sample rate and increment are used only for the
|
cannam@54
|
37 * conversion from beat frame location to bpm in the tempo array.
|
cannam@54
|
38 */
|
cannam@54
|
39 TempoTrackV2(float sampleRate, size_t dfIncrement);
|
cannam@52
|
40 ~TempoTrackV2();
|
cannam@52
|
41
|
luis@100
|
42 // Returned beat periods are given in df increment units; inputtempo and tempi in bpm
|
cannam@52
|
43 void calculateBeatPeriod(const vector<double> &df,
|
cannam@53
|
44 vector<double> &beatPeriod,
|
Chris@161
|
45 vector<double> &tempi) {
|
Chris@161
|
46 calculateBeatPeriod(df, beatPeriod, tempi, 120.0, false);
|
Chris@161
|
47 }
|
Chris@161
|
48
|
Chris@161
|
49 // Returned beat periods are given in df increment units; inputtempo and tempi in bpm
|
Chris@161
|
50 // MEPD 28/11/12 Expose inputtempo and constraintempo parameters
|
Chris@161
|
51 // Note, if inputtempo = 120 and constraintempo = false, then functionality is as it was before
|
Chris@161
|
52 void calculateBeatPeriod(const vector<double> &df,
|
Chris@161
|
53 vector<double> &beatPeriod,
|
Chris@161
|
54 vector<double> &tempi,
|
Chris@161
|
55 double inputtempo, bool constraintempo);
|
Chris@161
|
56
|
Chris@161
|
57 // Returned beat positions are given in df increment units
|
Chris@161
|
58 void calculateBeats(const vector<double> &df,
|
Chris@161
|
59 const vector<double> &beatPeriod,
|
Chris@161
|
60 vector<double> &beats) {
|
Chris@161
|
61 calculateBeats(df, beatPeriod, beats, 0.9, 4.0);
|
Chris@161
|
62 }
|
cannam@52
|
63
|
cannam@54
|
64 // Returned beat positions are given in df increment units
|
luis@100
|
65 // MEPD 28/11/12 Expose alpha and tightness parameters
|
Chris@161
|
66 // Note, if alpha = 0.9 and tightness = 4, then functionality is as it was before
|
cannam@52
|
67 void calculateBeats(const vector<double> &df,
|
cannam@52
|
68 const vector<double> &beatPeriod,
|
Chris@161
|
69 vector<double> &beats,
|
Chris@161
|
70 double alpha, double tightness);
|
cannam@52
|
71
|
cannam@52
|
72 private:
|
cannam@52
|
73 typedef vector<int> i_vec_t;
|
cannam@52
|
74 typedef vector<vector<int> > i_mat_t;
|
cannam@52
|
75 typedef vector<double> d_vec_t;
|
cannam@52
|
76 typedef vector<vector<double> > d_mat_t;
|
cannam@52
|
77
|
cannam@54
|
78 float m_rate;
|
cannam@54
|
79 size_t m_increment;
|
cannam@54
|
80
|
cannam@52
|
81 void adapt_thresh(d_vec_t &df);
|
cannam@52
|
82 double mean_array(const d_vec_t &dfin, int start, int end);
|
cannam@52
|
83 void filter_df(d_vec_t &df);
|
cannam@52
|
84 void get_rcf(const d_vec_t &dfframe, const d_vec_t &wv, d_vec_t &rcf);
|
cannam@53
|
85 void viterbi_decode(const d_mat_t &rcfmat, const d_vec_t &wv,
|
cannam@53
|
86 d_vec_t &bp, d_vec_t &tempi);
|
cannam@52
|
87 double get_max_val(const d_vec_t &df);
|
cannam@52
|
88 int get_max_ind(const d_vec_t &df);
|
cannam@52
|
89 void normalise_vec(d_vec_t &df);
|
cannam@52
|
90 };
|
cannam@52
|
91
|
cannam@52
|
92 #endif
|