comparison runner/FeatureExtractionManager.cpp @ 21:9a4e410bda7a

* Add --force option, and throw/catch exceptions for failure cases rather than exiting directly
author Chris Cannam
date Tue, 07 Jul 2009 10:34:27 +0000
parents bd1deebe1129
children 4ab7c925f7ac
comparison
equal deleted inserted replaced
20:7d87bf308509 21:9a4e410bda7a
19 #include <vamp-hostsdk/PluginBufferingAdapter.h> 19 #include <vamp-hostsdk/PluginBufferingAdapter.h>
20 #include <vamp-hostsdk/PluginInputDomainAdapter.h> 20 #include <vamp-hostsdk/PluginInputDomainAdapter.h>
21 #include <vamp-hostsdk/PluginSummarisingAdapter.h> 21 #include <vamp-hostsdk/PluginSummarisingAdapter.h>
22 #include <vamp-hostsdk/PluginWrapper.h> 22 #include <vamp-hostsdk/PluginWrapper.h>
23 #include <vamp-hostsdk/PluginLoader.h> 23 #include <vamp-hostsdk/PluginLoader.h>
24
25 #include "base/Exceptions.h"
24 26
25 #include <iostream> 27 #include <iostream>
26 28
27 using namespace std; 29 using namespace std;
28 30
371 373
372 FileSource source(audioSource, &retrievalProgress); 374 FileSource source(audioSource, &retrievalProgress);
373 if (!source.isAvailable()) { 375 if (!source.isAvailable()) {
374 cerr << "ERROR: File or URL \"" << audioSource.toStdString() 376 cerr << "ERROR: File or URL \"" << audioSource.toStdString()
375 << "\" could not be located" << endl; 377 << "\" could not be located" << endl;
376 exit(1); 378 throw FileNotFound(audioSource);
377 } 379 }
378 380
379 source.waitForData(); 381 source.waitForData();
380 382
381 if (QFileInfo(audioSource).suffix().toLower() == "m3u") { 383 if (QFileInfo(audioSource).suffix().toLower() == "m3u") {
387 } 389 }
388 return; 390 return;
389 } else { 391 } else {
390 cerr << "ERROR: Playlist \"" << audioSource.toStdString() 392 cerr << "ERROR: Playlist \"" << audioSource.toStdString()
391 << "\" could not be opened" << endl; 393 << "\" could not be opened" << endl;
392 exit(1); 394 throw FileNotFound(audioSource);
393 } 395 }
394 } 396 }
395 397
396 if (m_sampleRate == 0) { 398 if (m_sampleRate == 0) {
397 cerr << "ERROR: Internal error in FeatureExtractionManager::extractFeatures: Plugin list is non-empty, but no sample rate set" << endl; 399 cerr << "ERROR: Internal error in FeatureExtractionManager::extractFeatures: Plugin list is non-empty, but no sample rate set" << endl;
400 402
401 AudioFileReader *reader = 403 AudioFileReader *reader =
402 AudioFileReaderFactory::createReader(source, m_sampleRate, &retrievalProgress); 404 AudioFileReaderFactory::createReader(source, m_sampleRate, &retrievalProgress);
403 405
404 if (!reader) { 406 if (!reader) {
405 cerr << "ERROR: File or URL \"" << audioSource.toStdString() 407 throw FailedToOpenFile(audioSource);
406 << "\" could not be opened" << endl;
407 exit(1);
408 } 408 }
409 409
410 size_t channels = reader->getChannelCount(); 410 size_t channels = reader->getChannelCount();
411 411
412 retrievalProgress.done(); 412 retrievalProgress.done();
413 413
414 cerr << "Opened " << channels << "-channel file or URL \"" << audioSource.toStdString() << "\"" << endl; 414 cerr << "Opened " << channels << "-channel file or URL \"" << audioSource.toStdString() << "\"" << endl;
415 415
416 // reject file if it has too few channels, plugin will handle if it has too many 416 // reject file if it has too few channels, plugin will handle if it has too many
417 if ((int)channels < m_channels) { 417 if ((int)channels < m_channels) {
418 //!!! should not be terminating here! 418 throw FileOperationFailed
419 cerr << "ERROR: File or URL \"" << audioSource.toStdString() << "\" has less than " << m_channels << " channels" << endl; 419 (audioSource,
420 exit(1); 420 QString("read sufficient channels (found %1, require %2)")
421 .arg(channels).arg(m_channels));
421 } 422 }
422 423
423 // allocate audio buffers 424 // allocate audio buffers
424 float **data = new float *[m_channels]; 425 float **data = new float *[m_channels];
425 for (int c = 0; c < m_channels; ++c) { 426 for (int c = 0; c < m_channels; ++c) {