To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / BeatRootProcessor.cpp
History | View | Annotate | Download (2.46 KB)
| 1 | 2:7d4e6b1ff3d1 | Chris | /* -*- 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 "BeatRootProcessor.h" |
||
| 17 | |||
| 18 | bool
|
||
| 19 | BeatRootProcessor::silent = true;
|
||
| 20 | |||
| 21 | 15:887c629502a9 | Chris | 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 | 36:937432fc2898 | Chris | EventList BeatRootProcessor::beatTrack(EventList *unfilledReturn) {
|
| 35 | 15:887c629502a9 | Chris | |
| 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 | 22:6afcb5edd7ab | Chris | for (int i = 0; i < (int)onsets.size(); i++) { |
| 53 | 15:887c629502a9 | Chris | 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 | 36:937432fc2898 | Chris | return BeatTracker::beatTrack(agentParameters, onsetList, unfilledReturn);
|
| 71 | 15:887c629502a9 | Chris | |
| 72 | } // processFile()
|