comparison BeatRootProcessor.cpp @ 15:887c629502a9

refactor: pull method implementations into .cpp files
author Chris Cannam
date Wed, 12 Oct 2011 10:55:52 +0100
parents 1c1e98cd1b2e
children 6afcb5edd7ab
comparison
equal deleted inserted replaced
14:f1252b6a7cf5 15:887c629502a9
16 #include "BeatRootProcessor.h" 16 #include "BeatRootProcessor.h"
17 17
18 bool 18 bool
19 BeatRootProcessor::silent = true; 19 BeatRootProcessor::silent = true;
20 20
21 void BeatRootProcessor::processFrame(const float *const *inputBuffers) {
22 double flux = 0;
23 for (int i = 0; i <= fftSize/2; i++) {
24 double mag = sqrt(inputBuffers[0][i*2] * inputBuffers[0][i*2] +
25 inputBuffers[0][i*2+1] * inputBuffers[0][i*2+1]);
26 if (mag > prevFrame[i]) flux += mag - prevFrame[i];
27 prevFrame[i] = mag;
28 }
29
30 spectralFlux.push_back(flux);
31
32 } // processFrame()
33
34 EventList BeatRootProcessor::beatTrack() {
35
36 #ifdef DEBUG_BEATROOT
37 std::cerr << "Spectral flux:" << std::endl;
38 for (int i = 0; i < spectralFlux.size(); ++i) {
39 if ((i % 8) == 0) std::cerr << "\n";
40 std::cerr << spectralFlux[i] << " ";
41 }
42 #endif
43
44 double hop = hopTime;
45 Peaks::normalise(spectralFlux);
46 vector<int> peaks = Peaks::findPeaks(spectralFlux, (int)lrint(0.06 / hop), 0.35, 0.84, true);
47 onsets.clear();
48 onsets.resize(peaks.size(), 0);
49 vector<int>::iterator it = peaks.begin();
50 onsetList.clear();
51 double minSalience = Peaks::min(spectralFlux);
52 for (int i = 0; i < onsets.size(); i++) {
53 int index = *it;
54 ++it;
55 onsets[i] = index * hop;
56 Event e = BeatTracker::newBeat(onsets[i], 0);
57 // if (debug)
58 // System.err.printf("Onset: %8.3f %8.3f %8.3f\n",
59 // onsets[i], energy[index], slope[index]);
60 // e.salience = slope[index]; // or combination of energy + slope??
61 // Note that salience must be non-negative or the beat tracking system fails!
62 e.salience = spectralFlux[index] - minSalience;
63 onsetList.push_back(e);
64 }
65
66 #ifdef DEBUG_BEATROOT
67 std::cerr << "Onsets: " << onsetList.size() << std::endl;
68 #endif
69
70 return BeatTracker::beatTrack(onsetList);
71
72 } // processFile()
73