comparison data/fileio/CodedAudioFileReader.cpp @ 1279:0a9193dc136b 3.0-integration

Debug output updates
author Chris Cannam
date Tue, 22 Nov 2016 16:40:41 +0000
parents 6877f4200912
children 56c06dc0937c
comparison
equal deleted inserted replaced
1278:0be27c989c1d 1279:0a9193dc136b
47 m_fileFrameCount(0), 47 m_fileFrameCount(0),
48 m_normalised(normalised), 48 m_normalised(normalised),
49 m_max(0.f), 49 m_max(0.f),
50 m_gain(1.f) 50 m_gain(1.f)
51 { 51 {
52 SVDEBUG << "CodedAudioFileReader::CodedAudioFileReader: rate " << targetRate << ", normalised = " << normalised << endl; 52 SVDEBUG << "CodedAudioFileReader:: cache mode: " << cacheMode
53 << " (" << (cacheMode == CacheInTemporaryFile
54 ? "CacheInTemporaryFile" : "CacheInMemory") << ")"
55 << ", rate: " << targetRate
56 << (targetRate == 0 ? " (use source rate)" : "")
57 << ", normalised: " << normalised << endl;
53 58
54 m_frameCount = 0; 59 m_frameCount = 0;
55 m_sampleRate = targetRate; 60 m_sampleRate = targetRate;
56 } 61 }
57 62
58 CodedAudioFileReader::~CodedAudioFileReader() 63 CodedAudioFileReader::~CodedAudioFileReader()
59 { 64 {
60 QMutexLocker locker(&m_cacheMutex); 65 QMutexLocker locker(&m_cacheMutex);
61 66
62 endSerialised(); 67 if (m_serialiser) endSerialised();
63 68
64 if (m_cacheFileWritePtr) sf_close(m_cacheFileWritePtr); 69 if (m_cacheFileWritePtr) sf_close(m_cacheFileWritePtr);
65 70
66 SVDEBUG << "CodedAudioFileReader::~CodedAudioFileReader: deleting cache file reader" << endl; 71 SVDEBUG << "CodedAudioFileReader::~CodedAudioFileReader: deleting cache file reader" << endl;
67 72
68 delete m_cacheFileReader; 73 delete m_cacheFileReader;
69 delete[] m_cacheWriteBuffer; 74 delete[] m_cacheWriteBuffer;
70 75
71 if (m_cacheFileName != "") { 76 if (m_cacheFileName != "") {
77 SVDEBUG << "CodedAudioFileReader::~CodedAudioFileReader: deleting cache file " << m_cacheFileName << endl;
72 if (!QFile(m_cacheFileName).remove()) { 78 if (!QFile(m_cacheFileName).remove()) {
73 cerr << "WARNING: CodedAudioFileReader::~CodedAudioFileReader: Failed to delete cache file \"" << m_cacheFileName << "\"" << endl; 79 SVDEBUG << "WARNING: CodedAudioFileReader::~CodedAudioFileReader: Failed to delete cache file \"" << m_cacheFileName << "\"" << endl;
74 } 80 }
75 } 81 }
76 82
77 delete m_resampler; 83 delete m_resampler;
78 delete[] m_resampleBuffer; 84 delete[] m_resampleBuffer;
85 } 91 }
86 92
87 void 93 void
88 CodedAudioFileReader::startSerialised(QString id) 94 CodedAudioFileReader::startSerialised(QString id)
89 { 95 {
90 SVDEBUG << "CodedAudioFileReader::startSerialised(" << id << ")" << endl; 96 SVDEBUG << "CodedAudioFileReader(" << this << ")::startSerialised: id = " << id << endl;
91 97
92 delete m_serialiser; 98 delete m_serialiser;
93 m_serialiser = new Serialiser(id); 99 m_serialiser = new Serialiser(id);
94 } 100 }
95 101
108 QMutexLocker locker(&m_cacheMutex); 114 QMutexLocker locker(&m_cacheMutex);
109 115
110 SVDEBUG << "CodedAudioFileReader::initialiseDecodeCache: file rate = " << m_fileRate << endl; 116 SVDEBUG << "CodedAudioFileReader::initialiseDecodeCache: file rate = " << m_fileRate << endl;
111 117
112 if (m_fileRate == 0) { 118 if (m_fileRate == 0) {
113 cerr << "CodedAudioFileReader::initialiseDecodeCache: ERROR: File sample rate unknown (bug in subclass implementation?)" << endl; 119 SVDEBUG << "CodedAudioFileReader::initialiseDecodeCache: ERROR: File sample rate unknown (bug in subclass implementation?)" << endl;
114 throw FileOperationFailed("(coded file)", "File sample rate unknown (bug in subclass implementation?)"); 120 throw FileOperationFailed("(coded file)", "File sample rate unknown (bug in subclass implementation?)");
115 } 121 }
116 if (m_sampleRate == 0) { 122 if (m_sampleRate == 0) {
117 m_sampleRate = m_fileRate; 123 m_sampleRate = m_fileRate;
118 SVDEBUG << "CodedAudioFileReader::initialiseDecodeCache: rate (from file) = " << m_fileRate << endl; 124 SVDEBUG << "CodedAudioFileReader::initialiseDecodeCache: rate (from file) = " << m_fileRate << endl;
138 .arg((intptr_t)this)); 144 .arg((intptr_t)this));
139 145
140 SF_INFO fileInfo; 146 SF_INFO fileInfo;
141 int fileRate = int(round(m_sampleRate)); 147 int fileRate = int(round(m_sampleRate));
142 if (m_sampleRate != sv_samplerate_t(fileRate)) { 148 if (m_sampleRate != sv_samplerate_t(fileRate)) {
143 cerr << "CodedAudioFileReader: WARNING: Non-integer sample rate " 149 SVDEBUG << "CodedAudioFileReader: WARNING: Non-integer sample rate "
144 << m_sampleRate << " presented for writing, rounding to " << fileRate 150 << m_sampleRate << " presented for writing, rounding to " << fileRate
145 << endl; 151 << endl;
146 } 152 }
147 fileInfo.samplerate = fileRate; 153 fileInfo.samplerate = fileRate;
148 fileInfo.channels = m_channelCount; 154 fileInfo.channels = m_channelCount;
179 // information here 185 // information here
180 186
181 m_cacheFileReader = new WavFileReader(m_cacheFileName); 187 m_cacheFileReader = new WavFileReader(m_cacheFileName);
182 188
183 if (!m_cacheFileReader->isOK()) { 189 if (!m_cacheFileReader->isOK()) {
184 cerr << "ERROR: CodedAudioFileReader::initialiseDecodeCache: Failed to construct WAV file reader for temporary file: " << m_cacheFileReader->getError() << endl; 190 SVDEBUG << "ERROR: CodedAudioFileReader::initialiseDecodeCache: Failed to construct WAV file reader for temporary file: " << m_cacheFileReader->getError() << endl;
185 delete m_cacheFileReader; 191 delete m_cacheFileReader;
186 m_cacheFileReader = 0; 192 m_cacheFileReader = 0;
187 m_cacheMode = CacheInMemory; 193 m_cacheMode = CacheInMemory;
188 sf_close(m_cacheFileWritePtr); 194 sf_close(m_cacheFileWritePtr);
189 } 195 }
190 196
191 } else { 197 } else {
192 cerr << "CodedAudioFileReader::initialiseDecodeCache: failed to open cache file \"" << m_cacheFileName << "\" (" << m_channelCount << " channels, sample rate " << m_sampleRate << " for writing, falling back to in-memory cache" << endl; 198 SVDEBUG << "CodedAudioFileReader::initialiseDecodeCache: failed to open cache file \"" << m_cacheFileName << "\" (" << m_channelCount << " channels, sample rate " << m_sampleRate << " for writing, falling back to in-memory cache" << endl;
193 m_cacheMode = CacheInMemory; 199 m_cacheMode = CacheInMemory;
194 } 200 }
195 201
196 } catch (DirectoryCreationFailed f) { 202 } catch (DirectoryCreationFailed f) {
197 cerr << "CodedAudioFileReader::initialiseDecodeCache: failed to create temporary directory! Falling back to in-memory cache" << endl; 203 SVDEBUG << "CodedAudioFileReader::initialiseDecodeCache: failed to create temporary directory! Falling back to in-memory cache" << endl;
198 m_cacheMode = CacheInMemory; 204 m_cacheMode = CacheInMemory;
199 } 205 }
200 } 206 }
201 207
202 if (m_cacheMode == CacheInMemory) { 208 if (m_cacheMode == CacheInMemory) {
297 QMutexLocker locker(&m_cacheMutex); 303 QMutexLocker locker(&m_cacheMutex);
298 304
299 Profiler profiler("CodedAudioFileReader::finishDecodeCache", true); 305 Profiler profiler("CodedAudioFileReader::finishDecodeCache", true);
300 306
301 if (!m_initialised) { 307 if (!m_initialised) {
302 cerr << "WARNING: CodedAudioFileReader::finishDecodeCache: Cache was never initialised!" << endl; 308 SVDEBUG << "WARNING: CodedAudioFileReader::finishDecodeCache: Cache was never initialised!" << endl;
303 return; 309 return;
304 } 310 }
305 311
306 pushBuffer(m_cacheWriteBuffer, 312 pushBuffer(m_cacheWriteBuffer,
307 m_cacheWriteBufferIndex / m_channelCount, 313 m_cacheWriteBufferIndex / m_channelCount,
465 if (!isOK()) return {}; 471 if (!isOK()) return {};
466 if (count == 0) return {}; 472 if (count == 0) return {};
467 473
468 sv_frame_t ix0 = start * m_channelCount; 474 sv_frame_t ix0 = start * m_channelCount;
469 sv_frame_t ix1 = ix0 + (count * m_channelCount); 475 sv_frame_t ix1 = ix0 + (count * m_channelCount);
470
471 476
472 // This lock used to be a QReadWriteLock, but it appears that 477 // This lock used to be a QReadWriteLock, but it appears that
473 // its lock mechanism is significantly slower than QMutex so 478 // its lock mechanism is significantly slower than QMutex so
474 // it's not a good idea in cases like this where we don't 479 // it's not a good idea in cases like this where we don't
475 // really have threads taking a long time to read concurrently 480 // really have threads taking a long time to read concurrently