changeset 556:53e5dc8439e7

* get whole columns at a time from fft model when running transform
author Chris Cannam
date Mon, 09 Feb 2009 11:53:29 +0000 (2009-02-09)
parents 8accc7969c1c
children a40023bebd15
files data/fft/FFTDataServer.cpp data/fft/FFTDataServer.h data/model/FFTModel.h transform/FeatureExtractionModelTransformer.cpp
diffstat 4 files changed, 46 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/data/fft/FFTDataServer.cpp	Mon Feb 09 11:38:08 2009 +0000
+++ b/data/fft/FFTDataServer.cpp	Mon Feb 09 11:53:29 2009 +0000
@@ -1083,6 +1083,36 @@
 }
 
 bool
+FFTDataServer::getValuesAt(size_t x, float *reals, float *imaginaries, size_t minbin, size_t count, size_t step)
+{
+    Profiler profiler("FFTDataServer::getValuesAt", false);
+
+    if (x >= m_width) return false;
+
+    if (minbin >= m_height) minbin = m_height - 1;
+    if (count == 0) count = (m_height - minbin) / step;
+    else if (minbin + count * step > m_height) {
+        count = (m_height - minbin) / step;
+    }
+
+    size_t col;
+    FFTCacheReader *cache = getCacheReader(x, col);
+    if (!cache) return false;
+
+    //!!! n.b. can throw
+    if (!cache->haveSetColumnAt(col)) {
+        Profiler profiler("FFTDataServer::getValuesAt: filling");
+        fillColumn(x);
+    }
+
+    for (size_t i = 0; i < count; ++i) {
+        cache->getValuesAt(col, i * step + minbin, reals[i], imaginaries[i]);
+    }
+
+    return true;
+}
+
+bool
 FFTDataServer::isColumnReady(size_t x)
 {
     Profiler profiler("FFTDataServer::isColumnReady", false);
--- a/data/fft/FFTDataServer.h	Mon Feb 09 11:38:08 2009 +0000
+++ b/data/fft/FFTDataServer.h	Mon Feb 09 11:53:29 2009 +0000
@@ -88,6 +88,7 @@
     bool       getMagnitudesAt(size_t x, float *values, size_t minbin = 0, size_t count = 0, size_t step = 1);
     bool       getNormalizedMagnitudesAt(size_t x, float *values, size_t minbin = 0, size_t count = 0, size_t step = 1);
     bool       getPhasesAt(size_t x, float *values, size_t minbin = 0, size_t count = 0, size_t step = 1);
+    bool       getValuesAt(size_t x, float *reals, float *imaginaries, size_t minbin = 0, size_t count = 0, size_t step = 1);
 
     void       suspend();
     void       suspendWrites();
--- a/data/model/FFTModel.h	Mon Feb 09 11:38:08 2009 +0000
+++ b/data/model/FFTModel.h	Mon Feb 09 11:53:29 2009 +0000
@@ -94,6 +94,9 @@
     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());
     }
+    inline bool getValuesAt(size_t x, float *reals, float *imaginaries, size_t minbin = 0, size_t count = 0) {
+        return m_server->getValuesAt(x << m_xshift, reals, imaginaries, minbin << m_yshift, count, getYRatio());
+    }
 
     inline size_t getFillExtent() const { return m_server->getFillExtent(); }
 
--- a/transform/FeatureExtractionModelTransformer.cpp	Mon Feb 09 11:38:08 2009 +0000
+++ b/transform/FeatureExtractionModelTransformer.cpp	Mon Feb 09 11:53:29 2009 +0000
@@ -449,6 +449,13 @@
 
     setCompletion(0);
 
+    float *reals = 0;
+    float *imaginaries = 0;
+    if (frequencyDomain) {
+        reals = new float[blockSize/2 + 1];
+        imaginaries = new float[blockSize/2 + 1];
+    }
+
     while (!m_abandoned) {
 
         if (frequencyDomain) {
@@ -472,9 +479,10 @@
         if (frequencyDomain) {
             for (size_t ch = 0; ch < channelCount; ++ch) {
                 int column = (blockFrame - startFrame) / stepSize;
+                fftModels[ch]->getValuesAt(column, reals, imaginaries);
                 for (size_t i = 0; i <= blockSize/2; ++i) {
-                    fftModels[ch]->getValuesAt
-                        (column, i, buffers[ch][i*2], buffers[ch][i*2+1]);
+                    buffers[ch][i*2] = reals[i];
+                    buffers[ch][i*2+1] = imaginaries[i];
                 }
             }
         } else {
@@ -518,6 +526,8 @@
         for (size_t ch = 0; ch < channelCount; ++ch) {
             delete fftModels[ch];
         }
+        delete[] reals;
+        delete[] imaginaries;
     }
 }