qm-dsp
1.8
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 QM DSP Library 00005 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2008-2009 Matthew Davies and QMUL. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 00017 #ifndef TEMPOTRACKV2_H 00018 #define TEMPOTRACKV2_H 00019 00020 #include <vector> 00021 using namespace std; 00022 00024 // think it does produce plausible results for e.g. 48000 as well as 00025 // 44100, but surely the fixed window sizes and comb filtering will 00026 // make it prefer double or half time when run at e.g. 96000? 00027 00028 class TempoTrackV2 00029 { 00030 public: 00039 TempoTrackV2(float sampleRate, size_t dfIncrement); 00040 ~TempoTrackV2(); 00041 00042 // Returned beat periods are given in df increment units; inputtempo and tempi in bpm 00043 void calculateBeatPeriod(const vector<double> &df, 00044 vector<double> &beatPeriod, 00045 vector<double> &tempi) { 00046 calculateBeatPeriod(df, beatPeriod, tempi, 120.0, false); 00047 } 00048 00049 // Returned beat periods are given in df increment units; inputtempo and tempi in bpm 00050 // MEPD 28/11/12 Expose inputtempo and constraintempo parameters 00051 // Note, if inputtempo = 120 and constraintempo = false, then functionality is as it was before 00052 void calculateBeatPeriod(const vector<double> &df, 00053 vector<double> &beatPeriod, 00054 vector<double> &tempi, 00055 double inputtempo, bool constraintempo); 00056 00057 // Returned beat positions are given in df increment units 00058 void calculateBeats(const vector<double> &df, 00059 const vector<double> &beatPeriod, 00060 vector<double> &beats) { 00061 calculateBeats(df, beatPeriod, beats, 0.9, 4.0); 00062 } 00063 00064 // Returned beat positions are given in df increment units 00065 // MEPD 28/11/12 Expose alpha and tightness parameters 00066 // Note, if alpha = 0.9 and tightness = 4, then functionality is as it was before 00067 void calculateBeats(const vector<double> &df, 00068 const vector<double> &beatPeriod, 00069 vector<double> &beats, 00070 double alpha, double tightness); 00071 00072 private: 00073 typedef vector<int> i_vec_t; 00074 typedef vector<vector<int> > i_mat_t; 00075 typedef vector<double> d_vec_t; 00076 typedef vector<vector<double> > d_mat_t; 00077 00078 float m_rate; 00079 size_t m_increment; 00080 00081 void adapt_thresh(d_vec_t &df); 00082 double mean_array(const d_vec_t &dfin, int start, int end); 00083 void filter_df(d_vec_t &df); 00084 void get_rcf(const d_vec_t &dfframe, const d_vec_t &wv, d_vec_t &rcf); 00085 void viterbi_decode(const d_mat_t &rcfmat, const d_vec_t &wv, 00086 d_vec_t &bp, d_vec_t &tempi); 00087 double get_max_val(const d_vec_t &df); 00088 int get_max_ind(const d_vec_t &df); 00089 void normalise_vec(d_vec_t &df); 00090 }; 00091 00092 #endif