annotate BeatTracker.cpp @ 17:47e1917c88fc

Add file previously forgotten in commit... doh. And .cat file.
author Chris Cannam
date Fri, 14 Oct 2011 09:59:53 +0100
parents
children 633ec097fa56
rev   line source
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@17 18 EventList BeatTracker::beatTrack(EventList events, EventList beats)
Chris@17 19 {
Chris@17 20 AgentList agents;
Chris@17 21 int count = 0;
Chris@17 22 double beatTime = -1;
Chris@17 23 if (!beats.empty()) {
Chris@17 24 count = beats.size() - 1;
Chris@17 25 EventList::iterator itr = beats.end();
Chris@17 26 --itr;
Chris@17 27 beatTime = itr->time;
Chris@17 28 }
Chris@17 29 if (count > 0) { // tempo given by mean of initial beats
Chris@17 30 double ioi = (beatTime - beats.begin()->time) / count;
Chris@17 31 agents.push_back(new Agent(ioi));
Chris@17 32 } else // tempo not given; use tempo induction
Chris@17 33 agents = Induction::beatInduction(events);
Chris@17 34 if (!beats.empty())
Chris@17 35 for (AgentList::iterator itr = agents.begin(); itr != agents.end();
Chris@17 36 ++itr) {
Chris@17 37 (*itr)->beatTime = beatTime;
Chris@17 38 (*itr)->beatCount = count;
Chris@17 39 (*itr)->events = beats;
Chris@17 40 }
Chris@17 41 agents.beatTrack(events, -1);
Chris@17 42 Agent *best = agents.bestAgent();
Chris@17 43 EventList results;
Chris@17 44 if (best) {
Chris@17 45 best->fillBeats(beatTime);
Chris@17 46 results = best->events;
Chris@17 47 }
Chris@17 48 for (AgentList::iterator ai = agents.begin(); ai != agents.end(); ++ai) {
Chris@17 49 delete *ai;
Chris@17 50 }
Chris@17 51 return results;
Chris@17 52 } // beatTrack()/1
Chris@17 53
Chris@17 54