Mercurial > hg > beatroot-vamp
diff BeatRootProcessor.h @ 15:887c629502a9
refactor: pull method implementations into .cpp files
author | Chris Cannam |
---|---|
date | Wed, 12 Oct 2011 10:55:52 +0100 |
parents | f1252b6a7cf5 |
children | 6afcb5edd7ab |
line wrap: on
line diff
--- a/BeatRootProcessor.h Fri Oct 07 14:07:42 2011 +0100 +++ b/BeatRootProcessor.h Wed Oct 12 10:55:52 2011 +0100 @@ -108,57 +108,11 @@ * then computing the spectral flux then (optionally) normalising * and calculating onsets. */ - void 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() + void processFrame(const float *const *inputBuffers); /** Tracks beats once all frames have been processed by processFrame */ - EventList beatTrack() { - - for (int i = 0; i < spectralFlux.size(); ++i) { - if ((i % 8) == 0) std::cerr << "\n"; - std::cerr << spectralFlux[i] << " "; - } - - 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 < 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(onsetList); - - } // processFile() + EventList beatTrack(); protected: /** Allocates memory for arrays, based on parameter settings */