To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / BeatTracker.cpp @ 23:633ec097fa56

History | View | Annotate | Download (1.7 KB)

1
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2

    
3
/*
4
  Vamp feature extraction plugin for the BeatRoot beat tracker.
5

6
  Centre for Digital Music, Queen Mary, University of London.
7
  This file copyright 2011 Simon Dixon, Chris Cannam 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
#include "BeatTracker.h"
17

    
18
EventList BeatTracker::beatTrack(AgentParameters params,
19
                                 EventList events, EventList beats)
20
{
21
    AgentList agents;
22
    int count = 0;
23
    double beatTime = -1;
24
    if (!beats.empty()) {
25
        count = beats.size() - 1;
26
        EventList::iterator itr = beats.end();
27
        --itr;
28
        beatTime = itr->time;
29
    }
30
    if (count > 0) { // tempo given by mean of initial beats
31
        double ioi = (beatTime - beats.begin()->time) / count;
32
        agents.push_back(new Agent(params, ioi));
33
    } else // tempo not given; use tempo induction
34
        agents = Induction::beatInduction(params, events);
35
    if (!beats.empty())
36
        for (AgentList::iterator itr = agents.begin(); itr != agents.end();
37
             ++itr) {
38
            (*itr)->beatTime = beatTime;
39
            (*itr)->beatCount = count;
40
            (*itr)->events = beats;
41
        }
42
    agents.beatTrack(events, params, -1);
43
    Agent *best = agents.bestAgent();
44
    EventList results;
45
    if (best) {
46
        best->fillBeats(beatTime);
47
        results = best->events;
48
    }
49
    for (AgentList::iterator ai = agents.begin(); ai != agents.end(); ++ai) {
50
        delete *ai;
51
    }
52
    return results;
53
} // beatTrack()/1
54
        
55