Chris@17
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@17
|
2
|
Chris@17
|
3 /*
|
Chris@17
|
4 Vamp feature extraction plugin for the BeatRoot beat tracker.
|
Chris@17
|
5
|
Chris@17
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@17
|
7 This file copyright 2011 Simon Dixon, Chris Cannam and QMUL.
|
Chris@17
|
8
|
Chris@17
|
9 This program is free software; you can redistribute it and/or
|
Chris@17
|
10 modify it under the terms of the GNU General Public License as
|
Chris@17
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@17
|
12 License, or (at your option) any later version. See the file
|
Chris@17
|
13 COPYING included with this distribution for more information.
|
Chris@17
|
14 */
|
Chris@17
|
15
|
Chris@17
|
16 #include "BeatTracker.h"
|
Chris@17
|
17
|
Chris@23
|
18 EventList BeatTracker::beatTrack(AgentParameters params,
|
Chris@36
|
19 EventList events, EventList beats,
|
Chris@36
|
20 EventList *unfilledReturn)
|
Chris@17
|
21 {
|
Chris@17
|
22 AgentList agents;
|
Chris@17
|
23 int count = 0;
|
Chris@17
|
24 double beatTime = -1;
|
Chris@17
|
25 if (!beats.empty()) {
|
Chris@17
|
26 count = beats.size() - 1;
|
Chris@17
|
27 EventList::iterator itr = beats.end();
|
Chris@17
|
28 --itr;
|
Chris@17
|
29 beatTime = itr->time;
|
Chris@17
|
30 }
|
Chris@17
|
31 if (count > 0) { // tempo given by mean of initial beats
|
Chris@17
|
32 double ioi = (beatTime - beats.begin()->time) / count;
|
Chris@23
|
33 agents.push_back(new Agent(params, ioi));
|
Chris@17
|
34 } else // tempo not given; use tempo induction
|
Chris@23
|
35 agents = Induction::beatInduction(params, events);
|
Chris@17
|
36 if (!beats.empty())
|
Chris@17
|
37 for (AgentList::iterator itr = agents.begin(); itr != agents.end();
|
Chris@17
|
38 ++itr) {
|
Chris@17
|
39 (*itr)->beatTime = beatTime;
|
Chris@17
|
40 (*itr)->beatCount = count;
|
Chris@17
|
41 (*itr)->events = beats;
|
Chris@17
|
42 }
|
Chris@23
|
43 agents.beatTrack(events, params, -1);
|
Chris@17
|
44 Agent *best = agents.bestAgent();
|
Chris@17
|
45 EventList results;
|
Chris@17
|
46 if (best) {
|
Chris@36
|
47 if (unfilledReturn) *unfilledReturn = best->events;
|
Chris@17
|
48 best->fillBeats(beatTime);
|
Chris@17
|
49 results = best->events;
|
Chris@17
|
50 }
|
Chris@17
|
51 for (AgentList::iterator ai = agents.begin(); ai != agents.end(); ++ai) {
|
Chris@17
|
52 delete *ai;
|
Chris@17
|
53 }
|
Chris@17
|
54 return results;
|
Chris@17
|
55 } // beatTrack()/1
|
Chris@17
|
56
|
Chris@17
|
57
|