annotate dsp/tempotracking/TempoTrackV2.h @ 279:c8908cdc8c32

* First cut at Matthew's downbeat estimator -- untested so far
author Chris Cannam <c.cannam@qmul.ac.uk>
date Tue, 10 Feb 2009 12:52:43 +0000
parents 833ca65b0820
children e5907ae6de17
rev   line source
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@277 8 All rights reserved.
c@277 9 */
c@277 10
c@277 11
c@277 12 #ifndef TEMPOTRACKV2_H
c@277 13 #define TEMPOTRACKV2_H
c@277 14
c@277 15 #include <vector>
c@277 16
c@277 17 using std::vector;
c@277 18
c@279 19 //!!! Question: how far is this actually sample rate dependent? I
c@279 20 // think it does produce plausible results for e.g. 48000 as well as
c@279 21 // 44100, but surely the fixed window sizes and comb filtering will
c@279 22 // make it prefer double or half time when run at e.g. 96000?
c@279 23
c@277 24 class TempoTrackV2
c@277 25 {
c@277 26 public:
c@279 27 /**
c@279 28 * Construct a tempo tracker that will operate on beat detection
c@279 29 * function data calculated from audio at the given sample rate
c@279 30 * with the given frame increment.
c@279 31 *
c@279 32 * Currently the sample rate and increment are used only for the
c@279 33 * conversion from beat frame location to bpm in the tempo array.
c@279 34 */
c@279 35 TempoTrackV2(float sampleRate, size_t dfIncrement);
c@277 36 ~TempoTrackV2();
c@277 37
c@279 38 // Returned beat periods are given in df increment units; tempi in bpm
c@277 39 void calculateBeatPeriod(const vector<double> &df,
c@278 40 vector<double> &beatPeriod,
c@278 41 vector<double> &tempi);
c@277 42
c@279 43 // Returned beat positions are given in df increment units
c@277 44 void calculateBeats(const vector<double> &df,
c@277 45 const vector<double> &beatPeriod,
c@277 46 vector<double> &beats);
c@277 47
c@277 48 private:
c@277 49 typedef vector<int> i_vec_t;
c@277 50 typedef vector<vector<int> > i_mat_t;
c@277 51 typedef vector<double> d_vec_t;
c@277 52 typedef vector<vector<double> > d_mat_t;
c@277 53
c@279 54 float m_rate;
c@279 55 size_t m_increment;
c@279 56
c@277 57 void adapt_thresh(d_vec_t &df);
c@277 58 double mean_array(const d_vec_t &dfin, int start, int end);
c@277 59 void filter_df(d_vec_t &df);
c@277 60 void get_rcf(const d_vec_t &dfframe, const d_vec_t &wv, d_vec_t &rcf);
c@278 61 void viterbi_decode(const d_mat_t &rcfmat, const d_vec_t &wv,
c@278 62 d_vec_t &bp, d_vec_t &tempi);
c@277 63 double get_max_val(const d_vec_t &df);
c@277 64 int get_max_ind(const d_vec_t &df);
c@277 65 void normalise_vec(d_vec_t &df);
c@277 66 };
c@277 67
c@277 68 #endif