-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeatRootProcessor.cpp
More file actions
73 lines (58 loc) · 2.46 KB
/
BeatRootProcessor.cpp
File metadata and controls
73 lines (58 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Vamp feature extraction plugin for the BeatRoot beat tracker.
Centre for Digital Music, Queen Mary, University of London.
This file copyright 2011 Simon Dixon, Chris Cannam and QMUL.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version. See the file
COPYING included with this distribution for more information.
*/
#include "BeatRootProcessor.h"
bool
BeatRootProcessor::silent = true;
void BeatRootProcessor::processFrame(const float *const *inputBuffers) {
double flux = 0;
for (int i = 0; i <= fftSize/2; i++) {
double mag = sqrt(inputBuffers[0][i*2] * inputBuffers[0][i*2] +
inputBuffers[0][i*2+1] * inputBuffers[0][i*2+1]);
if (mag > prevFrame[i]) flux += mag - prevFrame[i];
prevFrame[i] = mag;
}
spectralFlux.push_back(flux);
} // processFrame()
EventList BeatRootProcessor::beatTrack(EventList *unfilledReturn) {
#ifdef DEBUG_BEATROOT
std::cerr << "Spectral flux:" << std::endl;
for (int i = 0; i < spectralFlux.size(); ++i) {
if ((i % 8) == 0) std::cerr << "\n";
std::cerr << spectralFlux[i] << " ";
}
#endif
double hop = hopTime;
Peaks::normalise(spectralFlux);
vector<int> peaks = Peaks::findPeaks(spectralFlux, (int)lrint(0.06 / hop), 0.35, 0.84, true);
onsets.clear();
onsets.resize(peaks.size(), 0);
vector<int>::iterator it = peaks.begin();
onsetList.clear();
double minSalience = Peaks::min(spectralFlux);
for (int i = 0; i < (int)onsets.size(); i++) {
int index = *it;
++it;
onsets[i] = index * hop;
Event e = BeatTracker::newBeat(onsets[i], 0);
// if (debug)
// System.err.printf("Onset: %8.3f %8.3f %8.3f\n",
// onsets[i], energy[index], slope[index]);
// e.salience = slope[index]; // or combination of energy + slope??
// Note that salience must be non-negative or the beat tracking system fails!
e.salience = spectralFlux[index] - minSalience;
onsetList.push_back(e);
}
#ifdef DEBUG_BEATROOT
std::cerr << "Onsets: " << onsetList.size() << std::endl;
#endif
return BeatTracker::beatTrack(agentParameters, onsetList, unfilledReturn);
} // processFile()