To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / BeatTracker.cpp
History | View | Annotate | Download (1.82 KB)
| 1 | 17:47e1917c88fc | Chris | /* -*- 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 | 23:633ec097fa56 | Chris | EventList BeatTracker::beatTrack(AgentParameters params, |
| 19 | 36:937432fc2898 | Chris | EventList events, EventList beats, |
| 20 | EventList *unfilledReturn) |
||
| 21 | 17:47e1917c88fc | Chris | {
|
| 22 | AgentList agents; |
||
| 23 | int count = 0; |
||
| 24 | double beatTime = -1; |
||
| 25 | if (!beats.empty()) {
|
||
| 26 | count = beats.size() - 1;
|
||
| 27 | EventList::iterator itr = beats.end(); |
||
| 28 | --itr; |
||
| 29 | beatTime = itr->time; |
||
| 30 | } |
||
| 31 | if (count > 0) { // tempo given by mean of initial beats |
||
| 32 | double ioi = (beatTime - beats.begin()->time) / count;
|
||
| 33 | 23:633ec097fa56 | Chris | agents.push_back(new Agent(params, ioi));
|
| 34 | 17:47e1917c88fc | Chris | } else // tempo not given; use tempo induction |
| 35 | 23:633ec097fa56 | Chris | agents = Induction::beatInduction(params, events); |
| 36 | 17:47e1917c88fc | Chris | if (!beats.empty())
|
| 37 | for (AgentList::iterator itr = agents.begin(); itr != agents.end();
|
||
| 38 | ++itr) {
|
||
| 39 | (*itr)->beatTime = beatTime; |
||
| 40 | (*itr)->beatCount = count; |
||
| 41 | (*itr)->events = beats; |
||
| 42 | } |
||
| 43 | 23:633ec097fa56 | Chris | agents.beatTrack(events, params, -1);
|
| 44 | 17:47e1917c88fc | Chris | Agent *best = agents.bestAgent(); |
| 45 | EventList results; |
||
| 46 | if (best) {
|
||
| 47 | 36:937432fc2898 | Chris | if (unfilledReturn) *unfilledReturn = best->events;
|
| 48 | 17:47e1917c88fc | Chris | best->fillBeats(beatTime); |
| 49 | results = best->events; |
||
| 50 | } |
||
| 51 | for (AgentList::iterator ai = agents.begin(); ai != agents.end(); ++ai) {
|
||
| 52 | delete *ai;
|
||
| 53 | } |
||
| 54 | return results;
|
||
| 55 | } // beatTrack()/1
|
||
| 56 |