Merge pull request #462 from jpcima/loopfix

Fix the case when multiple loops occur in one buffer
This commit is contained in:
JP Cimalando 2020-09-29 11:24:50 +02:00 committed by GitHub
commit a1dd0fe578
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View file

@ -139,6 +139,20 @@ constexpr T clamp(T v, T lo, T hi)
return max(min(v, hi), lo); return max(min(v, hi), lo);
} }
/**
* @brief Compute the floating-point remainder (fmod)
*
* @tparam T
* @param x
* @param m
* @return T
*/
template <class T>
inline constexpr T fastFmod(T x, T m)
{
return x - m * static_cast<int>(x / m);
}
template <int Increment = 1, class T> template <int Increment = 1, class T>
inline CXX14_CONSTEXPR void incrementAll(T& only) inline CXX14_CONSTEXPR void incrementAll(T& only)
{ {

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(