Skip to content

Commit 46a99af

Browse files
Calculating correct value for when parameter for loop buffer source start method
1 parent b559985 commit 46a99af

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

v3/src/sound/webaudio/WebAudioSound.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,14 @@ Object.defineProperty(WebAudioSound.prototype, 'loop', {
353353
this.currentConfig.loop = value;
354354
if(this.isPlaying) {
355355
if(value) {
356-
var when = 0;
356+
var lastRateUpdateCurrentTime = 0;
357+
for (var i = 0; i < this.rateUpdates.length - 1; i++) {
358+
lastRateUpdateCurrentTime +=
359+
(this.rateUpdates[i + 1].time - this.rateUpdates[i].time) * this.rateUpdates[i].rate;
360+
}
361+
var lastRateUpdate = this.rateUpdates[this.rateUpdates.length - 1];
362+
var when = this.playTime + lastRateUpdate.time
363+
+ (this.duration - lastRateUpdateCurrentTime) / lastRateUpdate.rate;
357364
var offset = this.currentMarker ? this.currentMarker.start : 0;
358365
var duration = this.duration;
359366
this.loopSource = this.createBufferSource();

0 commit comments

Comments
 (0)