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