annotate dsp/tempotracking/TempoTrackV2.h @ 386:6acd63422d44

Make the calculation functions available with default parameters again as well (for Segmentino)
author Chris Cannam <c.cannam@qmul.ac.uk>
date Tue, 03 Dec 2013 10:02:46 +0000
parents 8252d055bd00
children 701233f8ed41
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@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
c@277 16
c@277 17 #ifndef TEMPOTRACKV2_H
c@277 18 #define TEMPOTRACKV2_H
c@277 19
c@277 20 #include <vector>
luis@327 21 using namespace std;
c@277 22
c@279 23 //!!! Question: how far is this actually sample rate dependent? I
c@279 24 // think it does produce plausible results for e.g. 48000 as well as
c@279 25 // 44100, but surely the fixed window sizes and comb filtering will
c@279 26 // make it prefer double or half time when run at e.g. 96000?
c@279 27
luis@327 28 class TempoTrackV2
c@277 29 {
c@277 30 public:
c@279 31 /**
c@279 32 * Construct a tempo tracker that will operate on beat detection
c@279 33 * function data calculated from audio at the given sample rate
c@279 34 * with the given frame increment.
c@279 35 *
c@279 36 * Currently the sample rate and increment are used only for the
c@279 37 * conversion from beat frame location to bpm in the tempo array.
c@279 38 */
c@279 39 TempoTrackV2(float sampleRate, size_t dfIncrement);
c@277 40 ~TempoTrackV2();
c@277 41
luis@327 42 // Returned beat periods are given in df increment units; inputtempo and tempi in bpm
c@277 43 void calculateBeatPeriod(const vector<double> &df,
c@278 44 vector<double> &beatPeriod,
c@386 45 vector<double> &tempi) {
c@386 46 calculateBeatPeriod(df, beatPeriod, tempi, 120.0, false);
c@386 47 }
c@386 48
c@386 49 // Returned beat periods are given in df increment units; inputtempo and tempi in bpm
c@386 50 // MEPD 28/11/12 Expose inputtempo and constraintempo parameters
c@386 51 // Note, if inputtempo = 120 and constraintempo = false, then functionality is as it was before
c@386 52 void calculateBeatPeriod(const vector<double> &df,
c@386 53 vector<double> &beatPeriod,
c@386 54 vector<double> &tempi,
c@386 55 double inputtempo, bool constraintempo);
c@386 56
c@386 57 // Returned beat positions are given in df increment units
c@386 58 void calculateBeats(const vector<double> &df,
c@386 59 const vector<double> &beatPeriod,
c@386 60 vector<double> &beats) {
c@386 61 calculateBeats(df, beatPeriod, beats, 0.9, 4.0);
c@386 62 }
c@277 63
c@279 64 // Returned beat positions are given in df increment units
luis@327 65 // MEPD 28/11/12 Expose alpha and tightness parameters
c@386 66 // Note, if alpha = 0.9 and tightness = 4, then functionality is as it was before
c@277 67 void calculateBeats(const vector<double> &df,
c@277 68 const vector<double> &beatPeriod,
c@386 69 vector<double> &beats,
c@386 70 double alpha, double tightness);
c@277 71
c@277 72 private:
c@277 73 typedef vector<int> i_vec_t;
c@277 74 typedef vector<vector<int> > i_mat_t;
c@277 75 typedef vector<double> d_vec_t;
c@277 76 typedef vector<vector<double> > d_mat_t;
c@277 77
c@279 78 float m_rate;
c@279 79 size_t m_increment;
c@279 80
c@277 81 void adapt_thresh(d_vec_t &df);
c@277 82 double mean_array(const d_vec_t &dfin, int start, int end);
c@277 83 void filter_df(d_vec_t &df);
c@277 84 void get_rcf(const d_vec_t &dfframe, const d_vec_t &wv, d_vec_t &rcf);
c@278 85 void viterbi_decode(const d_mat_t &rcfmat, const d_vec_t &wv,
c@278 86 d_vec_t &bp, d_vec_t &tempi);
c@277 87 double get_max_val(const d_vec_t &df);
c@277 88 int get_max_ind(const d_vec_t &df);
c@277 89 void normalise_vec(d_vec_t &df);
c@277 90 };
c@277 91
c@277 92 #endif