diff data/model/FFTModel.cpp @ 1100:5cbf71022679 simple-fft-model

Smooth signal flow through from file to fft model
author Chris Cannam
date Mon, 15 Jun 2015 16:02:58 +0100
parents 4d9816ba0ebe
children e994747fb9dd
line wrap: on
line diff
--- a/data/model/FFTModel.cpp	Mon Jun 15 15:35:57 2015 +0100
+++ b/data/model/FFTModel.cpp	Mon Jun 15 16:02:58 2015 +0100
@@ -225,23 +225,24 @@
 //         << "): saved range is (" << m_savedData.range.first
 //         << "," << m_savedData.range.second << ")" << endl;
 
-    if (m_savedData.range == range) return m_savedData.data;
+    if (m_savedData.range == range) {
+        return m_savedData.data;
+    }
 
     if (range.first < m_savedData.range.second &&
         range.first >= m_savedData.range.first &&
         range.second > m_savedData.range.second) {
 
-        //!!! Need FFTModel overlap tests to exercise this
-        
-        sv_frame_t off = range.first - m_savedData.range.first;
-                
-        vector<float> acc(m_savedData.data.begin() + off, m_savedData.data.end());
+        sv_frame_t discard = range.first - m_savedData.range.first;
+
+        vector<float> acc(m_savedData.data.begin() + discard,
+                          m_savedData.data.end());
 
         vector<float> rest =
             getSourceDataUncached({ m_savedData.range.second, range.second });
+
+        acc.insert(acc.end(), rest.begin(), rest.end());
         
-        acc.insert(acc.end(), rest.begin(), rest.end());
-
         m_savedData = { range, acc };
         return acc;
 
@@ -279,6 +280,7 @@
 	if (channels > 1) {
             int n = int(data.size());
             float factor = 1.f / float(channels);
+            // use mean instead of sum for fft model input
 	    for (int i = 0; i < n; ++i) {
 		data[i] *= factor;
 	    }
@@ -298,7 +300,7 @@
     }
     
     auto samples = getSourceSamples(n);
-    m_windower.cut(&samples[0]);
+    m_windower.cut(samples.data());
     auto col = m_fft.process(samples);
 
     SavedColumn sc { n, col };