Fix the case when multiple loops occur in one buffer

This commit is contained in:
Jean Pierre Cimalando 2020-09-29 03:20:02 +02:00
parent 4d20f7722a
commit d6e8d547e4

View file

@ -549,12 +549,12 @@ void sfz::Voice::fillWithData(AudioSpan<float> buffer) noexcept
if (region->shouldLoop() && region->loopEnd(currentPromise->oversamplingFactor) <= source.getNumFrames()) { if (region->shouldLoop() && region->loopEnd(currentPromise->oversamplingFactor) <= source.getNumFrames()) {
const auto loopEnd = static_cast<int>(region->loopEnd(currentPromise->oversamplingFactor)); const auto loopEnd = static_cast<int>(region->loopEnd(currentPromise->oversamplingFactor));
const auto offset = loopEnd - static_cast<int>(region->loopStart(currentPromise->oversamplingFactor)) + 1; const auto loopStart = static_cast<int>(region->loopStart(currentPromise->oversamplingFactor));
for (auto* index = indices->begin(); index < indices->end(); ++index) { const auto loopSize = loopEnd + 1 - loopStart;
if (*index > loopEnd) { for (auto* it = indices->begin(), *end = indices->end(); it < end; ++it) {
const auto remainingElements = static_cast<size_t>(std::distance(index, indices->end())); auto index = *it;
subtract1<int>(offset, { index, remainingElements }); *it = (index < loopEnd + 1) ? index :
} (loopStart + (index - loopStart) % loopSize);
} }
} else { } else {
const auto sampleEnd = min( const auto sampleEnd = min(