diff data/model/FFTModel.cpp @ 1206:659372323b45 tony-2.0-integration

Merge latest SV 3.0 branch code
author Chris Cannam
date Fri, 19 Aug 2016 15:58:57 +0100
parents 6f7a440b6218
children 6b847a59d908
line wrap: on
line diff
--- a/data/model/FFTModel.cpp	Tue Oct 20 12:54:06 2015 +0100
+++ b/data/model/FFTModel.cpp	Fri Aug 19 15:58:57 2016 +0100
@@ -98,9 +98,21 @@
 {
     auto cplx = getFFTColumn(x);
     Column col;
-    col.reserve(int(cplx.size()));
+    col.reserve(cplx.size());
     for (auto c: cplx) col.push_back(abs(c));
-    return col;
+    return move(col);
+}
+
+FFTModel::Column
+FFTModel::getPhases(int x) const
+{
+    auto cplx = getFFTColumn(x);
+    Column col;
+    col.reserve(cplx.size());
+    for (auto c: cplx) {
+        col.push_back(arg(c));
+    }
+    return move(col);
 }
 
 float
@@ -116,7 +128,8 @@
 {
     Column col(getColumn(x));
     float max = 0.f;
-    for (int i = 0; i < col.size(); ++i) {
+    int n = int(col.size());
+    for (int i = 0; i < n; ++i) {
         if (col[i] > max) max = col[i];
     }
     return max;
@@ -138,13 +151,6 @@
 }
 
 bool
-FFTModel::isColumnAvailable(int) const
-{
-    //!!!
-    return true;
-}
-
-bool
 FFTModel::getMagnitudesAt(int x, float *values, int minbin, int count) const
 {
     if (count == 0) count = getHeight();
@@ -155,23 +161,6 @@
     return true;
 }
 
-float
-FFTModel::getNormalizedMagnitudesAt(int x, float *values, int minbin, int count) const
-{
-    if (!getMagnitudesAt(x, values, minbin, count)) return false;
-    if (count == 0) count = getHeight();
-    float max = 0.f;
-    for (int i = 0; i < count; ++i) {
-        if (values[i] > max) max = values[i];
-    }
-    if (max > 0.f) {
-        for (int i = 0; i < count; ++i) {
-            values[i] /= max;
-        }
-    }
-    return max;
-}
-
 bool
 FFTModel::getPhasesAt(int x, float *values, int minbin, int count) const
 {
@@ -313,7 +302,7 @@
     }
     m_cached.push_back(sc);
 
-    return col;
+    return move(col);
 }
 
 bool
@@ -354,7 +343,7 @@
 }
 
 FFTModel::PeakLocationSet
-FFTModel::getPeaks(PeakPickType type, int x, int ymin, int ymax)
+FFTModel::getPeaks(PeakPickType type, int x, int ymin, int ymax) const
 {
     Profiler profiler("FFTModel::getPeaks");
 
@@ -388,10 +377,11 @@
     }
 
     Column values = getColumn(x);
+    int nv = int(values.size());
 
     float mean = 0.f;
-    for (int i = 0; i < values.size(); ++i) mean += values[i];
-    if (values.size() > 0) mean = mean / float(values.size());
+    for (int i = 0; i < nv; ++i) mean += values[i];
+    if (nv > 0) mean = mean / float(values.size());
     
     // For peak picking we use a moving median window, picking the
     // highest value within each continuous region of values that
@@ -412,8 +402,8 @@
     else binmin = 0;
 
     int binmax;
-    if (ymax + halfWin < values.size()) binmax = ymax + halfWin;
-    else binmax = values.size()-1;
+    if (ymax + halfWin < nv) binmax = ymax + halfWin;
+    else binmax = nv - 1;
 
     int prevcentre = 0;
 
@@ -434,8 +424,8 @@
         int actualSize = int(window.size());
 
         if (type == MajorPitchAdaptivePeaks) {
-            if (ymax + halfWin < values.size()) binmax = ymax + halfWin;
-            else binmax = values.size()-1;
+            if (ymax + halfWin < nv) binmax = ymax + halfWin;
+            else binmax = nv - 1;
         }
 
         deque<float> sorted(window);
@@ -455,7 +445,7 @@
                 inrange.push_back(centrebin);
             }
 
-            if (centre <= median || centrebin+1 == values.size()) {
+            if (centre <= median || centrebin+1 == nv) {
                 if (!inrange.empty()) {
                     int peakbin = 0;
                     float peakval = 0.f;
@@ -501,7 +491,7 @@
 
 FFTModel::PeakSet
 FFTModel::getPeakFrequencies(PeakPickType type, int x,
-                             int ymin, int ymax)
+                             int ymin, int ymax) const
 {
     Profiler profiler("FFTModel::getPeakFrequencies");