changeset 1399:ba1f0234efa7

Fixes to spectrum axis calculations, + default to starting at bin 1
author Chris Cannam
date Wed, 14 Nov 2018 15:47:21 +0000
parents f228bee4981c
children decb7741d036
files layer/SliceLayer.cpp layer/SpectrogramLayer.cpp layer/SpectrumLayer.cpp
diffstat 3 files changed, 19 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/layer/SliceLayer.cpp	Wed Nov 14 15:14:21 2018 +0000
+++ b/layer/SliceLayer.cpp	Wed Nov 14 15:47:21 2018 +0000
@@ -209,9 +209,13 @@
     int w = pw - origin;
     if (w < 1) w = 1;
 
+    if (pmax <= pmin) {
+        pmax = pmin + 1.0;
+    }
+    
     if (p < pmin) p = pmin;
     if (p > pmax) p = pmax;
-    
+
     if (m_binScale == LinearBins) {
         x = (w * (p - pmin)) / (pmax - pmin);
     } else {
@@ -246,16 +250,14 @@
         double pmaxlog = log10(pmax + reqdshift + origin);
         double plog = log10(p + reqdshift + origin);
         x = (w * (plog - pminlog)) / (pmaxlog - pminlog);
-
-/*        
+        /*
         cerr << "getXForScalePoint(" << p << "): pmin = " << pmin
              << ", pmax = " << pmax << ", w = " << w
              << ", reqdshift = " << reqdshift
              << ", pminlog = " << pminlog << ", pmaxlog = " << pmaxlog
              << ", plog = " << plog 
              << " -> x = " << x << endl;
-*/
-
+        */
         if (m_binScale == InvertedLogBins) {
             // still stoopid
             x = w - x;
@@ -288,6 +290,10 @@
 
     double eps = 1e-10;
 
+    if (pmax <= pmin) {
+        pmax = pmin + 1.0;
+    }
+
     if (m_binScale == LinearBins) {
         p = pmin + eps + (x * (pmax - pmin)) / w;
     } else {
--- a/layer/SpectrogramLayer.cpp	Wed Nov 14 15:14:21 2018 +0000
+++ b/layer/SpectrogramLayer.cpp	Wed Nov 14 15:47:21 2018 +0000
@@ -698,7 +698,6 @@
         return;
     }
     if (name == "Spectrogram Y Smoothing") {
-        setWindowSize(m_windowSize);
         invalidateRenderers();
         invalidateMagnitudes();
         emit layerParametersChanged();
@@ -783,21 +782,6 @@
 SpectrogramLayer::getOversampling() const
 {
     return m_oversampling;
-    /*!!!
-    if (m_binDisplay != BinDisplay::AllBins) {
-        return 1;
-    }
-
-    Preferences::SpectrogramSmoothing smoothing = 
-        Preferences::getInstance()->getSpectrogramSmoothing();
-    
-    if (smoothing == Preferences::NoSpectrogramSmoothing ||
-        smoothing == Preferences::SpectrogramInterpolated) {
-        return 1;
-    }
-
-    return 4;
-    */
 }
 
 void
@@ -1556,8 +1540,7 @@
         Preferences::SpectrogramSmoothing smoothing = 
             Preferences::getInstance()->getSpectrogramSmoothing();
         params.interpolate = 
-            (smoothing == Preferences::SpectrogramInterpolated ||
-             smoothing == Preferences::SpectrogramZeroPaddedAndInterpolated);
+            (smoothing != Preferences::NoSpectrogramSmoothing);
 
         m_renderers[viewId] = new Colour3DPlotRenderer(sources, params);
 
--- a/layer/SpectrumLayer.cpp	Wed Nov 14 15:14:21 2018 +0000
+++ b/layer/SpectrumLayer.cpp	Wed Nov 14 15:47:21 2018 +0000
@@ -122,6 +122,11 @@
                                     getWindowIncrement(),
                                     fftSize);
 
+    if (m_minbin == 0 && m_maxbin == 0) {
+        m_minbin = 1;
+        m_maxbin = newFFT->getHeight();
+    }
+    
     setSliceableModel(newFFT);
 
     m_biasCurve.clear();
@@ -433,6 +438,7 @@
     if (!m_sliceableModel) return 0;
 
     double fmin = getFrequencyForBin(m_minbin);
+
     if (m_binScale == LogBins && m_minbin == 0) {
         // See comment in getFrequencyForX above
         fmin = getFrequencyForBin(0.8);
@@ -440,8 +446,8 @@
     }
     
     double fmax = getFrequencyForBin(m_maxbin);
-
     double x = getXForScalePoint(v, freq, fmin, fmax);
+    
     return x;
 }