diff base/FFTFileCache.cpp @ 90:c4e163f911dd

* Switch spectrogram layer over to using the new rudimentary disk-backed FFT cache
author Chris Cannam
date Wed, 03 May 2006 14:26:26 +0000
parents 024d4a71f5bf
children 1aebdc68ec6d
line wrap: on
line diff
--- a/base/FFTFileCache.cpp	Wed May 03 11:15:46 2006 +0000
+++ b/base/FFTFileCache.cpp	Wed May 03 14:26:26 2006 +0000
@@ -17,8 +17,112 @@
 
 #include "MatrixFileCache.h"
 
-FFTFileCache::FFTFileCache()
+#include <iostream>
+
+//!!! This class is a work in progress -- it does only as much as we
+// need for the current SpectrogramLayer.  Slated for substantial
+// refactoring and extension.
+
+// The underlying matrix has height (m_height * 2 + 1).  In each
+// column we store magnitude at [0], [2] etc and phase at [1], [3]
+// etc, and then store the normalization factor (maximum magnitude) at
+// [m_height * 2].
+
+FFTFileCache::FFTFileCache(QString fileBase, MatrixFileCache::Mode mode) :
+    m_colbuf(0),
+    m_mfc(new MatrixFileCache(fileBase, mode))
 {
-    //...
-    
 }
+
+FFTFileCache::~FFTFileCache()
+{
+    delete m_colbuf;
+    delete m_mfc;
+}
+
+size_t
+FFTFileCache::getWidth() const
+{
+    return m_mfc->getWidth();
+}
+
+size_t
+FFTFileCache::getHeight() const
+{
+    size_t mh = m_mfc->getHeight();
+    if (mh > 0) return (mh - 1) / 2;
+    else return 0;
+}
+
+void
+FFTFileCache::resize(size_t width, size_t height)
+{
+    m_mfc->resize(width, height * 2 + 1);
+    delete m_colbuf;
+    m_colbuf = new float[height * 2 + 1];
+}
+
+void
+FFTFileCache::reset()
+{
+    m_mfc->reset();
+}
+
+float
+FFTFileCache::getMagnitudeAt(size_t x, size_t y) const
+{
+    return m_mfc->getValueAt(x, y * 2);
+}
+
+float
+FFTFileCache::getNormalizedMagnitudeAt(size_t x, size_t y) const
+{
+    float factor = m_mfc->getValueAt(x, m_mfc->getHeight() - 1);
+    float mag = m_mfc->getValueAt(x, y * 2);
+    if (factor != 0) return mag / factor;
+    else return 0.f;
+}
+
+float
+FFTFileCache::getPhaseAt(size_t x, size_t y) const
+{
+    return m_mfc->getValueAt(x, y * 2 + 1);
+}
+
+void
+FFTFileCache::setNormalizationFactor(size_t x, float factor)
+{
+    m_mfc->setValueAt(x, m_mfc->getHeight() - 1, factor);
+}
+
+void
+FFTFileCache::setMagnitudeAt(size_t x, size_t y, float mag)
+{
+    m_mfc->setValueAt(x, y * 2, mag);
+}
+
+void
+FFTFileCache::setNormalizedMagnitudeAt(size_t x, size_t y, float norm)
+{
+    float factor = m_mfc->getValueAt(x, m_mfc->getHeight() - 1);
+    m_mfc->setValueAt(x, y * 2, norm * factor);
+}
+
+void
+FFTFileCache::setPhaseAt(size_t x, size_t y, float phase)
+{
+    m_mfc->setValueAt(x, y * 2 + 1, phase);
+}
+
+void
+FFTFileCache::setColumnAt(size_t x, float *mags, float *phases, float factor)
+{
+    size_t h = getHeight();
+    for (size_t y = 0; y < h; ++y) {
+        m_colbuf[y * 2] = mags[y];
+        m_colbuf[y * 2 + 1] = phases[y];
+    }
+    m_colbuf[h * 2] = factor;
+    m_mfc->setColumnAt(x, m_colbuf);
+}
+