changeset 1095:b66734b5f806 simple-fft-model

Fix to fft cache
author Chris Cannam
date Sat, 13 Jun 2015 08:47:05 +0100
parents b386363ff6c8
children 4d9816ba0ebe
files data/fft/FFTapi.h data/model/FFTModel.cpp data/model/FFTModel.h
diffstat 3 files changed, 20 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/data/fft/FFTapi.h	Fri Jun 12 19:18:56 2015 +0100
+++ b/data/fft/FFTapi.h	Sat Jun 13 08:47:05 2015 +0100
@@ -73,6 +73,8 @@
         const int hs = m_size/2;
         for (int i = 0; i < hs; ++i) {
             m_input[i] = in[i + hs];
+        }
+        for (int i = 0; i < hs; ++i) {
             m_input[i + hs] = in[i];
         }
         fftf_execute(m_plan);
--- a/data/model/FFTModel.cpp	Fri Jun 12 19:18:56 2015 +0100
+++ b/data/model/FFTModel.cpp	Sat Jun 13 08:47:05 2015 +0100
@@ -235,14 +235,27 @@
         
         sv_frame_t off = range.first - m_savedData.range.first;
                 
-        vector<float> partial(m_savedData.data.begin() + off, m_savedData.data.end());
+        vector<float> acc(m_savedData.data.begin() + off, m_savedData.data.end());
 
-        vector<float> rest = getSourceData({ m_savedData.range.second, range.second });
+        vector<float> rest =
+            getSourceDataUncached({ m_savedData.range.second, range.second });
         
-        partial.insert(partial.end(), rest.begin(), rest.end());
-        return partial;
+        acc.insert(acc.end(), rest.begin(), rest.end());
+
+        m_savedData = { range, acc };
+        return acc;
+
+    } else {
+
+        auto data = getSourceDataUncached(range);
+        m_savedData = { range, data };
+        return data;
     }
+}
 
+vector<float>
+FFTModel::getSourceDataUncached(pair<sv_frame_t, sv_frame_t> range) const
+{
     vector<float> data(range.second - range.first, 0.f);
     decltype(range.first) pfx = 0;
     if (range.first < 0) {
@@ -262,8 +275,6 @@
 	    }
 	}
     }
-
-    m_savedData = { range, data };
     
     return data;
 }
--- a/data/model/FFTModel.h	Fri Jun 12 19:18:56 2015 +0100
+++ b/data/model/FFTModel.h	Sat Jun 13 08:47:05 2015 +0100
@@ -169,6 +169,7 @@
     std::vector<std::complex<float> > getFFTColumn(int column) const;
     std::vector<float> getSourceSamples(int column) const;
     std::vector<float> getSourceData(std::pair<sv_frame_t, sv_frame_t>) const;
+    std::vector<float> getSourceDataUncached(std::pair<sv_frame_t, sv_frame_t>) const;
 
     struct SavedSourceData {
         std::pair<sv_frame_t, sv_frame_t> range;