changeset 551:408e56d30f58

* Re-enable peak frequencies display in spectrogram
author Chris Cannam
date Thu, 05 Feb 2009 17:33:21 +0000
parents 107d3f3705c9
children bbe503e368a9
files data/model/Dense3DModelPeakCache.cpp data/model/FFTModel.cpp data/model/FFTModel.h
diffstat 3 files changed, 31 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/data/model/Dense3DModelPeakCache.cpp	Thu Feb 05 14:17:11 2009 +0000
+++ b/data/model/Dense3DModelPeakCache.cpp	Thu Feb 05 17:33:21 2009 +0000
@@ -15,6 +15,8 @@
 
 #include "Dense3DModelPeakCache.h"
 
+#include "base/Profiler.h"
+
 Dense3DModelPeakCache::Dense3DModelPeakCache(DenseThreeDimensionalModel *source,
 					     size_t columnsPerPeak) :
     m_source(source),
@@ -57,6 +59,7 @@
 Dense3DModelPeakCache::Column
 Dense3DModelPeakCache::getColumn(size_t column) const
 {
+    Profiler profiler("Dense3DModelPeakCache::getColumn");
     if (!m_source) return Column();
     if (!haveColumn(column)) fillColumn(column);
     return m_cache->getColumn(column);
@@ -97,7 +100,13 @@
 void
 Dense3DModelPeakCache::fillColumn(size_t column) const
 {
-    if (column >= m_coverage.size()) m_coverage.resize(column + 1);
+    Profiler profiler("Dense3DModelPeakCache::fillColumn");
+
+    if (column >= m_coverage.size()) {
+        // see note in sourceModelChanged
+        if (m_coverage.size() > 0) m_coverage.reset(m_coverage.size()-1);
+        m_coverage.resize(column + 1);
+    }
 
     Column peak;
     for (int i = 0; i < m_resolution; ++i) {
--- a/data/model/FFTModel.cpp	Thu Feb 05 14:17:11 2009 +0000
+++ b/data/model/FFTModel.cpp	Thu Feb 05 17:33:21 2009 +0000
@@ -241,6 +241,8 @@
 FFTModel::PeakLocationSet
 FFTModel::getPeaks(PeakPickType type, size_t x, size_t ymin, size_t ymax)
 {
+    Profiler profiler("FFTModel::getPeaks");
+
     FFTModel::PeakLocationSet peaks;
     if (!isOK()) return peaks;
 
@@ -248,27 +250,28 @@
         ymax = getHeight() - 1;
     }
 
-    Column values;
-
     if (type == AllPeaks) {
-        for (size_t y = ymin; y <= ymax; ++y) {
-            values.push_back(getMagnitudeAt(x, y));
-        }
-        size_t i = 0;
+        int minbin = ymin;
+        if (minbin > 0) minbin = minbin - 1;
+        int maxbin = ymax;
+        if (maxbin < getHeight() - 1) maxbin = maxbin + 1;
+        const int n = maxbin - minbin + 1;
+        float values[n];
+        getMagnitudesAt(x, values, minbin, maxbin - minbin + 1);
         for (size_t bin = ymin; bin <= ymax; ++bin) {
-            if ((i == 0 || values[i] > values[i-1]) &&
-                (i == values.size()-1 || values[i] >= values[i+1])) {
+            if (bin == minbin || bin == maxbin) continue;
+            if (values[bin - minbin] > values[bin - minbin - 1] &&
+                values[bin - minbin] > values[bin - minbin + 1]) {
                 peaks.insert(bin);
             }
-            ++i;
         }
         return peaks;
     }
 
-    values = getColumn(x);
+    Column values = getColumn(x);
 
     float mean = 0.f;
-    for (int i =0; i < values.size(); ++i) mean += values[i];
+    for (int i = 0; i < values.size(); ++i) mean += values[i];
     if (values.size() >0) mean /= values.size();
 
     // For peak picking we use a moving median window, picking the
@@ -382,6 +385,8 @@
 FFTModel::getPeakFrequencies(PeakPickType type, size_t x,
                              size_t ymin, size_t ymax)
 {
+    Profiler profiler("FFTModel::getPeakFrequencies");
+
     PeakSet peaks;
     if (!isOK()) return peaks;
     PeakLocationSet locations = getPeaks(type, x, ymin, ymax);
--- a/data/model/FFTModel.h	Thu Feb 05 14:17:11 2009 +0000
+++ b/data/model/FFTModel.h	Thu Feb 05 17:33:21 2009 +0000
@@ -85,13 +85,13 @@
         return m_server->isColumnReady(x << m_xshift);
     }
 
-    inline float getMagnitudesAt(size_t x, float *values, size_t minbin = 0, size_t count = 0) {
+    inline bool getMagnitudesAt(size_t x, float *values, size_t minbin = 0, size_t count = 0) {
         return m_server->getMagnitudesAt(x << m_xshift, values, minbin << m_yshift, count, getYRatio());
     }
-    inline float getNormalizedMagnitudesAt(size_t x, float *values, size_t minbin = 0, size_t count = 0) {
+    inline bool getNormalizedMagnitudesAt(size_t x, float *values, size_t minbin = 0, size_t count = 0) {
         return m_server->getNormalizedMagnitudesAt(x << m_xshift, values, minbin << m_yshift, count, getYRatio());
     }
-    inline float getPhasesAt(size_t x, float *values, size_t minbin = 0, size_t count = 0) {
+    inline bool getPhasesAt(size_t x, float *values, size_t minbin = 0, size_t count = 0) {
         return m_server->getPhasesAt(x << m_xshift, values, minbin << m_yshift, count, getYRatio());
     }
 
@@ -157,8 +157,8 @@
         MajorPitchAdaptivePeaks  /// Bigger window for higher frequencies
     };
 
-    typedef std::set<size_t> PeakLocationSet;
-    typedef std::map<size_t, float> PeakSet;
+    typedef std::set<size_t> PeakLocationSet; // bin
+    typedef std::map<size_t, float> PeakSet; // bin -> freq
 
     /**
      * Return locations of peak bins in the range [ymin,ymax].  If