comparison BeatRootProcessor.h @ 9:4f6626f9ffac

Many fixes. This now compiles and passes the plugin tester, but I don't expect it produces any results yet.
author Chris Cannam
date Fri, 30 Sep 2011 15:39:17 +0100
parents f04f87b5e643
children 1c1e98cd1b2e
comparison
equal deleted inserted replaced
8:f04f87b5e643 9:4f6626f9ffac
25 25
26 using std::vector; 26 using std::vector;
27 27
28 class BeatRootProcessor 28 class BeatRootProcessor
29 { 29 {
30 public:
31 int getFFTSize() const { return fftSize; }
32 int getHopSize() const { return hopSize; }
33
30 protected: 34 protected:
31 /** Sample rate of audio */ 35 /** Sample rate of audio */
32 float sampleRate; 36 float sampleRate;
33 37
34 /** Spacing of audio frames (determines the amount of overlap or 38 /** Spacing of audio frames (determines the amount of overlap or
89 * detection function(s). */ 93 * detection function(s). */
90 vector<double> onsets; 94 vector<double> onsets;
91 95
92 /** The estimated onset times and their saliences. */ 96 /** The estimated onset times and their saliences. */
93 EventList onsetList; 97 EventList onsetList;
94
95 /** Total number of audio frames if known, or -1 for live or compressed input. */
96 int totalFrames;
97
98 /** Flag for enabling or disabling debugging output */
99 static bool debug;
100 98
101 /** Flag for suppressing all standard output messages except results. */ 99 /** Flag for suppressing all standard output messages except results. */
102 static bool silent; 100 static bool silent;
103 101
104 /** RMS frame energy below this value results in the frame being 102 /** RMS frame energy below this value results in the frame being
133 frameRMS = 0; 131 frameRMS = 0;
134 ltAverage = 0; 132 ltAverage = 0;
135 frameCount = 0; 133 frameCount = 0;
136 hopSize = 0; 134 hopSize = 0;
137 fftSize = 0; 135 fftSize = 0;
138 hopTime = 0.010; // DEFAULT, overridden with -h 136 hopTime = 0.010;
139 fftTime = 0.04644; // DEFAULT, overridden with -f 137 fftTime = 0.04644;
140 totalFrames = -1; //!!! not needed? 138 hopSize = lrint(sampleRate * hopTime);
139 fftSize = lrint(pow(2, lrint( log(fftTime * sampleRate) / log(2))));
141 } // constructor 140 } // constructor
141
142 void reset() {
143 init();
144 }
142 145
143 protected: 146 protected:
144 /** Allocates memory for arrays, based on parameter settings */ 147 /** Allocates memory for arrays, based on parameter settings */
145 void init() { 148 void init() {
146 hopSize = lrint(sampleRate * hopTime);
147 fftSize = lrint(pow(2, lrint( log(fftTime * sampleRate) / log(2))));
148 makeFreqMap(fftSize, sampleRate); 149 makeFreqMap(fftSize, sampleRate);
149 prevFrame.clear(); 150 prevFrame.clear();
150 for (int i = 0; i < freqMapSize; i++) prevFrame.push_back(0); 151 for (int i = 0; i < freqMapSize; i++) prevFrame.push_back(0);
151 frameCount = 0; 152 frameCount = 0;
152 frameRMS = 0; 153 frameRMS = 0;
166 double binWidth = sampleRate / fftSize; 167 double binWidth = sampleRate / fftSize;
167 int crossoverBin = (int)(2 / (pow(2, 1/12.0) - 1)); 168 int crossoverBin = (int)(2 / (pow(2, 1/12.0) - 1));
168 int crossoverMidi = (int)lrint(log(crossoverBin*binWidth/440)/ 169 int crossoverMidi = (int)lrint(log(crossoverBin*binWidth/440)/
169 log(2) * 12 + 69); 170 log(2) * 12 + 69);
170 int i = 0; 171 int i = 0;
171 while (i <= crossoverBin) 172 while (i <= crossoverBin && i <= fftSize/2)
172 freqMap[i++] = i; 173 freqMap[i++] = i;
173 while (i <= fftSize/2) { 174 while (i <= fftSize/2) {
174 double midi = log(i*binWidth/440) / log(2) * 12 + 69; 175 double midi = log(i*binWidth/440) / log(2) * 12 + 69;
175 if (midi > 127) 176 if (midi > 127)
176 midi = 127; 177 midi = 127;
177 freqMap[i++] = crossoverBin + (int)lrint(midi) - crossoverMidi; 178 freqMap[i++] = crossoverBin + (int)lrint(midi) - crossoverMidi;
178 } 179 }
179 freqMapSize = freqMap[i-1] + 1; 180 freqMapSize = freqMap[i-1] + 1;
180 } // makeFreqMap() 181 } // makeFreqMap()
181 182
182 /** Processes a frame of audio data by first computing the STFT with a 183 /** Processes a frame of frequency-domain audio data by mapping
183 * Hamming window, then mapping the frequency bins into a part-linear 184 * the frequency bins into a part-linear part-logarithmic array,
184 * part-logarithmic array, then computing the spectral flux 185 * then computing the spectral flux then (optionally) normalising
185 * then (optionally) normalising and calculating onsets. 186 * and calculating onsets.
186 */ 187 */
187 void processFrame(const float *const *inputBuffers) { 188 void processFrame(const float *const *inputBuffers) {
188 newFrame.clear(); 189 newFrame.clear();
189 for (int i = 0; i < freqMapSize; i++) { 190 for (int i = 0; i < freqMapSize; i++) {
190 newFrame.push_back(0); 191 newFrame.push_back(0);