Tonejs / Tone.js

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

Tone.Player in sync mode sometimes playing twice. #1098

Open slocka opened 2 years ago

slocka commented 2 years ago

Describe the bug

I am using the Tone.player synced with the Transport and I noticed that it some scenarios, the same player ends up being played twice at the same time resulting in a noticeable increase in volume of the sound played by the player. I haven't been able to pinpoint the exact condition in which this happens nor the reason but you can reproduce it in the provided codesandbox.

To Reproduce There are two scenarios in which I noticed this happening:

Expected behavior In both cases the player never plays twice the same sound at a time and the volume remains stable.

What I've tried I tried to debug the issue and noticed that the _start function of the player was sometimes called twice when I guess it should be called only once. It is sometimes called from both places: https://github.com/Tonejs/Tone.js/blob/dev/Tone/source/Source.ts#L231 and https://github.com/Tonejs/Tone.js/blob/dev/Tone/source/Source.ts#L339 at the same time. It is not always the case though, so I suspect that it's a race condition maybe related to the time of the clock.

I was hopping that it could be related to this floating point issue https://github.com/Tonejs/Tone.js/issues/999 but I tried with version 14.8.40 and the issue is still happening