Mercurial > hg > svgui
diff layer/SpectrumLayer.cpp @ 1387:bca9870301b7 spectrogramparam
Small speedups
author | Chris Cannam |
---|---|
date | Mon, 12 Nov 2018 14:48:42 +0000 |
parents | fc3d89f88690 |
children | 1eb560b363e7 |
line wrap: on
line diff
--- a/layer/SpectrumLayer.cpp Mon Nov 12 11:34:34 2018 +0000 +++ b/layer/SpectrumLayer.cpp Mon Nov 12 14:48:42 2018 +0000 @@ -705,7 +705,8 @@ int peakminbin = 0; int peakmaxbin = fft->getHeight() - 1; double peakmaxfreq = Pitch::getFrequencyForPitch(128); - peakmaxbin = int(((peakmaxfreq * fft->getHeight() * 2) / fft->getSampleRate())); + peakmaxbin = int(((peakmaxfreq * fft->getHeight() * 2) / + fft->getSampleRate())); FFTModel::PeakSet peaks = fft->getPeakFrequencies (FFTModel::MajorPitchAdaptivePeaks, col, peakminbin, peakmaxbin); @@ -714,9 +715,17 @@ getBiasCurve(curve); int cs = int(curve.size()); + int px = -1; + for (FFTModel::PeakSet::iterator i = peaks.begin(); i != peaks.end(); ++i) { + double freq = i->second; + int x = int(lrint(getXForFrequency(v, freq))); + if (x == px) { + continue; + } + int bin = i->first; // cerr << "bin = " << bin << ", thresh = " << thresh << ", value = " << fft->getMagnitudeAt(col, bin) << endl; @@ -725,15 +734,14 @@ if (value < thresh) continue; if (bin < cs) value *= curve[bin]; - double freq = i->second; - int x = int(lrint(getXForFrequency(v, freq))); - double norm = 0.f; // don't need return value, need norm: (void)getYForValue(v, value, norm); - paint.setPen(mapper.map(norm)); + paint.setPen(QPen(mapper.map(norm), 1)); paint.drawLine(x, 0, x, v->getPaintHeight() - scaleHeight - 1); + + px = x; } paint.restore();