Mercurial > hg > svcore
changeset 1008:d9e0e59a1581
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.)
author | Chris Cannam |
---|---|
date | Fri, 14 Nov 2014 13:51:33 +0000 (2014-11-14) |
parents | d954e03274e8 |
children | e369dd281cf2 |
files | data/model/AggregateWaveModel.cpp transform/FeatureExtractionModelTransformer.cpp |
diffstat | 2 files changed, 34 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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;