comparison data/fileio/CodedAudioFileReader.cpp @ 689:573d45e9487b

Merge from debug-output branch
author Chris Cannam
date Tue, 14 Jun 2011 14:47:59 +0100
parents 06f13a3b9e9e
children 1424aa29ae95
comparison
equal deleted inserted replaced
688:be43b2fe68e8 689:573d45e9487b
38 m_cacheWriteBufferIndex(0), 38 m_cacheWriteBufferIndex(0),
39 m_cacheWriteBufferSize(16384), 39 m_cacheWriteBufferSize(16384),
40 m_resampler(0), 40 m_resampler(0),
41 m_resampleBuffer(0) 41 m_resampleBuffer(0)
42 { 42 {
43 // std::cerr << "CodedAudioFileReader::CodedAudioFileReader: rate " << targetRate << std::endl; 43 // DEBUG << "CodedAudioFileReader::CodedAudioFileReader: rate " << targetRate << endl;
44 44
45 m_frameCount = 0; 45 m_frameCount = 0;
46 m_sampleRate = targetRate; 46 m_sampleRate = targetRate;
47 } 47 }
48 48
52 52
53 endSerialised(); 53 endSerialised();
54 54
55 if (m_cacheFileWritePtr) sf_close(m_cacheFileWritePtr); 55 if (m_cacheFileWritePtr) sf_close(m_cacheFileWritePtr);
56 56
57 // std::cerr << "CodedAudioFileReader::~CodedAudioFileReader: deleting cache file reader" << std::endl; 57 // DEBUG << "CodedAudioFileReader::~CodedAudioFileReader: deleting cache file reader" << endl;
58 58
59 delete m_cacheFileReader; 59 delete m_cacheFileReader;
60 delete[] m_cacheWriteBuffer; 60 delete[] m_cacheWriteBuffer;
61 61
62 if (m_cacheFileName != "") { 62 if (m_cacheFileName != "") {
63 if (!QFile(m_cacheFileName).remove()) { 63 if (!QFile(m_cacheFileName).remove()) {
64 std::cerr << "WARNING: CodedAudioFileReader::~CodedAudioFileReader: Failed to delete cache file \"" << m_cacheFileName.toStdString() << "\"" << std::endl; 64 std::cerr << "WARNING: CodedAudioFileReader::~CodedAudioFileReader: Failed to delete cache file \"" << m_cacheFileName << "\"" << std::endl;
65 } 65 }
66 } 66 }
67 67
68 delete m_resampler; 68 delete m_resampler;
69 delete[] m_resampleBuffer; 69 delete[] m_resampleBuffer;
70 } 70 }
71 71
72 void 72 void
73 CodedAudioFileReader::startSerialised(QString id) 73 CodedAudioFileReader::startSerialised(QString id)
74 { 74 {
75 // std::cerr << "CodedAudioFileReader::startSerialised(" << id.toStdString() << ")" << std::endl; 75 // DEBUG << "CodedAudioFileReader::startSerialised(" << id << ")" << endl;
76 76
77 delete m_serialiser; 77 delete m_serialiser;
78 m_serialiser = new Serialiser(id); 78 m_serialiser = new Serialiser(id);
79 } 79 }
80 80
90 void 90 void
91 CodedAudioFileReader::initialiseDecodeCache() 91 CodedAudioFileReader::initialiseDecodeCache()
92 { 92 {
93 QMutexLocker locker(&m_cacheMutex); 93 QMutexLocker locker(&m_cacheMutex);
94 94
95 // std::cerr << "CodedAudioFileReader::initialiseDecodeCache: file rate = " << m_fileRate << std::endl; 95 // DEBUG << "CodedAudioFileReader::initialiseDecodeCache: file rate = " << m_fileRate << endl;
96 96
97 if (m_fileRate == 0) { 97 if (m_fileRate == 0) {
98 std::cerr << "CodedAudioFileReader::initialiseDecodeCache: ERROR: File sample rate unknown (bug in subclass implementation?)" << std::endl; 98 DEBUG << "CodedAudioFileReader::initialiseDecodeCache: ERROR: File sample rate unknown (bug in subclass implementation?)" << endl;
99 m_fileRate = 48000; // got to have something 99 m_fileRate = 48000; // got to have something
100 } 100 }
101 if (m_sampleRate == 0) { 101 if (m_sampleRate == 0) {
102 m_sampleRate = m_fileRate; 102 m_sampleRate = m_fileRate;
103 std::cerr << "CodedAudioFileReader::initialiseDecodeCache: rate (from file) = " << m_fileRate << std::endl; 103 DEBUG << "CodedAudioFileReader::initialiseDecodeCache: rate (from file) = " << m_fileRate << endl;
104 } 104 }
105 if (m_fileRate != m_sampleRate) { 105 if (m_fileRate != m_sampleRate) {
106 std::cerr << "CodedAudioFileReader: resampling " << m_fileRate << " -> " << m_sampleRate << std::endl; 106 std::cerr << "CodedAudioFileReader: resampling " << m_fileRate << " -> " << m_sampleRate << std::endl;
107 m_resampler = new Resampler(Resampler::FastestTolerable, 107 m_resampler = new Resampler(Resampler::FastestTolerable,
108 m_channelCount, 108 m_channelCount,
142 // information here 142 // information here
143 143
144 m_cacheFileReader = new WavFileReader(m_cacheFileName); 144 m_cacheFileReader = new WavFileReader(m_cacheFileName);
145 145
146 if (!m_cacheFileReader->isOK()) { 146 if (!m_cacheFileReader->isOK()) {
147 std::cerr << "ERROR: CodedAudioFileReader::initialiseDecodeCache: Failed to construct WAV file reader for temporary file: " << m_cacheFileReader->getError().toStdString() << std::endl; 147 std::cerr << "ERROR: CodedAudioFileReader::initialiseDecodeCache: Failed to construct WAV file reader for temporary file: " << m_cacheFileReader->getError() << std::endl;
148 delete m_cacheFileReader; 148 delete m_cacheFileReader;
149 m_cacheFileReader = 0; 149 m_cacheFileReader = 0;
150 m_cacheMode = CacheInMemory; 150 m_cacheMode = CacheInMemory;
151 sf_close(m_cacheFileWritePtr); 151 sf_close(m_cacheFileWritePtr);
152 } 152 }
153 153
154 } else { 154 } else {
155 std::cerr << "CodedAudioFileReader::initialiseDecodeCache: failed to open cache file \"" << m_cacheFileName.toStdString() << "\" (" << m_channelCount << " channels, sample rate " << m_sampleRate << " for writing, falling back to in-memory cache" << std::endl; 155 std::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" << std::endl;
156 m_cacheMode = CacheInMemory; 156 m_cacheMode = CacheInMemory;
157 } 157 }
158 158
159 } catch (DirectoryCreationFailed f) { 159 } catch (DirectoryCreationFailed f) {
160 std::cerr << "CodedAudioFileReader::initialiseDecodeCache: failed to create temporary directory! Falling back to in-memory cache" << std::endl; 160 std::cerr << "CodedAudioFileReader::initialiseDecodeCache: failed to create temporary directory! Falling back to in-memory cache" << std::endl;
352 // Lock is only required in CacheInMemory mode (the cache file 352 // Lock is only required in CacheInMemory mode (the cache file
353 // reader is expected to be thread safe and manage its own 353 // reader is expected to be thread safe and manage its own
354 // locking) 354 // locking)
355 355
356 if (!m_initialised) { 356 if (!m_initialised) {
357 std::cerr << "CodedAudioFileReader::getInterleavedFrames: not initialised" << std::endl; 357 DEBUG << "CodedAudioFileReader::getInterleavedFrames: not initialised" << endl;
358 return; 358 return;
359 } 359 }
360 360
361 switch (m_cacheMode) { 361 switch (m_cacheMode) {
362 362