comparison Agent.cpp @ 6:02d388f98c23

Introduce a number of new classes derived from the Java
author Chris Cannam
date Tue, 27 Sep 2011 18:37:01 +0100
parents
children f04f87b5e643
comparison
equal deleted inserted replaced
5:2150607d4726 6:02d388f98c23
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 "Agent.h"
17 #include "BeatTracker.h"
18
19 double Agent::POST_MARGIN_FACTOR = 0.3;
20 double Agent::PRE_MARGIN_FACTOR = 0.15;
21 const double Agent::INNER_MARGIN = 0.040;
22 double Agent::MAX_CHANGE = 0.2;
23 double Agent::CONF_FACTOR = 0.5;
24 const double Agent::DEFAULT_CORRECTION_FACTOR = 50.0;
25 const double Agent::DEFAULT_EXPIRY_TIME = 10.0;
26
27 int Agent::idCounter = 0;
28
29 double Agent::innerMargin = 0.0;
30 double Agent::outerMargin = 0.0;
31 double Agent::correctionFactor = 0.0;
32 double Agent::expiryTime = 0.0;
33 double Agent::decayFactor = 0.0;
34
35 bool Agent::considerAsBeat(Event e, const AgentList &a) {
36 double err;
37 if (beatTime < 0) { // first event
38 accept(e, 0, 1);
39 return true;
40 } else { // subsequent events
41 if (e.keyDown - events.l.getLast().keyDown > expiryTime) {
42 phaseScore = -1.0; // flag agent to be deleted
43 return false;
44 }
45 double beats = Math.round((e.keyDown - beatTime) / beatInterval);
46 err = e.keyDown - beatTime - beats * beatInterval;
47 if ((beats > 0) && (-preMargin <= err) && (err <= postMargin)) {
48 if (Math.abs(err) > innerMargin) // Create new agent that skips this
49 a.add(new Agent(this)); // event (avoids large phase jump)
50 accept(e, err, (int)beats);
51 return true;
52 }
53 }
54 return false;
55 } // considerAsBeat()
56
57
58 void fillBeats(double start) {
59 double prevBeat = 0, nextBeat, currentInterval, beats;
60 EventList::iterator list = events.begin();
61 if (list != events.end()) {
62 ++list;
63 prevBeat = list->time;
64 --list;
65 }
66 for ( ; list != events.end(); ++list) {
67 ++list;
68 nextBeat = list->time;
69 --list;
70 beats = nearbyint((nextBeat - prevBeat) / beatInterval - 0.01); //prefer slow
71 currentInterval = (nextBeat - prevBeat) / beats;
72 for ( ; (nextBeat > start) && (beats > 1.5); beats--) {
73 prevBeat += currentInterval;
74 //!!! need to insert this event after current itr
75 list.add(BeatTracker::newBeat(prevBeat, 0)); // more than once OK??
76 }
77 prevBeat = nextBeat;
78 }
79 } // fillBeats()