Tonejs / Tone.js

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

First Tone.Player looped sample not reliably triggering (browser dependent) #893

Closed cantonbecker closed 3 years ago

cantonbecker commented 3 years ago

I wonder if anyone has advice on how to make my Tone.js composition a little more reliable:

https://pisongs.com/techno/

After the samples load and the play button is revealed, click the play button. After a few seconds -- when the digit "1" lights up in the "3.14" tickertape) you should hear a bell rhythm and a banging beat, generated by:

// this is the banging beat
Tone.Transport.schedule(function(time){ loopDronePlayer500.start(3.8095238095238 + loopOffset); }, 3.8095238095238 + loopOffset);

// this is the bell rhythm
Tone.Transport.schedule(function(time){ loopPlayer497.start(0 + loopOffset); }, 0 + loopOffset);

The way I've solved this in the past is by detecting the browser and adding extra silence at the beginning of the whole song, sometimes up to 6 seconds. But I wonder if there's something fundamentally wrong about how I'm invoking the Tone.js audio engine or something.

If you view source on the page, 100% of the javascript is right there in the html file. Nothing is external other than Tone.js, which makes it pretty easy to examine/debug.

Thanks for any tips!

tambien commented 3 years ago

Please post questions to the forums and not the issues page.

My guess by glancing at your snippets: the timing issue is related to not using the transport time in the callback function. Make sure you pass the time given by Transport.schedule in when scheduling your samples.