Mercurial > hg > svcore
comparison data/fileio/CodedAudioFileReader.cpp @ 265:e08f486e8d8c
* Enable threaded decoding for Ogg and MP3 files.
Needs some work on reducing updates to the overview widget
author | Chris Cannam |
---|---|
date | Wed, 06 Jun 2007 16:24:55 +0000 |
parents | 71dfc6ab3b54 |
children | 2268963dabd1 |
comparison
equal
deleted
inserted
replaced
264:260032c26c4f | 265:e08f486e8d8c |
---|---|
71 fileInfo.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT; | 71 fileInfo.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT; |
72 | 72 |
73 m_cacheFileWritePtr = sf_open(m_cacheFileName.toLocal8Bit(), | 73 m_cacheFileWritePtr = sf_open(m_cacheFileName.toLocal8Bit(), |
74 SFM_WRITE, &fileInfo); | 74 SFM_WRITE, &fileInfo); |
75 | 75 |
76 if (!m_cacheFileWritePtr) { | 76 if (m_cacheFileWritePtr) { |
77 | |
78 //!!! really want to do this now only if we're in a | |
79 //threaded mode -- creating the reader later if we're | |
80 //not threaded -- but we don't have access to that | |
81 //information here | |
82 | |
83 m_cacheFileReader = new WavFileReader(m_cacheFileName); | |
84 | |
85 if (!m_cacheFileReader->isOK()) { | |
86 std::cerr << "ERROR: CodedAudioFileReader::initialiseDecodeCache: Failed to construct WAV file reader for temporary file: " << m_cacheFileReader->getError().toStdString() << std::endl; | |
87 delete m_cacheFileReader; | |
88 m_cacheFileReader = 0; | |
89 m_cacheMode = CacheInMemory; | |
90 sf_close(m_cacheFileWritePtr); | |
91 } | |
92 } else { | |
77 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; | 93 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; |
78 m_cacheMode = CacheInMemory; | 94 m_cacheMode = CacheInMemory; |
79 } | 95 } |
96 | |
80 } catch (DirectoryCreationFailed f) { | 97 } catch (DirectoryCreationFailed f) { |
81 std::cerr << "CodedAudioFileReader::initialiseDecodeCache: failed to create temporary directory! Falling back to in-memory cache" << std::endl; | 98 std::cerr << "CodedAudioFileReader::initialiseDecodeCache: failed to create temporary directory! Falling back to in-memory cache" << std::endl; |
82 m_cacheMode = CacheInMemory; | 99 m_cacheMode = CacheInMemory; |
83 } | 100 } |
84 } | 101 } |
110 sf_writef_float(m_cacheFileWritePtr, | 127 sf_writef_float(m_cacheFileWritePtr, |
111 m_cacheWriteBuffer, | 128 m_cacheWriteBuffer, |
112 m_cacheWriteBufferSize); | 129 m_cacheWriteBufferSize); |
113 | 130 |
114 m_cacheWriteBufferIndex = 0; | 131 m_cacheWriteBufferIndex = 0; |
132 | |
133 if (m_cacheWriteBufferIndex % 10240 == 0 && | |
134 m_cacheFileReader) { | |
135 m_cacheFileReader->updateFrameCount(); | |
136 } | |
115 } | 137 } |
116 break; | 138 break; |
117 | 139 |
118 case CacheInMemory: | 140 case CacheInMemory: |
119 m_data.push_back(sample); | 141 m_data.push_back(sample); |
152 m_cacheWriteBufferIndex = 0; | 174 m_cacheWriteBufferIndex = 0; |
153 | 175 |
154 sf_close(m_cacheFileWritePtr); | 176 sf_close(m_cacheFileWritePtr); |
155 m_cacheFileWritePtr = 0; | 177 m_cacheFileWritePtr = 0; |
156 | 178 |
179 m_cacheFileReader->updateFrameCount(); | |
180 /* | |
157 m_cacheFileReader = new WavFileReader(m_cacheFileName); | 181 m_cacheFileReader = new WavFileReader(m_cacheFileName); |
158 | 182 |
159 if (!m_cacheFileReader->isOK()) { | 183 if (!m_cacheFileReader->isOK()) { |
160 std::cerr << "ERROR: CodedAudioFileReader::finishDecodeCache: Failed to construct WAV file reader for temporary file: " << m_cacheFileReader->getError().toStdString() << std::endl; | 184 std::cerr << "ERROR: CodedAudioFileReader::finishDecodeCache: Failed to construct WAV file reader for temporary file: " << m_cacheFileReader->getError().toStdString() << std::endl; |
161 delete m_cacheFileReader; | 185 delete m_cacheFileReader; |
162 m_cacheFileReader = 0; | 186 m_cacheFileReader = 0; |
163 } | 187 }*/ |
188 | |
164 break; | 189 break; |
165 | 190 |
166 case CacheInMemory: | 191 case CacheInMemory: |
167 // nothing to do | 192 // nothing to do |
168 break; | 193 break; |
174 SampleBlock &frames) const | 199 SampleBlock &frames) const |
175 { | 200 { |
176 //!!! we want to ensure this doesn't require a lock -- at the | 201 //!!! we want to ensure this doesn't require a lock -- at the |
177 // moment it does need one, but it doesn't have one... | 202 // moment it does need one, but it doesn't have one... |
178 | 203 |
179 if (!m_initialised) return; | 204 if (!m_initialised) { |
205 std::cerr << "CodedAudioFileReader::getInterleavedFrames: not initialised" << std::endl; | |
206 return; | |
207 } | |
180 | 208 |
181 switch (m_cacheMode) { | 209 switch (m_cacheMode) { |
182 | 210 |
183 case CacheInTemporaryFile: | 211 case CacheInTemporaryFile: |
184 if (m_cacheFileReader) { | 212 if (m_cacheFileReader) { |