Skip to content

Commit

Permalink
fix: loop loop
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsek committed Dec 11, 2024
1 parent c20520a commit a31881a
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ void AudioBufferSourceNode::processNode(AudioBus *processingBus, int framesToPro
return;
}

// // Wrap to the start of the loop if necessary
// if (loop_ && vReadIndex_ >= vFrameEnd) {
// vReadIndex_ = vFrameStart + std::fmod(vReadIndex_ - vFrameStart, vFrameDelta);
// }

if (std::fabs(playbackRate) == 1.0) {
processWithoutInterpolation(processingBus, startOffset, offsetLength, playbackRate);
} else {
Expand Down Expand Up @@ -123,6 +118,10 @@ void AudioBufferSourceNode::processWithoutInterpolation(

size_t framesLeft = offsetLength;

if (loop_ && readIndex >= frameEnd) {
readIndex = frameStart + (readIndex - frameStart) % frameDelta;
}

while (framesLeft > 0) {
size_t framesToEnd = frameEnd - readIndex;
size_t framesToCopy = std::min(framesToEnd, framesLeft);
Expand Down Expand Up @@ -178,6 +177,11 @@ void AudioBufferSourceNode::processWithInterpolation(

size_t framesLeft = offsetLength;

// Wrap to the start of the loop if necessary
if (loop_ && vReadIndex_ >= vFrameEnd) {
vReadIndex_ = vFrameStart + std::fmod(vReadIndex_ - vFrameStart, vFrameDelta);
}

while (framesLeft > 0) {
size_t readIndex = static_cast<size_t>(vReadIndex_);
size_t nextReadIndex = readIndex + 1;
Expand Down

0 comments on commit a31881a

Please sign in to comment.