various fixes to MidiRegionView selection handling, key handling, drawing of ghost...
[ardour2.git] / libs / qm-dsp / dsp / tempotracking / TempoTrackV2.h
bloba08919fb1e177f8ac57d102841f391761e758df1
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
3 /*
4 QM DSP Library
6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2008-2009 Matthew Davies and QMUL.
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.
17 #ifndef TEMPOTRACKV2_H
18 #define TEMPOTRACKV2_H
20 #include <vector>
22 using std::vector;
24 //!!! Question: how far is this actually sample rate dependent? I
25 // think it does produce plausible results for e.g. 48000 as well as
26 // 44100, but surely the fixed window sizes and comb filtering will
27 // make it prefer double or half time when run at e.g. 96000?
29 class TempoTrackV2
31 public:
32 /**
33 * Construct a tempo tracker that will operate on beat detection
34 * function data calculated from audio at the given sample rate
35 * with the given frame increment.
37 * Currently the sample rate and increment are used only for the
38 * conversion from beat frame location to bpm in the tempo array.
40 TempoTrackV2(float sampleRate, size_t dfIncrement);
41 ~TempoTrackV2();
43 // Returned beat periods are given in df increment units; tempi in bpm
44 void calculateBeatPeriod(const vector<double> &df,
45 vector<double> &beatPeriod,
46 vector<double> &tempi);
48 // Returned beat positions are given in df increment units
49 void calculateBeats(const vector<double> &df,
50 const vector<double> &beatPeriod,
51 vector<double> &beats);
53 private:
54 typedef vector<int> i_vec_t;
55 typedef vector<vector<int> > i_mat_t;
56 typedef vector<double> d_vec_t;
57 typedef vector<vector<double> > d_mat_t;
59 float m_rate;
60 size_t m_increment;
62 void adapt_thresh(d_vec_t &df);
63 double mean_array(const d_vec_t &dfin, int start, int end);
64 void filter_df(d_vec_t &df);
65 void get_rcf(const d_vec_t &dfframe, const d_vec_t &wv, d_vec_t &rcf);
66 void viterbi_decode(const d_mat_t &rcfmat, const d_vec_t &wv,
67 d_vec_t &bp, d_vec_t &tempi);
68 double get_max_val(const d_vec_t &df);
69 int get_max_ind(const d_vec_t &df);
70 void normalise_vec(d_vec_t &df);
73 #endif