comparison data/fileio/QuickTimeFileReader.cpp @ 297:c022976d18e8

* Merge from sv-match-alignment branch (excluding alignment-specific document). - add aggregate wave model (not yet complete enough to be added as a true model in a layer, but there's potential) - add play solo mode - add alignment model -- unused in plain SV - fix two plugin leaks - add m3u playlist support (opens all files at once, potentially hazardous) - fix retrieval of pre-encoded URLs - add ability to resample audio files on import, so as to match rates with other files previously loaded; add preference for same - add preliminary support in transform code for range and rate of transform input - reorganise preferences dialog, move dark-background option to preferences, add option for temporary directory location
author Chris Cannam
date Fri, 28 Sep 2007 13:56:38 +0000
parents 42e6c8360df1
children bbf87199e6e1
comparison
equal deleted inserted replaced
296:2b6c99b607f1 297:c022976d18e8
48 }; 48 };
49 49
50 50
51 QuickTimeFileReader::QuickTimeFileReader(QString path, 51 QuickTimeFileReader::QuickTimeFileReader(QString path,
52 DecodeMode decodeMode, 52 DecodeMode decodeMode,
53 CacheMode mode) : 53 CacheMode mode,
54 CodedAudioFileReader(mode), 54 size_t targetRate) :
55 CodedAudioFileReader(mode, targetRate),
55 m_path(path), 56 m_path(path),
56 m_d(new D), 57 m_d(new D),
57 m_progress(0), 58 m_progress(0),
58 m_cancelled(false), 59 m_cancelled(false),
59 m_completion(0), 60 m_completion(0),
60 m_decodeThread(0) 61 m_decodeThread(0)
61 { 62 {
62 m_frameCount = 0;
63 m_channelCount = 0; 63 m_channelCount = 0;
64 m_sampleRate = 0; 64 m_fileRate = 0;
65 65
66 Profiler profiler("QuickTimeFileReader::QuickTimeFileReader", true); 66 Profiler profiler("QuickTimeFileReader::QuickTimeFileReader", true);
67 67
68 std::cerr << "QuickTimeFileReader: path is \"" << path.toStdString() << "\"" << std::endl; 68 std::cerr << "QuickTimeFileReader: path is \"" << path.toStdString() << "\"" << std::endl;
69 69
179 m_error = QString("Error in QuickTime decoder property get: code %1").arg(m_d->err); 179 m_error = QString("Error in QuickTime decoder property get: code %1").arg(m_d->err);
180 return; 180 return;
181 } 181 }
182 182
183 m_channelCount = m_d->asbd.mChannelsPerFrame; 183 m_channelCount = m_d->asbd.mChannelsPerFrame;
184 m_sampleRate = m_d->asbd.mSampleRate; 184 m_fileRate = m_d->asbd.mSampleRate;
185 185
186 std::cerr << "QuickTime: " << m_channelCount << " channels, " << m_sampleRate << " kHz" << std::endl; 186 std::cerr << "QuickTime: " << m_channelCount << " channels, " << m_fileRate << " kHz" << std::endl;
187 187
188 m_d->asbd.mFormatFlags = 188 m_d->asbd.mFormatFlags =
189 kAudioFormatFlagIsFloat | 189 kAudioFormatFlagIsFloat |
190 kAudioFormatFlagIsPacked | 190 kAudioFormatFlagIsPacked |
191 kAudioFormatFlagsNativeEndian; 191 kAudioFormatFlagsNativeEndian;
234 break; 234 break;
235 } 235 }
236 236
237 // std::cerr << "Read " << framesRead << " frames (block size " << m_d->blockSize << ")" << std::endl; 237 // std::cerr << "Read " << framesRead << " frames (block size " << m_d->blockSize << ")" << std::endl;
238 238
239 m_frameCount += framesRead;
240
241 // QuickTime buffers are interleaved unless specified otherwise 239 // QuickTime buffers are interleaved unless specified otherwise
242 for (UInt32 i = 0; i < framesRead * m_channelCount; ++i) { 240 addSamplesToDecodeCache(m_d->data, framesRead);
243 addSampleToDecodeCache(m_d->data[i]);
244 }
245 241
246 if (framesRead < m_d->blockSize) break; 242 if (framesRead < m_d->blockSize) break;
247 } 243 }
248 244
249 finishDecodeCache(); 245 finishDecodeCache();
286 } 282 }
287 283
288 void 284 void
289 QuickTimeFileReader::DecodeThread::run() 285 QuickTimeFileReader::DecodeThread::run()
290 { 286 {
287 if (m_reader->m_cacheMode == CacheInTemporaryFile) {
288 m_reader->m_completion = 1;
289 m_reader->startSerialised("QuickTimeFileReader::Decode");
290 }
291
291 while (1) { 292 while (1) {
292 293
293 UInt32 framesRead = m_reader->m_d->blockSize; 294 UInt32 framesRead = m_reader->m_d->blockSize;
294 UInt32 extractionFlags = 0; 295 UInt32 extractionFlags = 0;
295 m_reader->m_d->err = MovieAudioExtractionFillBuffer 296 m_reader->m_d->err = MovieAudioExtractionFillBuffer
299 m_reader->m_error = QString("Error in QuickTime decoding: code %1") 300 m_reader->m_error = QString("Error in QuickTime decoding: code %1")
300 .arg(m_reader->m_d->err); 301 .arg(m_reader->m_d->err);
301 break; 302 break;
302 } 303 }
303 304
304 m_reader->m_frameCount += framesRead;
305
306 // QuickTime buffers are interleaved unless specified otherwise 305 // QuickTime buffers are interleaved unless specified otherwise
307 for (UInt32 i = 0; i < framesRead * m_reader->m_channelCount; ++i) { 306 addSamplesToDecodeCache(m_d->data, framesRead);
308 m_reader->addSampleToDecodeCache(m_reader->m_d->data[i]);
309 }
310 307
311 if (framesRead < m_reader->m_d->blockSize) break; 308 if (framesRead < m_reader->m_d->blockSize) break;
312 } 309 }
313 310
314 m_reader->finishDecodeCache(); 311 m_reader->finishDecodeCache();
317 if (m_reader->m_d->err) { 314 if (m_reader->m_d->err) {
318 m_reader->m_error = QString("Error ending QuickTime extraction session: code %1").arg(m_reader->m_d->err); 315 m_reader->m_error = QString("Error ending QuickTime extraction session: code %1").arg(m_reader->m_d->err);
319 } 316 }
320 317
321 m_reader->m_completion = 100; 318 m_reader->m_completion = 100;
319 m_reader->endSerialised();
322 } 320 }
323 321
324 void 322 void
325 QuickTimeFileReader::getSupportedExtensions(std::set<QString> &extensions) 323 QuickTimeFileReader::getSupportedExtensions(std::set<QString> &extensions)
326 { 324 {
337 extensions.insert("mp4"); 335 extensions.insert("mp4");
338 extensions.insert("wav"); 336 extensions.insert("wav");
339 } 337 }
340 338
341 #endif 339 #endif
340