comparison ConstrainedHarmonicPeak.cpp @ 4:3bf29717cc01

m_blockSize -> m_fftSize (they happen to be the same in this case, but that's what we use it as)
author Chris Cannam
date Fri, 07 Mar 2014 16:20:59 +0000
parents ab0b04e1c56b
children e9b629578488
comparison
equal deleted inserted replaced
2:ee3cf00cfa4c 4:3bf29717cc01
8 using std::endl; 8 using std::endl;
9 using std::vector; 9 using std::vector;
10 10
11 ConstrainedHarmonicPeak::ConstrainedHarmonicPeak(float inputSampleRate) : 11 ConstrainedHarmonicPeak::ConstrainedHarmonicPeak(float inputSampleRate) :
12 Plugin(inputSampleRate), 12 Plugin(inputSampleRate),
13 m_blockSize(0), 13 m_fftSize(0),
14 m_minFreq(0), 14 m_minFreq(0),
15 m_maxFreq(inputSampleRate/2), 15 m_maxFreq(inputSampleRate/2),
16 m_harmonics(5) 16 m_harmonics(5)
17 { 17 {
18 } 18 }
197 << " out of acceptable range " << getMinChannelCount() 197 << " out of acceptable range " << getMinChannelCount()
198 << " -> " << getMaxChannelCount() << endl; 198 << " -> " << getMaxChannelCount() << endl;
199 return false; 199 return false;
200 } 200 }
201 201
202 m_blockSize = blockSize; 202 m_fftSize = blockSize;
203 203
204 return true; 204 return true;
205 } 205 }
206 206
207 void 207 void
241 ConstrainedHarmonicPeak::FeatureSet 241 ConstrainedHarmonicPeak::FeatureSet
242 ConstrainedHarmonicPeak::process(const float *const *inputBuffers, Vamp::RealTime timestamp) 242 ConstrainedHarmonicPeak::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
243 { 243 {
244 FeatureSet fs; 244 FeatureSet fs;
245 245
246 int hs = m_blockSize/2; 246 int hs = m_fftSize/2;
247 247
248 double *mags = new double[hs+1]; 248 double *mags = new double[hs+1];
249 for (int i = 0; i <= hs; ++i) { 249 for (int i = 0; i <= hs; ++i) {
250 mags[i] = sqrtf(inputBuffers[0][i*2] * inputBuffers[0][i*2] + 250 mags[i] = sqrt(inputBuffers[0][i*2] * inputBuffers[0][i*2] +
251 inputBuffers[0][i*2+1] * inputBuffers[0][i*2+1]); 251 inputBuffers[0][i*2+1] * inputBuffers[0][i*2+1]);
252 } 252 }
253 253
254 // bin freq is bin * samplerate / fftsize 254 // bin freq is bin * samplerate / fftsize
255 255
256 int minbin = int(floor((m_minFreq * m_blockSize) / m_inputSampleRate)); 256 int minbin = int(floor((m_minFreq * m_fftSize) / m_inputSampleRate));
257 int maxbin = int(ceil((m_maxFreq * m_blockSize) / m_inputSampleRate)); 257 int maxbin = int(ceil((m_maxFreq * m_fftSize) / m_inputSampleRate));
258 if (minbin > hs) minbin = hs; 258 if (minbin > hs) minbin = hs;
259 if (maxbin > hs) maxbin = hs; 259 if (maxbin > hs) maxbin = hs;
260 if (maxbin <= minbin) return fs; 260 if (maxbin <= minbin) return fs;
261 261
262 double *hps = new double[maxbin - minbin + 1]; 262 double *hps = new double[maxbin - minbin + 1];
293 } 293 }
294 294
295 double interpolated = findInterpolatedPeak(hps, maxidx, maxbin - minbin + 1); 295 double interpolated = findInterpolatedPeak(hps, maxidx, maxbin - minbin + 1);
296 interpolated = interpolated + minbin; 296 interpolated = interpolated + minbin;
297 297
298 double freq = interpolated * m_inputSampleRate / m_blockSize; 298 double freq = interpolated * m_inputSampleRate / m_fftSize;
299 299
300 Feature f; 300 Feature f;
301 f.values.push_back(freq); 301 f.values.push_back(freq);
302 fs[0].push_back(f); 302 fs[0].push_back(f);
303 303