Mercurial > hg > svcore
diff plugin/transform/FeatureExtractionModelTransformer.cpp @ 363:0e30c8ec15a0
* Add wave file model method for reading more than one channel at once,
avoiding ludicrously expensive backward seeks and double-reads when
playing multi-channel files or using them as inputs to feature extraction
plugins
author | Chris Cannam |
---|---|
date | Thu, 24 Jan 2008 14:35:43 +0000 |
parents | 399ea254afd6 |
children | 4bb19132da23 |
line wrap: on
line diff
--- a/plugin/transform/FeatureExtractionModelTransformer.cpp Thu Jan 24 11:03:59 2008 +0000 +++ b/plugin/transform/FeatureExtractionModelTransformer.cpp Thu Jan 24 14:35:43 2008 +0000 @@ -385,17 +385,16 @@ // channelCount is either m_input.getModel()->channelCount or 1 - for (size_t ch = 0; ch < channelCount; ++ch) { - if (frequencyDomain) { + if (frequencyDomain) { + for (size_t ch = 0; ch < channelCount; ++ch) { int column = (blockFrame - startFrame) / stepSize; for (size_t i = 0; i <= blockSize/2; ++i) { fftModels[ch]->getValuesAt (column, i, buffers[ch][i*2], buffers[ch][i*2+1]); } - } else { - getFrames(ch, channelCount, - blockFrame, blockSize, buffers[ch]); - } + } + } else { + getFrames(channelCount, blockFrame, blockSize, buffers); } Vamp::Plugin::FeatureSet features = m_plugin->process @@ -435,15 +434,17 @@ } void -FeatureExtractionModelTransformer::getFrames(int channel, int channelCount, - long startFrame, long size, - float *buffer) +FeatureExtractionModelTransformer::getFrames(int channelCount, + long startFrame, long size, + float **buffers) { long offset = 0; if (startFrame < 0) { - for (int i = 0; i < size && startFrame + i < 0; ++i) { - buffer[i] = 0.0f; + for (int c = 0; c < channelCount; ++c) { + for (int i = 0; i < size && startFrame + i < 0; ++i) { + buffers[c][i] = 0.0f; + } } offset = -startFrame; size -= offset; @@ -453,24 +454,43 @@ DenseTimeValueModel *input = getConformingInput(); if (!input) return; + + long got = 0; - long got = input->getData - ((channelCount == 1 ? m_input.getChannel() : channel), - startFrame, size, buffer + offset); + if (channelCount == 1) { + + got = input->getData(m_input.getChannel(), startFrame, size, + buffers[0] + offset); + + if (m_input.getChannel() == -1 && input->getChannelCount() > 1) { + // use mean instead of sum, as plugin input + float cc = float(input->getChannelCount()); + for (long i = 0; i < size; ++i) { + buffers[0][i + offset] /= cc; + } + } + + } else { + + float **writebuf = buffers; + if (offset > 0) { + writebuf = new float *[channelCount]; + for (int i = 0; i < channelCount; ++i) { + writebuf[i] = buffers[i] + offset; + } + } + + got = input->getData(0, channelCount-1, startFrame, size, writebuf); + + if (writebuf != buffers) delete[] writebuf; + } while (got < size) { - buffer[offset + got] = 0.0; + for (int c = 0; c < channelCount; ++c) { + buffers[c][got + offset] = 0.0; + } ++got; } - - if (m_input.getChannel() == -1 && channelCount == 1 && - input->getChannelCount() > 1) { - // use mean instead of sum, as plugin input - int cc = input->getChannelCount(); - for (long i = 0; i < size; ++i) { - buffer[i] /= cc; - } - } } void