changeset 280:daf89d31f45c

* Restore Scale setting which had mistakenly disappeared from spectrum * Some tweaks to spectrum peaks * Make spectrum default to 4096/75%... or is that overdoing it? * Show harmonic cursor even during playback if in measure mode and mouse in relevant pane * Avoid crash when trying to measure a non-layer * Various adjustments to some icons to make them look better in white-on-black schemes
author Chris Cannam
date Fri, 13 Jul 2007 15:54:17 +0000
parents 7802b0e2b0ff
children 9c447d664275
files data/fft/FFTDataServer.cpp data/model/FFTModel.cpp data/model/FFTModel.h
diffstat 3 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/data/fft/FFTDataServer.cpp	Fri Jul 13 10:51:15 2007 +0000
+++ b/data/fft/FFTDataServer.cpp	Fri Jul 13 15:54:17 2007 +0000
@@ -874,8 +874,10 @@
     if (!cache) return 0;
 
     if (!cache->haveSetColumnAt(col)) {
+#ifdef DEBUG_FFT_SERVER
         std::cerr << "FFTDataServer::getMagnitudeAt: calling fillColumn(" 
                   << x << ")" << std::endl;
+#endif
         fillColumn(x);
     }
     return cache->getMagnitudeAt(col, y);
--- a/data/model/FFTModel.cpp	Fri Jul 13 10:51:15 2007 +0000
+++ b/data/model/FFTModel.cpp	Fri Jul 13 15:54:17 2007 +0000
@@ -184,7 +184,8 @@
 
     std::deque<float> window;
     std::vector<size_t> inrange;
-    size_t medianWinSize = getPeakPickWindowSize(type, sampleRate, ymin);
+    float dist = 0.5;
+    size_t medianWinSize = getPeakPickWindowSize(type, sampleRate, ymin, dist);
     size_t halfWin = medianWinSize/2;
 
     size_t binmin;
@@ -201,7 +202,8 @@
 
         window.push_back(value);
 
-        medianWinSize = getPeakPickWindowSize(type, sampleRate, bin);
+        // so-called median will actually be the dist*100'th percentile
+        medianWinSize = getPeakPickWindowSize(type, sampleRate, bin, dist);
         halfWin = medianWinSize/2;
 
         while (window.size() > medianWinSize) window.pop_front();
@@ -213,7 +215,7 @@
 
         std::deque<float> sorted(window);
         std::sort(sorted.begin(), sorted.end());
-        float median = sorted[sorted.size()/2];
+        float median = sorted[int(sorted.size() * dist)];
 
         if (value > median) {
             inrange.push_back(bin);
@@ -241,16 +243,23 @@
 }
 
 size_t
-FFTModel::getPeakPickWindowSize(PeakPickType type, size_t sampleRate, size_t bin) const
+FFTModel::getPeakPickWindowSize(PeakPickType type, size_t sampleRate,
+                                size_t bin, float &percentile) const
 {
+    percentile = 0.5;
     if (type == MajorPeaks) return 10;
     if (bin == 0) return 3;
+
     size_t fftSize = m_server->getFFTSize() >> m_yshift;
     float binfreq = (sampleRate * bin) / fftSize;
     float hifreq = Pitch::getFrequencyForPitch(73, 0, binfreq);
+
     int hibin = lrintf((hifreq * fftSize) / sampleRate);
     int medianWinSize = hibin - bin;
     if (medianWinSize < 3) medianWinSize = 3;
+
+    percentile = 0.5 + (binfreq / sampleRate);
+
     return medianWinSize;
 }
 
--- a/data/model/FFTModel.h	Fri Jul 13 10:51:15 2007 +0000
+++ b/data/model/FFTModel.h	Fri Jul 13 15:54:17 2007 +0000
@@ -172,7 +172,8 @@
     int m_xshift;
     int m_yshift;
 
-    size_t getPeakPickWindowSize(PeakPickType type, size_t sampleRate, size_t bin) const;
+    size_t getPeakPickWindowSize(PeakPickType type, size_t sampleRate,
+                                 size_t bin, float &percentile) const;
 };
 
 #endif