~mr-unwell2006/mixxx/features_key_preferences

« back to all changes in this revision

Viewing changes to mixxx/vamp-plugins/dsp/TempoTrackV2.h

  • Committer: Keith Salisbury
  • Date: 2012-06-24 07:28:29 UTC
  • mfrom: (3002.1.281 trunk)
  • Revision ID: keithsalisbury@gmail.com-20120624072829-y14q80b9dnac35c2
merged with trunk

Show diffs side-by-side

added added

removed removed

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