Mercurial > hg > sonic-annotator
comparison runner/FeatureExtractionManager.cpp @ 34:76ea8ffc4dfa
* Fix mixdown for multi-channel source -> 1-channel plugin
author | Chris Cannam |
---|---|
date | Mon, 24 May 2010 15:06:30 +0000 |
parents | 8b20521fc40f |
children | 69c438d4b9d3 |
comparison
equal
deleted
inserted
replaced
33:44dc87d1059d | 34:76ea8ffc4dfa |
---|---|
427 | 427 |
428 retrievalProgress.done(); | 428 retrievalProgress.done(); |
429 | 429 |
430 cerr << "Opened " << channels << "-channel file or URL \"" << audioSource.toStdString() << "\"" << endl; | 430 cerr << "Opened " << channels << "-channel file or URL \"" << audioSource.toStdString() << "\"" << endl; |
431 | 431 |
432 // 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 |
433 if ((int)channels < m_channels) { | 433 if ((int)channels < m_channels) { |
434 delete reader; | 434 delete reader; |
435 throw FileOperationFailed | 435 throw FileOperationFailed |
436 (audioSource, | 436 (audioSource, |
437 QString("read sufficient channels (found %1, require %2)") | 437 QString("read sufficient channels (found %1, require %2)") |
572 | 572 |
573 // We have to do our own channel handling here; we can't just | 573 // We have to do our own channel handling here; we can't just |
574 // leave it to the plugin adapter because the same plugin | 574 // leave it to the plugin adapter because the same plugin |
575 // adapter may have to serve for input files with various | 575 // adapter may have to serve for input files with various |
576 // numbers of channels (so the adapter is simply configured | 576 // numbers of channels (so the adapter is simply configured |
577 // with a fixed channel count, generally 1). | 577 // with a fixed channel count). |
578 | 578 |
579 int rc = reader->getChannelCount(); | 579 int rc = reader->getChannelCount(); |
580 | 580 |
581 for (int j = 0; j < m_blockSize; ++j) { | 581 // m_channels is the number of channels we need for the plugin |
582 | |
583 int index; | |
584 int fc = (int)frames.size(); | |
585 if (m_channels == 1) { // only case in which we can sensibly mix down | |
586 for (int j = 0; j < m_blockSize; ++j) { | |
587 data[0][j] = 0.f; | |
588 } | |
589 for (int c = 0; c < rc; ++c) { | |
590 for (int j = 0; j < m_blockSize; ++j) { | |
591 index = j * rc + c; | |
592 if (index < fc) data[0][j] += frames[index]; | |
593 } | |
594 } | |
595 for (int j = 0; j < m_blockSize; ++j) { | |
596 data[0][j] /= rc; | |
597 } | |
598 } else { | |
582 for (int c = 0; c < m_channels; ++c) { | 599 for (int c = 0; c < m_channels; ++c) { |
583 int index; | 600 for (int j = 0; j < m_blockSize; ++j) { |
601 data[c][j] = 0.f; | |
602 } | |
584 if (c < rc) { | 603 if (c < rc) { |
585 index = j * rc + c; | 604 for (int j = 0; j < m_blockSize; ++j) { |
586 data[c][j] = 0.f; | 605 index = j * rc + c; |
587 } else { | 606 if (index < fc) data[c][j] += frames[index]; |
588 index = j * rc + (c % rc); | 607 } |
589 } | 608 } |
590 if (index < (int)frames.size()) { | 609 } |
591 data[c][j] += frames[index]; | 610 } |
592 } | |
593 } | |
594 } | |
595 | 611 |
596 Vamp::RealTime timestamp = Vamp::RealTime::frame2RealTime | 612 Vamp::RealTime timestamp = Vamp::RealTime::frame2RealTime |
597 (i, m_sampleRate); | 613 (i, m_sampleRate); |
598 | 614 |
599 for (PluginMap::iterator pi = m_plugins.begin(); | 615 for (PluginMap::iterator pi = m_plugins.begin(); |