diff data/fft/FFTFileCache.h @ 266:2268963dabd1

* FFT: fix invalid write of normalisation factor in compact mode of disc cache * FFT: fix range problem for normalisation factor in compact mode (it was stored as an unsigned scaled from an assumed float range of 0->1, which is not very plausible and not accurate enough even if true -- use a float instead) * Spectrogram: fix vertical zoom behaviour for log frequency spectrograms: make the thing in the middle of the display remain in the middle after zoom * Overview widget: don't update the detailed waveform if still decoding the audio file (too expensive to do all those redraws)
author Chris Cannam
date Fri, 08 Jun 2007 15:19:50 +0000
parents 91fdc752e540
children 02d2ad95ea52
line wrap: on
line diff
--- a/data/fft/FFTFileCache.h	Wed Jun 06 16:24:55 2007 +0000
+++ b/data/fft/FFTFileCache.h	Fri Jun 08 15:19:50 2007 +0000
@@ -97,18 +97,47 @@
     void populateReadBuf(size_t x) const;
 
     float getNormalizationFactor(size_t col) const {
+        size_t h = m_mfc->getHeight();
+        if (h < m_factorSize) return 0;
         if (m_storageType != Compact) {
-            return getFromReadBufStandard(col, m_mfc->getHeight() - 1);
+            return getFromReadBufStandard(col, h - 1);
         } else {
-            float factor;
-            factor = getFromReadBufCompactUnsigned(col, m_mfc->getHeight() - 1);
-            return factor / 65535.0;
+            union {
+                float f;
+                uint16_t u[2];
+            } factor;
+            if (!m_readbuf ||
+                !(m_readbufCol == col ||
+                  (m_readbufWidth > 1 && m_readbufCol+1 == col))) {
+                populateReadBuf(col);
+            }
+            size_t ix = (col - m_readbufCol) * m_mfc->getHeight() + h;
+            factor.u[0] = ((uint16_t *)m_readbuf)[ix - 2];
+            factor.u[1] = ((uint16_t *)m_readbuf)[ix - 1];
+            return factor.f;
         }
     }
 
+    void setNormalizationFactorToWritebuf(float newfactor) {
+        size_t h = m_mfc->getHeight();
+        if (h < m_factorSize) return;
+        if (m_storageType != Compact) {
+            ((float *)m_writebuf)[h - 1] = newfactor;
+        } else {
+            union {
+                float f;
+                uint16_t u[2];
+            } factor;
+            factor.f = newfactor;
+            ((uint16_t *)m_writebuf)[h - 2] = factor.u[0];
+            ((uint16_t *)m_writebuf)[h - 1] = factor.u[1];
+        }
+    }            
+
     MatrixFile *m_mfc;
     QMutex m_writeMutex;
     StorageType m_storageType;
+    size_t m_factorSize;
 };
 
 #endif