Tone.js
Tone.js copied to clipboard
Setting Player.playbackRate makes the Tone Transport out of sync
Describe the bug
So, I was using the latest version 14.7.77 and I noticed that setting Tone.Transport.seconds after changing player.playbackRate is not going to the correct position. The audio also seems to end earlier then it should. I downgraded to 14.7.39, which is the version I was using in one of my other projects, and it started working perfectly again. So, I think that you might have changed something with the playbackRate in a newer version.
To Reproduce
const duration = () => {
const duration = player.buffer.duration / player.playbackRate
dispatch({type: "duration", value: duration})
return duration
}
const speed = async (event: React.ChangeEvent<HTMLInputElement>) => {
const speed = Number(event.target.value)
dispatch({type: "speed", value: speed})
player.playbackRate = speed
let percent = Tone.Transport.seconds / state.duration
const newDuration = duration()
/*Out of time on 14.7.77*/
Tone.Transport.seconds = percent * newDuration
}
Expected behavior
Setting Tone.Transport.seconds maintains the correct position.
Additional context N/A
Thanks for the issue! probably related to this commit. When i have a minute, i'll try to figure out how to roll this commit back without re-introducing the issue i was fixing when i made that change (#721)...
I checked #721, and I think the 'multiplying line' was introduced because of this issue: #375.
I was making a playbackRate-adjustable player, arrived to these issues, and was trying to figure out why the #375 fix vanished in the newest release.
Hi, I'm still interested in seeing this bug get fixed as modifying the audio playbackRate is crucial for me.
Honestly, I think that having this one fixed is more important than #721, so if you can't find a fix for both of them I would just roll back the change and reopen #721 until you find an alternative fix for that.