Mercurial > hg > sonic-annotator
comparison runner/FeatureExtractionManager.cpp @ 31:8b20521fc40f
* Commit old fix (which I hope was correct!) to avoid leaking fds on
exceptions
* Remove dependency on audioio library
author | Chris Cannam |
---|---|
date | Fri, 12 Mar 2010 12:08:21 +0000 |
parents | 0af07912f386 |
children | 76ea8ffc4dfa |
comparison
equal
deleted
inserted
replaced
30:1141bc562301 | 31:8b20521fc40f |
---|---|
381 | 381 |
382 void FeatureExtractionManager::extractFeatures(QString audioSource) | 382 void FeatureExtractionManager::extractFeatures(QString audioSource) |
383 { | 383 { |
384 if (m_plugins.empty()) return; | 384 if (m_plugins.empty()) return; |
385 | 385 |
386 testOutputFiles(audioSource); | |
387 | |
386 ProgressPrinter retrievalProgress("Retrieving audio data..."); | 388 ProgressPrinter retrievalProgress("Retrieving audio data..."); |
387 | 389 |
388 FileSource source(audioSource, &retrievalProgress); | 390 FileSource source(audioSource, &retrievalProgress); |
389 if (!source.isAvailable()) { | 391 if (!source.isAvailable()) { |
390 cerr << "ERROR: File or URL \"" << audioSource.toStdString() | 392 cerr << "ERROR: File or URL \"" << audioSource.toStdString() |
427 | 429 |
428 cerr << "Opened " << channels << "-channel file or URL \"" << audioSource.toStdString() << "\"" << endl; | 430 cerr << "Opened " << channels << "-channel file or URL \"" << audioSource.toStdString() << "\"" << endl; |
429 | 431 |
430 // reject file if it has too few channels, plugin will handle if it has too many | 432 // reject file if it has too few channels, plugin will handle if it has too many |
431 if ((int)channels < m_channels) { | 433 if ((int)channels < m_channels) { |
434 delete reader; | |
432 throw FileOperationFailed | 435 throw FileOperationFailed |
433 (audioSource, | 436 (audioSource, |
434 QString("read sufficient channels (found %1, require %2)") | 437 QString("read sufficient channels (found %1, require %2)") |
435 .arg(channels).arg(m_channels)); | 438 .arg(channels).arg(m_channels)); |
436 } | 439 } |
438 // allocate audio buffers | 441 // allocate audio buffers |
439 float **data = new float *[m_channels]; | 442 float **data = new float *[m_channels]; |
440 for (int c = 0; c < m_channels; ++c) { | 443 for (int c = 0; c < m_channels; ++c) { |
441 data[c] = new float[m_blockSize]; | 444 data[c] = new float[m_blockSize]; |
442 } | 445 } |
446 | |
447 struct LifespanMgr { // unintrusive hack introduced to ensure | |
448 // destruction on exceptions | |
449 AudioFileReader *m_r; | |
450 int m_c; | |
451 float **m_d; | |
452 LifespanMgr(AudioFileReader *r, int c, float **d) : | |
453 m_r(r), m_c(c), m_d(d) { } | |
454 ~LifespanMgr() { destroy(); } | |
455 void destroy() { | |
456 if (!m_r) return; | |
457 delete m_r; | |
458 for (int i = 0; i < m_c; ++i) delete[] m_d[i]; | |
459 delete[] m_d; | |
460 m_r = 0; | |
461 } | |
462 }; | |
463 LifespanMgr lifemgr(reader, m_channels, data); | |
443 | 464 |
444 size_t frameCount = reader->getFrameCount(); | 465 size_t frameCount = reader->getFrameCount(); |
445 | 466 |
446 // cerr << "file has " << frameCount << " frames" << endl; | 467 // cerr << "file has " << frameCount << " frames" << endl; |
447 | 468 |
591 if (progress > pp) extractionProgress.setProgress(progress); | 612 if (progress > pp) extractionProgress.setProgress(progress); |
592 } | 613 } |
593 | 614 |
594 // std::cerr << "FeatureExtractionManager: deleting audio file reader" << std::endl; | 615 // std::cerr << "FeatureExtractionManager: deleting audio file reader" << std::endl; |
595 | 616 |
596 delete reader; | 617 lifemgr.destroy(); // deletes reader, data |
597 | 618 |
598 for (PluginMap::iterator pi = m_plugins.begin(); | 619 for (PluginMap::iterator pi = m_plugins.begin(); |
599 pi != m_plugins.end(); ++pi) { | 620 pi != m_plugins.end(); ++pi) { |
600 | 621 |
601 Plugin *plugin = pi->first; | 622 Plugin *plugin = pi->first; |
720 Transform::summaryTypeToString(summaryType).toStdString()); | 741 Transform::summaryTypeToString(summaryType).toStdString()); |
721 } | 742 } |
722 } | 743 } |
723 } | 744 } |
724 | 745 |
746 void FeatureExtractionManager::testOutputFiles(QString audioSource) | |
747 { | |
748 for (PluginMap::iterator pi = m_plugins.begin(); | |
749 pi != m_plugins.end(); ++pi) { | |
750 | |
751 for (TransformWriterMap::iterator ti = pi->second.begin(); | |
752 ti != pi->second.end(); ++ti) { | |
753 | |
754 vector<FeatureWriter *> &writers = ti->second; | |
755 | |
756 for (int i = 0; i < (int)writers.size(); ++i) { | |
757 writers[i]->testOutputFile(audioSource, ti->first.getIdentifier()); | |
758 } | |
759 } | |
760 } | |
761 } | |
762 | |
725 void FeatureExtractionManager::finish() | 763 void FeatureExtractionManager::finish() |
726 { | 764 { |
727 for (PluginMap::iterator pi = m_plugins.begin(); | 765 for (PluginMap::iterator pi = m_plugins.begin(); |
728 pi != m_plugins.end(); ++pi) { | 766 pi != m_plugins.end(); ++pi) { |
729 | 767 |