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);
}
/**
* @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>
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()) {
const auto loopEnd = static_cast<int>(region->loopEnd(currentPromise->oversamplingFactor));
const auto offset = loopEnd - static_cast<int>(region->loopStart(currentPromise->oversamplingFactor)) + 1;
for (auto* index = indices->begin(); index < indices->end(); ++index) {
if (*index > loopEnd) {
const auto remainingElements = static_cast<size_t>(std::distance(index, indices->end()));
subtract1<int>(offset, { index, remainingElements });
}
const auto loopStart = static_cast<int>(region->loopStart(currentPromise->oversamplingFactor));
const auto loopSize = loopEnd + 1 - loopStart;
for (auto* it = indices->begin(), *end = indices->end(); it < end; ++it) {
auto index = *it;
*it = (index < loopEnd + 1) ? index :
(loopStart + (index - loopStart) % loopSize);
}
} else {
const auto sampleEnd = min(