diff layer/SpectrogramLayer.cpp @ 1450:6cf3cb6641e1 single-point

Tweak peak-cache allocations etc in the hope of making long spectrograms a little faster to re-render
author Chris Cannam
date Wed, 01 May 2019 14:41:28 +0100
parents e2b6a13a1f69
children 66bf1abfefc1
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp	Wed May 01 14:40:51 2019 +0100
+++ b/layer/SpectrogramLayer.cpp	Wed May 01 14:41:28 2019 +0100
@@ -1411,7 +1411,10 @@
     FFTModel *oldModel = m_fftModel;
     m_fftModel = newModel;
 
-    if (canStoreWholeCache()) { // i.e. if enough memory
+    bool createWholeCache = false;
+    checkCacheSpace(&m_peakCacheDivisor, &createWholeCache);
+    
+    if (createWholeCache) {
         m_wholeCache = new Dense3DModelPeakCache(m_fftModel, 1);
         m_peakCache = new Dense3DModelPeakCache(m_wholeCache, m_peakCacheDivisor);
     } else {
@@ -1422,12 +1425,14 @@
     delete oldModel;
 }
 
-bool
-SpectrogramLayer::canStoreWholeCache() const
+void
+SpectrogramLayer::checkCacheSpace(int *suggestedPeakDivisor,
+                                  bool *createWholeCache) const
 {
-    if (!m_fftModel) {
-        return false; // or true, doesn't really matter
-    }
+    *suggestedPeakDivisor = 8;
+    *createWholeCache = false;
+    
+    if (!m_fftModel) return;
 
     size_t sz =
         size_t(m_fftModel->getWidth()) *
@@ -1436,23 +1441,28 @@
 
     try {
         SVDEBUG << "Requesting advice from StorageAdviser on whether to create whole-model cache" << endl;
+        // The lower amount here is the amount required for the
+        // slightly higher-resolution version of the peak cache
+        // without a whole-model cache; the higher amount is that for
+        // the whole-model cache. The factors of 1024 are because
+        // StorageAdviser rather stupidly works in kilobytes
         StorageAdviser::Recommendation recommendation =
             StorageAdviser::recommend
             (StorageAdviser::Criteria(StorageAdviser::SpeedCritical |
                                       StorageAdviser::PrecisionCritical |
                                       StorageAdviser::FrequentLookupLikely),
-             sz / 1024, sz / 1024);
-        if ((recommendation & StorageAdviser::UseDisc) ||
-            (recommendation & StorageAdviser::ConserveSpace)) {
+             (sz / 8) / 1024, sz / 1024);
+        if (recommendation & StorageAdviser::UseDisc) {
             SVDEBUG << "Seems inadvisable to create whole-model cache" << endl;
-            return false;
-        } else {
+        } else if (recommendation & StorageAdviser::ConserveSpace) {
+            SVDEBUG << "Seems inadvisable to create whole-model cache but acceptable to use the slightly higher-resolution peak cache" << endl;
+            *suggestedPeakDivisor = 4;
+        } else  {
             SVDEBUG << "Seems fine to create whole-model cache" << endl;
-            return true;
+            *createWholeCache = true;
         }
     } catch (const InsufficientDiscSpace &) {
         SVDEBUG << "Seems like a terrible idea to create whole-model cache" << endl;
-        return false;
     }
 }