changeset 1387:bca9870301b7 spectrogramparam

Small speedups
author Chris Cannam
date Mon, 12 Nov 2018 14:48:42 +0000
parents fc3d89f88690
children 81dda64a7edc
files layer/SliceLayer.cpp layer/SpectrumLayer.cpp
diffstat 2 files changed, 22 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/layer/SliceLayer.cpp	Mon Nov 12 11:34:34 2018 +0000
+++ b/layer/SliceLayer.cpp	Mon Nov 12 14:48:42 2018 +0000
@@ -402,11 +402,19 @@
         }
     }
 
+    int mh = m_sliceableModel->getHeight();
+    
     if (m_plotStyle == PlotBlocks) {
         // Must use actual zero-width pen, too slow otherwise
         paint.setPen(QPen(getBaseQColor(), 0));
     } else {
-        paint.setPen(PaintAssistant::scalePen(getBaseQColor()));
+        // Similarly, if there are very many bins here, let's drop to
+        // a precise 1-pixel-width pen
+        if (mh > 10000) {
+            paint.setPen(QPen(getBaseQColor(), 1));
+        } else {
+            paint.setPen(PaintAssistant::scalePen(getBaseQColor()));
+        }
     }
 
     int xorigin = getVerticalScaleWidth(v, true, paint) + 1;
@@ -423,7 +431,6 @@
 
     QPainterPath path;
 
-    int mh = m_sliceableModel->getHeight();
     int bin0 = 0;
 
     if (m_maxbin > m_minbin) {
--- 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();