To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / Agent.cpp @ 13:0d4048bfadbb
History | View | Annotate | Download (3.15 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 "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::correctionFactor = 0.0; |
| 31 |
double Agent::expiryTime = 0.0; |
| 32 |
double Agent::decayFactor = 0.0; |
| 33 |
|
| 34 |
bool Agent::considerAsBeat(Event e, AgentList &a) {
|
| 35 |
double err;
|
| 36 |
if (beatTime < 0) { // first event |
| 37 |
#ifdef DEBUG_BEATROOT
|
| 38 |
std::cerr << "Ag#" << idNumber << ": accepting first event trivially at " << e.time << std::endl; |
| 39 |
#endif
|
| 40 |
accept(e, 0, 1); |
| 41 |
return true; |
| 42 |
} else { // subsequent events |
| 43 |
EventList::iterator last = events.end(); |
| 44 |
--last; |
| 45 |
if (e.time - last->time > expiryTime) {
|
| 46 |
#ifdef DEBUG_BEATROOT
|
| 47 |
std::cerr << "Ag#" << idNumber << ": time " << e.time |
| 48 |
<< " too late relative to " << last->time << " (expiry " |
| 49 |
<< expiryTime << "), giving up" << std::endl;
|
| 50 |
#endif
|
| 51 |
phaseScore = -1.0; // flag agent to be deleted |
| 52 |
return false; |
| 53 |
} |
| 54 |
double beats = nearbyint((e.time - beatTime) / beatInterval);
|
| 55 |
err = e.time - beatTime - beats * beatInterval; |
| 56 |
#ifdef DEBUG_BEATROOT
|
| 57 |
std::cerr << "Ag#" << idNumber << ": time " << e.time << ", err " << err << " for beats " << beats << std::endl; |
| 58 |
#endif
|
| 59 |
if ((beats > 0) && (-preMargin <= err) && (err <= postMargin)) { |
| 60 |
if (fabs(err) > innerMargin) { // Create new agent that skips this |
| 61 |
#ifdef DEBUG_BEATROOT
|
| 62 |
std::cerr << "Ag#" << idNumber << ": creating another new agent" << std::endl; |
| 63 |
#endif
|
| 64 |
a.add(clone()); // event (avoids large phase jump)
|
| 65 |
} |
| 66 |
accept(e, err, (int)beats);
|
| 67 |
return true; |
| 68 |
} |
| 69 |
} |
| 70 |
return false; |
| 71 |
} // considerAsBeat()
|
| 72 |
|
| 73 |
|
| 74 |
void Agent::fillBeats(double start) { |
| 75 |
double prevBeat = 0, nextBeat, currentInterval, beats; |
| 76 |
EventList::iterator ei = events.begin(); |
| 77 |
if (ei != events.end()) {
|
| 78 |
EventList::iterator ni = ei; |
| 79 |
prevBeat = (++ni)->time; |
| 80 |
} |
| 81 |
for ( ; ei != events.end(); ) {
|
| 82 |
EventList::iterator ni = ei; |
| 83 |
nextBeat = (++ni)->time; |
| 84 |
beats = nearbyint((nextBeat - prevBeat) / beatInterval - 0.01); //prefer slow |
| 85 |
currentInterval = (nextBeat - prevBeat) / beats; |
| 86 |
for ( ; (nextBeat > start) && (beats > 1.5); beats--) { |
| 87 |
prevBeat += currentInterval; |
| 88 |
events.insert(ni, BeatTracker::newBeat(prevBeat, 0));
|
| 89 |
} |
| 90 |
prevBeat = nextBeat; |
| 91 |
ei = ni; |
| 92 |
} |
| 93 |
} // fillBeats()
|