comparison 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
comparison
equal deleted inserted replaced
1097:abc309f507ae 1098:329ddaf7415d
19 #include "DecodingWavFileReader.h" 19 #include "DecodingWavFileReader.h"
20 #include "OggVorbisFileReader.h" 20 #include "OggVorbisFileReader.h"
21 #include "MP3FileReader.h" 21 #include "MP3FileReader.h"
22 #include "QuickTimeFileReader.h" 22 #include "QuickTimeFileReader.h"
23 #include "CoreAudioFileReader.h" 23 #include "CoreAudioFileReader.h"
24 #include "AudioFileSizeEstimator.h"
25
26 #include "base/StorageAdviser.h"
24 27
25 #include <QString> 28 #include <QString>
26 #include <QFileInfo> 29 #include <QFileInfo>
27 #include <iostream> 30 #include <iostream>
28 31
96 return 0; 99 return 0;
97 } 100 }
98 101
99 AudioFileReader *reader = 0; 102 AudioFileReader *reader = 0;
100 103
104 sv_frame_t estimatedSamples =
105 AudioFileSizeEstimator::estimate(source, targetRate);
106
101 CodedAudioFileReader::CacheMode cacheMode = 107 CodedAudioFileReader::CacheMode cacheMode =
102 CodedAudioFileReader::CacheInTemporaryFile; 108 CodedAudioFileReader::CacheInTemporaryFile;
103 109
110 if (estimatedSamples > 0) {
111 size_t kb = (estimatedSamples * sizeof(float)) / 1024;
112 StorageAdviser::Recommendation rec =
113 StorageAdviser::recommend(StorageAdviser::SpeedCritical, kb, kb);
114 if (rec == StorageAdviser::UseMemory ||
115 rec == StorageAdviser::PreferMemory) {
116 cacheMode = CodedAudioFileReader::CacheInMemory;
117 }
118 }
119
104 CodedAudioFileReader::DecodeMode decodeMode = 120 CodedAudioFileReader::DecodeMode decodeMode =
105 (threading ? 121 (threading ?
106 CodedAudioFileReader::DecodeThreaded : 122 CodedAudioFileReader::DecodeThreaded :
107 CodedAudioFileReader::DecodeAtOnce); 123 CodedAudioFileReader::DecodeAtOnce);
108 124