# HG changeset patch # User Chris Cannam # Date 1415973093 0 # Node ID d9e0e59a158126bc4dc57bb6673741e9c318c514 # Parent d954e03274e84ecfa1d1e6a4600e96497d5ad53d When using an aggregate model to pass data to a transform, zero-pad the shorter input to the duration of the longer rather than truncating the longer. (This is better behaviour for e.g. MATCH, and in any case the code was previously truncating incorrectly and ending up with garbage data at the end.) diff -r d954e03274e8 -r d9e0e59a1581 data/model/AggregateWaveModel.cpp --- a/data/model/AggregateWaveModel.cpp Wed Oct 15 17:02:48 2014 +0100 +++ b/data/model/AggregateWaveModel.cpp Fri Nov 14 13:51:33 2014 +0000 @@ -118,14 +118,21 @@ } } - int sz = count; - + int longest = 0; + for (int c = ch0; c <= ch1; ++c) { - int szHere = + int here = m_components[c].model->getData(m_components[c].channel, start, count, readbuf); - if (szHere < sz) sz = szHere; + if (here > longest) { + longest = here; + } + if (here < count) { + for (int i = here; i < count; ++i) { + readbuf[i] = 0.f; + } + } if (mixing) { for (int i = 0; i < count; ++i) { buffer[i] += readbuf[i]; @@ -134,7 +141,7 @@ } if (mixing) delete[] readbuf; - return sz; + return longest; } int @@ -157,14 +164,21 @@ } } - int sz = count; + int longest = 0; for (int c = ch0; c <= ch1; ++c) { - int szHere = + int here = m_components[c].model->getData(m_components[c].channel, start, count, readbuf); - if (szHere < sz) sz = szHere; + if (here > longest) { + longest = here; + } + if (here < count) { + for (int i = here; i < count; ++i) { + readbuf[i] = 0.; + } + } if (mixing) { for (int i = 0; i < count; ++i) { buffer[i] += readbuf[i]; @@ -173,7 +187,7 @@ } if (mixing) delete[] readbuf; - return sz; + return longest; } int diff -r d954e03274e8 -r d9e0e59a1581 transform/FeatureExtractionModelTransformer.cpp --- a/transform/FeatureExtractionModelTransformer.cpp Wed Oct 15 17:02:48 2014 +0100 +++ b/transform/FeatureExtractionModelTransformer.cpp Fri Nov 14 13:51:33 2014 +0000 @@ -679,11 +679,17 @@ if (frequencyDomain) { for (int ch = 0; ch < channelCount; ++ch) { int column = (blockFrame - startFrame) / stepSize; - fftModels[ch]->getValuesAt(column, reals, imaginaries); - for (int i = 0; i <= blockSize/2; ++i) { - buffers[ch][i*2] = reals[i]; - buffers[ch][i*2+1] = imaginaries[i]; - } + if (fftModels[ch]->getValuesAt(column, reals, imaginaries)) { + for (int i = 0; i <= blockSize/2; ++i) { + buffers[ch][i*2] = reals[i]; + buffers[ch][i*2+1] = imaginaries[i]; + } + } else { + for (int i = 0; i <= blockSize/2; ++i) { + buffers[ch][i*2] = 0.f; + buffers[ch][i*2+1] = 0.f; + } + } error = fftModels[ch]->getError(); if (error != "") { cerr << "FeatureExtractionModelTransformer::run: Abandoning, error is " << error << endl;