Tonejs / Tone.js

A Web Audio framework for making interactive music in the browser.
https://tonejs.github.io
MIT License
13.4k stars 976 forks source link

AudioContext.currentTime stops incrementing #1028

Closed natepmay closed 2 years ago

natepmay commented 2 years ago

My web app makes an FMSynth named synth globally, then defines a sequence globally like this:

const seq = new Tone.Sequence((time, note) => {
  synth.triggerAttackRelease(note, 0.5, time);
}, makeMidiArray(["C","E","G","B"]));

(The function makeMidiArray just chooses octaves for pitches and turns them into Tone.Midi events and doesn't seem to be the problem).

The user plays single notes using triggerAttackRelease() with the transport stopped, as well as playing sequences using this function:

function playChord(midiArray){
  seq.set({
      loop: false,
      events: midiArray
  });
  let now = Tone.now();
  Tone.Transport.stop(now);
  seq.start(0).stop(2);
  Tone.Transport.start(now).stop(now + 2);
}

Occasionally, users have reported that the app freezes up, and when I finally was able to reproduce the error and debug I noticed that the currentTime of the AudioContext had stopped incrementing at 63.328. Running Tone.start() in the console returned a promise that was "resolved" instead of "fulfilled" as it is when the app is working.

The error seems to be mostly or only happening on iOs but it's really hard to tell because it's so inconsistent. Any idea why the time stops incrementing?

Note: I'm noticing now that I should call Tone.now() twice—once for stopping and then again for starting. Could that be what's freezing up the whole app?

tambien commented 2 years ago

Hi @natepmay. The code you provided looks fine to me and running similar code for me does not produce that issue.

AudioContext.currentTime is native to the Web Audio API so might not be a Tone.js issue. If it's happening on iOS only sounds like it might be specific to that platform. Is it possible that there are maybe too many things running on the page and the browser is running out of processing resources?

If it's possible to reproduce the issue then i can try to look further into it

natepmay commented 2 years ago

@tambien thanks so much for taking a look and testing it out. I feel better hearing you say there's nothing weird in the code itself. I'll keep trying to catch the problem red-handed and seeing if browser resources may be the issue. I'll also be interested to see if anyone else finds this thread and reports a similar problem. Since the problem seems to be with the Web Audio API feel free to close out the issue.