comparison runner/main.cpp @ 45:69c438d4b9d3

* Pick up default sample rate and channel count from first audio file (formerly they were hardcoded to 44100 and 1...)
author Chris Cannam
date Mon, 18 Oct 2010 14:17:48 +0100
parents 102bb1729184
children 4d07f61dba3f
comparison
equal deleted inserted replaced
44:aa521baace07 45:69c438d4b9d3
21 #include <QSettings> 21 #include <QSettings>
22 #include <QStringList> 22 #include <QStringList>
23 #include <QString> 23 #include <QString>
24 #include <QFileInfo> 24 #include <QFileInfo>
25 #include <QDir> 25 #include <QDir>
26 #include <QSet>
26 27
27 using std::cout; 28 using std::cout;
28 using std::cerr; 29 using std::cerr;
29 using std::endl; 30 using std::endl;
30 using std::vector; 31 using std::vector;
585 << ": failed to set requested summary types" << endl; 586 << ": failed to set requested summary types" << endl;
586 exit(1); 587 exit(1);
587 } 588 }
588 } 589 }
589 590
590 // the manager dictates the sample rate and number of channels
591 // to work at - files with too few channels are rejected,
592 // too many channels are handled as usual by the Vamp plugin
593
594 //!!! Review this: although we probably do want to fix the channel
595 // count here, we don't necessarily want to fix the rate: it's
596 // specified in the Transform file.
597
598 manager.setDefaultSampleRate(44100);
599 manager.setChannels(1);
600
601 vector<FeatureWriter *> writers; 591 vector<FeatureWriter *> writers;
602 592
603 for (set<string>::const_iterator i = requestedWriterTags.begin(); 593 for (set<string>::const_iterator i = requestedWriterTags.begin();
604 i != requestedWriterTags.end(); ++i) { 594 i != requestedWriterTags.end(); ++i) {
605 595
680 cerr << myname.toStdString() << ": failed to read template list file \"" << *i << "\"" << endl; 670 cerr << myname.toStdString() << ": failed to read template list file \"" << *i << "\"" << endl;
681 exit(2); 671 exit(2);
682 } 672 }
683 } 673 }
684 674
685 bool haveFeatureExtractor = false;
686
687 for (set<string>::const_iterator i = requestedTransformFiles.begin();
688 i != requestedTransformFiles.end(); ++i) {
689 if (manager.addFeatureExtractorFromFile(i->c_str(), writers)) {
690 haveFeatureExtractor = true;
691 }
692 }
693
694 for (set<string>::const_iterator i = requestedDefaultTransforms.begin();
695 i != requestedDefaultTransforms.end(); ++i) {
696 if (manager.addDefaultFeatureExtractor(i->c_str(), writers)) {
697 haveFeatureExtractor = true;
698 }
699 }
700
701 if (!haveFeatureExtractor) {
702 cerr << myname.toStdString() << ": no feature extractors added" << endl;
703 exit(2);
704 }
705
706 QStringList sources; 675 QStringList sources;
707 if (!recursive) { 676 if (!recursive) {
708 sources = otherArgs; 677 sources = otherArgs;
709 } else { 678 } else {
710 for (QStringList::const_iterator i = otherArgs.begin(); 679 for (QStringList::const_iterator i = otherArgs.begin();
719 } 688 }
720 } 689 }
721 } 690 }
722 691
723 bool good = true; 692 bool good = true;
693 QSet<QString> badSources;
724 694
725 for (QStringList::const_iterator i = sources.begin(); 695 for (QStringList::const_iterator i = sources.begin();
726 i != sources.end(); ++i) { 696 i != sources.end(); ++i) {
727 std::cerr << "Extracting features for: \"" << i->toStdString() << "\"" << std::endl;
728 try { 697 try {
729 manager.extractFeatures(*i); 698 manager.addSource(*i);
730 } catch (const std::exception &e) { 699 } catch (const std::exception &e) {
700 badSources.insert(*i);
731 cerr << "ERROR: Failed to process file \"" << i->toStdString() 701 cerr << "ERROR: Failed to process file \"" << i->toStdString()
732 << "\": " << e.what() << endl; 702 << "\": " << e.what() << endl;
733 cerr << "NOTE: If you want to continue with processing any further files after an" << endl
734 << "error like this, use the --force option" << endl;
735 if (force) { 703 if (force) {
736 // print a note only if we have more files to process 704 // print a note only if we have more files to process
737 QStringList::const_iterator j = i; 705 QStringList::const_iterator j = i;
738 if (++j != sources.end()) { 706 if (++j != sources.end()) {
739 cerr << "NOTE: \"--force\" option was provided, continuing (more errors may occur)" << endl; 707 cerr << "NOTE: \"--force\" option was provided, continuing (more errors may occur)" << endl;
740 } 708 }
741 } else { 709 } else {
710 cerr << "NOTE: If you want to continue with processing any further files after an" << endl
711 << "error like this, use the --force option" << endl;
742 good = false; 712 good = false;
743 break; 713 break;
714 }
715 }
716 }
717
718 if (good) {
719
720 bool haveFeatureExtractor = false;
721
722 for (set<string>::const_iterator i = requestedTransformFiles.begin();
723 i != requestedTransformFiles.end(); ++i) {
724 if (manager.addFeatureExtractorFromFile(i->c_str(), writers)) {
725 haveFeatureExtractor = true;
726 }
727 }
728
729 for (set<string>::const_iterator i = requestedDefaultTransforms.begin();
730 i != requestedDefaultTransforms.end(); ++i) {
731 if (manager.addDefaultFeatureExtractor(i->c_str(), writers)) {
732 haveFeatureExtractor = true;
733 }
734 }
735
736 if (!haveFeatureExtractor) {
737 cerr << myname.toStdString() << ": no feature extractors added" << endl;
738 good = false;
739 }
740 }
741
742 if (good) {
743 for (QStringList::const_iterator i = sources.begin();
744 i != sources.end(); ++i) {
745 if (badSources.contains(*i)) continue;
746 std::cerr << "Extracting features for: \"" << i->toStdString() << "\"" << std::endl;
747 try {
748 manager.extractFeatures(*i);
749 } catch (const std::exception &e) {
750 cerr << "ERROR: Feature extraction failed for \"" << i->toStdString()
751 << "\": " << e.what() << endl;
752 if (force) {
753 // print a note only if we have more files to process
754 QStringList::const_iterator j = i;
755 if (++j != sources.end()) {
756 cerr << "NOTE: \"--force\" option was provided, continuing (more errors may occur)" << endl;
757 }
758 } else {
759 cerr << "NOTE: If you want to continue with processing any further files after an" << endl
760 << "error like this, use the --force option" << endl;
761 good = false;
762 break;
763 }
744 } 764 }
745 } 765 }
746 } 766 }
747 767
748 for (int i = 0; i < writers.size(); ++i) delete writers[i]; 768 for (int i = 0; i < writers.size(); ++i) delete writers[i];