comparison data/model/FFTModel.cpp @ 1154:aa588c391d1a 3.0-integration

Convert 3d model column type from QVector to std::vector; replace another user of ResizeableBitset
author Chris Cannam
date Fri, 22 Jan 2016 13:39:45 +0000
parents e994747fb9dd
children 546d4e417346
comparison
equal deleted inserted replaced
1153:ece369c5bb68 1154:aa588c391d1a
96 FFTModel::Column 96 FFTModel::Column
97 FFTModel::getColumn(int x) const 97 FFTModel::getColumn(int x) const
98 { 98 {
99 auto cplx = getFFTColumn(x); 99 auto cplx = getFFTColumn(x);
100 Column col; 100 Column col;
101 col.reserve(int(cplx.size())); 101 col.reserve(cplx.size());
102 for (auto c: cplx) col.push_back(abs(c)); 102 for (auto c: cplx) col.push_back(abs(c));
103 return col; 103 return move(col);
104 } 104 }
105 105
106 float 106 float
107 FFTModel::getMagnitudeAt(int x, int y) const 107 FFTModel::getMagnitudeAt(int x, int y) const
108 { 108 {
114 float 114 float
115 FFTModel::getMaximumMagnitudeAt(int x) const 115 FFTModel::getMaximumMagnitudeAt(int x) const
116 { 116 {
117 Column col(getColumn(x)); 117 Column col(getColumn(x));
118 float max = 0.f; 118 float max = 0.f;
119 for (int i = 0; i < col.size(); ++i) { 119 int n = int(col.size());
120 for (int i = 0; i < n; ++i) {
120 if (col[i] > max) max = col[i]; 121 if (col[i] > max) max = col[i];
121 } 122 }
122 return max; 123 return max;
123 } 124 }
124 125
311 if (m_cached.size() >= m_cacheSize) { 312 if (m_cached.size() >= m_cacheSize) {
312 m_cached.pop_front(); 313 m_cached.pop_front();
313 } 314 }
314 m_cached.push_back(sc); 315 m_cached.push_back(sc);
315 316
316 return col; 317 return move(col);
317 } 318 }
318 319
319 bool 320 bool
320 FFTModel::estimateStableFrequency(int x, int y, double &frequency) 321 FFTModel::estimateStableFrequency(int x, int y, double &frequency)
321 { 322 {
386 } 387 }
387 return peaks; 388 return peaks;
388 } 389 }
389 390
390 Column values = getColumn(x); 391 Column values = getColumn(x);
392 int nv = int(values.size());
391 393
392 float mean = 0.f; 394 float mean = 0.f;
393 for (int i = 0; i < values.size(); ++i) mean += values[i]; 395 for (int i = 0; i < nv; ++i) mean += values[i];
394 if (values.size() > 0) mean = mean / float(values.size()); 396 if (nv > 0) mean = mean / float(values.size());
395 397
396 // For peak picking we use a moving median window, picking the 398 // For peak picking we use a moving median window, picking the
397 // highest value within each continuous region of values that 399 // highest value within each continuous region of values that
398 // exceed the median. For pitch adaptivity, we adjust the window 400 // exceed the median. For pitch adaptivity, we adjust the window
399 // size to a roughly constant pitch range (about four tones). 401 // size to a roughly constant pitch range (about four tones).
410 int binmin; 412 int binmin;
411 if (ymin > halfWin) binmin = ymin - halfWin; 413 if (ymin > halfWin) binmin = ymin - halfWin;
412 else binmin = 0; 414 else binmin = 0;
413 415
414 int binmax; 416 int binmax;
415 if (ymax + halfWin < values.size()) binmax = ymax + halfWin; 417 if (ymax + halfWin < nv) binmax = ymax + halfWin;
416 else binmax = values.size()-1; 418 else binmax = nv - 1;
417 419
418 int prevcentre = 0; 420 int prevcentre = 0;
419 421
420 for (int bin = binmin; bin <= binmax; ++bin) { 422 for (int bin = binmin; bin <= binmax; ++bin) {
421 423
432 } 434 }
433 435
434 int actualSize = int(window.size()); 436 int actualSize = int(window.size());
435 437
436 if (type == MajorPitchAdaptivePeaks) { 438 if (type == MajorPitchAdaptivePeaks) {
437 if (ymax + halfWin < values.size()) binmax = ymax + halfWin; 439 if (ymax + halfWin < nv) binmax = ymax + halfWin;
438 else binmax = values.size()-1; 440 else binmax = nv - 1;
439 } 441 }
440 442
441 deque<float> sorted(window); 443 deque<float> sorted(window);
442 sort(sorted.begin(), sorted.end()); 444 sort(sorted.begin(), sorted.end());
443 float median = sorted[int(float(sorted.size()) * dist)]; 445 float median = sorted[int(float(sorted.size()) * dist)];
453 455
454 if (centre > median) { 456 if (centre > median) {
455 inrange.push_back(centrebin); 457 inrange.push_back(centrebin);
456 } 458 }
457 459
458 if (centre <= median || centrebin+1 == values.size()) { 460 if (centre <= median || centrebin+1 == nv) {
459 if (!inrange.empty()) { 461 if (!inrange.empty()) {
460 int peakbin = 0; 462 int peakbin = 0;
461 float peakval = 0.f; 463 float peakval = 0.f;
462 for (int i = 0; i < (int)inrange.size(); ++i) { 464 for (int i = 0; i < (int)inrange.size(); ++i) {
463 if (i == 0 || values[inrange[i]] > peakval) { 465 if (i == 0 || values[inrange[i]] > peakval) {