diff layer/SpectrumLayer.cpp @ 1394:4a36f6130056 spectrogramparam

Various tweaks & fixes to log-scale handling in spectrum. We can't easily preserve the nice behaviour where peaks stay in place as fft size changes, without potentially losing a bit of low-frequency information
author Chris Cannam
date Wed, 14 Nov 2018 14:17:06 +0000
parents 900bed394f5a
children 2e316a724336
line wrap: on
line diff
--- a/layer/SpectrumLayer.cpp	Wed Nov 14 14:16:06 2018 +0000
+++ b/layer/SpectrumLayer.cpp	Wed Nov 14 14:17:06 2018 +0000
@@ -389,9 +389,22 @@
 SpectrumLayer::getFrequencyForX(const LayerGeometryProvider *v, double x) const
 {
     if (!m_sliceableModel) return 0;
-    double freq = getScalePointForX(v, x,
-                                    getFrequencyForBin(m_minbin),
-                                    getFrequencyForBin(m_maxbin));
+
+    double fmin = getFrequencyForBin(m_minbin);
+
+    if (m_binScale == LogBins && m_minbin == 0) {
+        // Avoid too much space going to the first bin, but do so in a
+        // way that usually avoids us shifting left/right as the
+        // window size or oversampling ratio change - i.e. base this
+        // on frequency rather than bin number unless we have a lot of
+        // very low-resolution content
+        fmin = getFrequencyForBin(0.8);
+        if (fmin > 6.0) fmin = 6.0;
+    }
+    
+    double fmax = getFrequencyForBin(m_maxbin);
+
+    double freq = getScalePointForX(v, x, fmin, fmax);
     return freq;
 }
 
@@ -418,9 +431,17 @@
 SpectrumLayer::getXForFrequency(const LayerGeometryProvider *v, double freq) const
 {
     if (!m_sliceableModel) return 0;
-    double x = getXForScalePoint(v, freq,
-                                 getFrequencyForBin(m_minbin),
-                                 getFrequencyForBin(m_maxbin));
+
+    double fmin = getFrequencyForBin(m_minbin);
+    if (m_binScale == LogBins && m_minbin == 0) {
+        // See comment in getFrequencyForX above
+        fmin = getFrequencyForBin(0.8);
+        if (fmin > 6.0) fmin = 6.0;
+    }
+    
+    double fmax = getFrequencyForBin(m_maxbin);
+
+    double x = getXForScalePoint(v, freq, fmin, fmax);
     return x;
 }