diff data/fileio/AudioFileReaderFactory.cpp @ 1098:329ddaf7415d simple-fft-model

Store temporary audio files in memory if we have plenty of it
author Chris Cannam
date Mon, 15 Jun 2015 14:35:37 +0100
parents abc309f507ae
children cd156ede1395
line wrap: on
line diff
--- a/data/fileio/AudioFileReaderFactory.cpp	Mon Jun 15 12:38:50 2015 +0100
+++ b/data/fileio/AudioFileReaderFactory.cpp	Mon Jun 15 14:35:37 2015 +0100
@@ -21,6 +21,9 @@
 #include "MP3FileReader.h"
 #include "QuickTimeFileReader.h"
 #include "CoreAudioFileReader.h"
+#include "AudioFileSizeEstimator.h"
+
+#include "base/StorageAdviser.h"
 
 #include <QString>
 #include <QFileInfo>
@@ -98,9 +101,22 @@
 
     AudioFileReader *reader = 0;
 
+    sv_frame_t estimatedSamples = 
+        AudioFileSizeEstimator::estimate(source, targetRate);
+    
     CodedAudioFileReader::CacheMode cacheMode =
         CodedAudioFileReader::CacheInTemporaryFile;
 
+    if (estimatedSamples > 0) {
+        size_t kb = (estimatedSamples * sizeof(float)) / 1024;
+        StorageAdviser::Recommendation rec =
+            StorageAdviser::recommend(StorageAdviser::SpeedCritical, kb, kb);
+        if (rec == StorageAdviser::UseMemory ||
+            rec == StorageAdviser::PreferMemory) {
+            cacheMode = CodedAudioFileReader::CacheInMemory;
+        }
+    }
+    
     CodedAudioFileReader::DecodeMode decodeMode =
         (threading ?
          CodedAudioFileReader::DecodeThreaded :