comparison BeatRootProcessor.h @ 4:c06cf6f7cb04

Bring in Peaks code from BeatRoot
author Chris Cannam
date Mon, 19 Sep 2011 15:48:26 +0100
parents a821f49c42f0
children 2150607d4726
comparison
equal deleted inserted replaced
3:a821f49c42f0 4:c06cf6f7cb04
14 */ 14 */
15 15
16 #ifndef _BEATROOT_PROCESSOR_H_ 16 #ifndef _BEATROOT_PROCESSOR_H_
17 #define _BEATROOT_PROCESSOR_H_ 17 #define _BEATROOT_PROCESSOR_H_
18 18
19 #include "Peaks.h"
20
19 #include <vector> 21 #include <vector>
20 #include <cmath> 22 #include <cmath>
21 23
22 using std::vector; 24 using std::vector;
23 25
51 53
52 /** Long term average frame energy (in frequency domain representation). */ 54 /** Long term average frame energy (in frequency domain representation). */
53 double ltAverage; 55 double ltAverage;
54 56
55 /** Spectral flux onset detection function, indexed by frame. */ 57 /** Spectral flux onset detection function, indexed by frame. */
56 vector<int> spectralFlux; 58 vector<double> spectralFlux;
57 59
58 /** A mapping function for mapping FFT bins to final frequency bins. 60 /** A mapping function for mapping FFT bins to final frequency bins.
59 * The mapping is linear (1-1) until the resolution reaches 2 points per 61 * The mapping is linear (1-1) until the resolution reaches 2 points per
60 * semitone, then logarithmic with a semitone resolution. e.g. for 62 * semitone, then logarithmic with a semitone resolution. e.g. for
61 * 44.1kHz sampling rate and fftSize of 2048 (46ms), bin spacing is 63 * 44.1kHz sampling rate and fftSize of 2048 (46ms), bin spacing is
275 // plot.fitAxes(); 277 // plot.fitAxes();
276 278
277 // double[] slope = new double[energy.length]; 279 // double[] slope = new double[energy.length];
278 // double hop = hopTime / energyOversampleFactor; 280 // double hop = hopTime / energyOversampleFactor;
279 // Peaks.getSlope(energy, hop, 15, slope); 281 // Peaks.getSlope(energy, hop, 15, slope);
280 // LinkedList<Integer> peaks = Peaks.findPeaks(slope, (int)lrint(0.06 / hop), 10); 282 // vector<Integer> peaks = Peaks.findPeaks(slope, (int)lrint(0.06 / hop), 10);
281 283
282 double hop = hopTime; 284 double hop = hopTime;
283 Peaks.normalise(spectralFlux); 285 Peaks::normalise(spectralFlux);
284 LinkedList<Integer> peaks = Peaks.findPeaks(spectralFlux, (int)lrint(0.06 / hop), 0.35, 0.84, true); 286 vector<int> peaks = Peaks::findPeaks(spectralFlux, (int)lrint(0.06 / hop), 0.35, 0.84, true);
285 onsets = new double[peaks.size()]; 287 onsets = new double[peaks.size()];
286 double[] y2 = new double[onsets.length]; 288 double[] y2 = new double[onsets.length];
287 Iterator<Integer> it = peaks.iterator(); 289 vector<int>::iterator it = peaks.begin();
288 onsetList = new EventList(); 290 onsetList = new EventList();
289 double minSalience = Peaks.min(spectralFlux); 291 double minSalience = Peaks.min(spectralFlux);
290 for (int i = 0; i < onsets.length; i++) { 292 for (int i = 0; i < onsets.length; i++) {
291 int index = it.next(); 293 int index = *it;
294 ++it;
292 onsets[i] = index * hop; 295 onsets[i] = index * hop;
293 y2[i] = spectralFlux[index]; 296 y2[i] = spectralFlux[index];
294 Event e = BeatTrackDisplay.newBeat(onsets[i], 0); 297 Event e = BeatTrackDisplay.newBeat(onsets[i], 0);
295 // if (debug) 298 // if (debug)
296 // System.err.printf("Onset: %8.3f %8.3f %8.3f\n", 299 // System.err.printf("Onset: %8.3f %8.3f %8.3f\n",