Tone.js icon indicating copy to clipboard operation
Tone.js copied to clipboard

Scheduling bufferSources in 14.7.x an offline scheduleRepeat causes strange glitching.

Open 0800robin opened this issue 5 years ago • 1 comments

Hi

Bumped my prod version from 13.8.4 up to 14.7.65 due to the noted iOS14 Safari issues. However i've encountered an issue while using schedule repeat in an offline callback.

Scheduling bufferSources an offline scheduleRepeat causes strange glitching.

issue presents using 14.7.65 (tone@next) - https://jsfiddle.net/7p2nu0mc/11/ issue does not presents using 13.8.4 - https://jsfiddle.net/3d890het/1/

If i'm missing something here i can close this issue.

Thanks for your tour de force in web audio, it rocks!

0800robin avatar Nov 08 '20 21:11 0800robin

The issue is that the function handleToneTransportTick is being played in the "online" context even when you're rendering with Tone.Offline. The glitch that you're hearing is all the notes playing at once.

To fix this, you can pass in the context that you want the note to be rendered in like this:

function handleToneTransportTick(time, context) {
    let source = new Tone.BufferSource({
        url: buffer,
        context,
    }).toDestination();
    source.start(time + 0.25);
}

Here's a modified version of the fiddle that doesn't have that same problem: https://jsfiddle.net/k4t3j0wa/6/

I'm going to look into why the default context is not being set to the OfflineAudioContext while that callback is being invoked, but wanted to provide a solution in the meantime.

tambien avatar Jan 13 '21 18:01 tambien