c@277: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ c@277: c@277: /* c@277: QM DSP Library c@277: c@277: Centre for Digital Music, Queen Mary, University of London. c@277: This file copyright 2008-2009 Matthew Davies and QMUL. c@277: All rights reserved. c@277: */ c@277: c@277: c@277: #ifndef TEMPOTRACKV2_H c@277: #define TEMPOTRACKV2_H c@277: c@277: #include c@277: c@277: using std::vector; c@277: c@279: //!!! Question: how far is this actually sample rate dependent? I c@279: // think it does produce plausible results for e.g. 48000 as well as c@279: // 44100, but surely the fixed window sizes and comb filtering will c@279: // make it prefer double or half time when run at e.g. 96000? c@279: c@277: class TempoTrackV2 c@277: { c@277: public: c@279: /** c@279: * Construct a tempo tracker that will operate on beat detection c@279: * function data calculated from audio at the given sample rate c@279: * with the given frame increment. c@279: * c@279: * Currently the sample rate and increment are used only for the c@279: * conversion from beat frame location to bpm in the tempo array. c@279: */ c@279: TempoTrackV2(float sampleRate, size_t dfIncrement); c@277: ~TempoTrackV2(); c@277: c@279: // Returned beat periods are given in df increment units; tempi in bpm c@277: void calculateBeatPeriod(const vector &df, c@278: vector &beatPeriod, c@278: vector &tempi); c@277: c@279: // Returned beat positions are given in df increment units c@277: void calculateBeats(const vector &df, c@277: const vector &beatPeriod, c@277: vector &beats); c@277: c@277: private: c@277: typedef vector i_vec_t; c@277: typedef vector > i_mat_t; c@277: typedef vector d_vec_t; c@277: typedef vector > d_mat_t; c@277: c@279: float m_rate; c@279: size_t m_increment; c@279: c@277: void adapt_thresh(d_vec_t &df); c@277: double mean_array(const d_vec_t &dfin, int start, int end); c@277: void filter_df(d_vec_t &df); c@277: void get_rcf(const d_vec_t &dfframe, const d_vec_t &wv, d_vec_t &rcf); c@278: void viterbi_decode(const d_mat_t &rcfmat, const d_vec_t &wv, c@278: d_vec_t &bp, d_vec_t &tempi); c@277: double get_max_val(const d_vec_t &df); c@277: int get_max_ind(const d_vec_t &df); c@277: void normalise_vec(d_vec_t &df); c@277: }; c@277: c@277: #endif