Mercurial > hg > beatroot-vamp
comparison 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 |
comparison
equal
deleted
inserted
replaced
14:f1252b6a7cf5 | 15:887c629502a9 |
---|---|
106 /** Processes a frame of frequency-domain audio data by mapping | 106 /** Processes a frame of frequency-domain audio data by mapping |
107 * the frequency bins into a part-linear part-logarithmic array, | 107 * the frequency bins into a part-linear part-logarithmic array, |
108 * then computing the spectral flux then (optionally) normalising | 108 * then computing the spectral flux then (optionally) normalising |
109 * and calculating onsets. | 109 * and calculating onsets. |
110 */ | 110 */ |
111 void processFrame(const float *const *inputBuffers) { | 111 void processFrame(const float *const *inputBuffers); |
112 double flux = 0; | |
113 for (int i = 0; i <= fftSize/2; i++) { | |
114 double mag = sqrt(inputBuffers[0][i*2] * inputBuffers[0][i*2] + | |
115 inputBuffers[0][i*2+1] * inputBuffers[0][i*2+1]); | |
116 if (mag > prevFrame[i]) flux += mag - prevFrame[i]; | |
117 prevFrame[i] = mag; | |
118 } | |
119 | |
120 spectralFlux.push_back(flux); | |
121 | |
122 } // processFrame() | |
123 | 112 |
124 /** Tracks beats once all frames have been processed by processFrame | 113 /** Tracks beats once all frames have been processed by processFrame |
125 */ | 114 */ |
126 EventList beatTrack() { | 115 EventList beatTrack(); |
127 | |
128 for (int i = 0; i < spectralFlux.size(); ++i) { | |
129 if ((i % 8) == 0) std::cerr << "\n"; | |
130 std::cerr << spectralFlux[i] << " "; | |
131 } | |
132 | |
133 double hop = hopTime; | |
134 Peaks::normalise(spectralFlux); | |
135 vector<int> peaks = Peaks::findPeaks(spectralFlux, (int)lrint(0.06 / hop), 0.35, 0.84, true); | |
136 onsets.clear(); | |
137 onsets.resize(peaks.size(), 0); | |
138 vector<int>::iterator it = peaks.begin(); | |
139 onsetList.clear(); | |
140 double minSalience = Peaks::min(spectralFlux); | |
141 for (int i = 0; i < onsets.size(); i++) { | |
142 int index = *it; | |
143 ++it; | |
144 onsets[i] = index * hop; | |
145 Event e = BeatTracker::newBeat(onsets[i], 0); | |
146 // if (debug) | |
147 // System.err.printf("Onset: %8.3f %8.3f %8.3f\n", | |
148 // onsets[i], energy[index], slope[index]); | |
149 // e.salience = slope[index]; // or combination of energy + slope?? | |
150 // Note that salience must be non-negative or the beat tracking system fails! | |
151 e.salience = spectralFlux[index] - minSalience; | |
152 onsetList.push_back(e); | |
153 } | |
154 | |
155 #ifdef DEBUG_BEATROOT | |
156 std::cerr << "Onsets: " << onsetList.size() << std::endl; | |
157 #endif | |
158 | |
159 return BeatTracker::beatTrack(onsetList); | |
160 | |
161 } // processFile() | |
162 | 116 |
163 protected: | 117 protected: |
164 /** Allocates memory for arrays, based on parameter settings */ | 118 /** Allocates memory for arrays, based on parameter settings */ |
165 void init() { | 119 void init() { |
166 makeFreqMap(fftSize, sampleRate); | 120 makeFreqMap(fftSize, sampleRate); |