comparison data/fileio/CodedAudioFileReader.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 4d9816ba0ebe
children 5cbf71022679
comparison
equal deleted inserted replaced
1097:abc309f507ae 1098:329ddaf7415d
19 #include "base/TempDirectory.h" 19 #include "base/TempDirectory.h"
20 #include "base/Exceptions.h" 20 #include "base/Exceptions.h"
21 #include "base/Profiler.h" 21 #include "base/Profiler.h"
22 #include "base/Serialiser.h" 22 #include "base/Serialiser.h"
23 #include "base/Resampler.h" 23 #include "base/Resampler.h"
24 #include "base/StorageAdviser.h"
24 25
25 #include <stdint.h> 26 #include <stdint.h>
26 #include <iostream> 27 #include <iostream>
27 #include <QDir> 28 #include <QDir>
28 #include <QMutexLocker> 29 #include <QMutexLocker>
57 CodedAudioFileReader::~CodedAudioFileReader() 58 CodedAudioFileReader::~CodedAudioFileReader()
58 { 59 {
59 QMutexLocker locker(&m_cacheMutex); 60 QMutexLocker locker(&m_cacheMutex);
60 61
61 endSerialised(); 62 endSerialised();
62 63
63 if (m_cacheFileWritePtr) sf_close(m_cacheFileWritePtr); 64 if (m_cacheFileWritePtr) sf_close(m_cacheFileWritePtr);
64 65
65 SVDEBUG << "CodedAudioFileReader::~CodedAudioFileReader: deleting cache file reader" << endl; 66 SVDEBUG << "CodedAudioFileReader::~CodedAudioFileReader: deleting cache file reader" << endl;
66 67
67 delete m_cacheFileReader; 68 delete m_cacheFileReader;
73 } 74 }
74 } 75 }
75 76
76 delete m_resampler; 77 delete m_resampler;
77 delete[] m_resampleBuffer; 78 delete[] m_resampleBuffer;
79
80 if (!m_data.empty()) {
81 StorageAdviser::notifyDoneAllocation
82 (StorageAdviser::MemoryAllocation,
83 (m_data.size() * sizeof(float)) / 1024);
84 }
78 } 85 }
79 86
80 void 87 void
81 CodedAudioFileReader::startSerialised(QString id) 88 CodedAudioFileReader::startSerialised(QString id)
82 { 89 {
292 299
293 delete m_resampler; 300 delete m_resampler;
294 m_resampler = 0; 301 m_resampler = 0;
295 302
296 if (m_cacheMode == CacheInTemporaryFile) { 303 if (m_cacheMode == CacheInTemporaryFile) {
304
297 sf_close(m_cacheFileWritePtr); 305 sf_close(m_cacheFileWritePtr);
298 m_cacheFileWritePtr = 0; 306 m_cacheFileWritePtr = 0;
299 if (m_cacheFileReader) m_cacheFileReader->updateFrameCount(); 307 if (m_cacheFileReader) m_cacheFileReader->updateFrameCount();
308
309 } else {
310 // I know, I know, we already allocated it...
311 StorageAdviser::notifyPlannedAllocation
312 (StorageAdviser::MemoryAllocation,
313 (m_data.size() * sizeof(float)) / 1024);
300 } 314 }
301 } 315 }
302 316
303 void 317 void
304 CodedAudioFileReader::pushBuffer(float *buffer, sv_frame_t sz, bool final) 318 CodedAudioFileReader::pushBuffer(float *buffer, sv_frame_t sz, bool final)