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:
When playing with the position of the transport and calling .start() without arguments: https://codesandbox.io/s/tonejs-bug-manual-update-of-position-qubmqp.
Try to alternate between start/pause/restart multiple times and notice that sometimes the volume increases and decreases.
It doesn't happen 100% of the times but it should still be fairly easy to reproduce after trying multiple times. Try to refresh the codesandbox if you can't reproduce it. Make sure to also refresh the codesandbox preview manually after each edit of the code as the auto update of the preview also plays the player twice (but this is not the issue here).
I managed to find a workaround by making sure to pause the transport before updating its position: see that here the issue does not happen https://codesandbox.io/s/tonejs-bug-manual-update-of-position-fix-fpxfo5
When the transport is in loop mode and the transport restarts the loop: https://codesandbox.io/s/tonejs-bug-loop-24e67o
Click "Start loop" and pay attention to the volume, wait for the loop to restart at 10s and notice how the volume increases after the loop as restarted.
I can't find a workaround for that one unfortunately.
Expected behavior
In both cases the player never plays twice the same sound at a time and the volume remains stable.
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
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:
When playing with the position of the transport and calling .start() without arguments: https://codesandbox.io/s/tonejs-bug-manual-update-of-position-qubmqp. Try to alternate between start/pause/restart multiple times and notice that sometimes the volume increases and decreases. It doesn't happen 100% of the times but it should still be fairly easy to reproduce after trying multiple times. Try to refresh the codesandbox if you can't reproduce it. Make sure to also refresh the codesandbox preview manually after each edit of the code as the auto update of the preview also plays the player twice (but this is not the issue here). I managed to find a workaround by making sure to pause the transport before updating its position: see that here the issue does not happen https://codesandbox.io/s/tonejs-bug-manual-update-of-position-fix-fpxfo5
When the transport is in loop mode and the transport restarts the loop: https://codesandbox.io/s/tonejs-bug-loop-24e67o Click "Start loop" and pay attention to the volume, wait for the loop to restart at 10s and notice how the volume increases after the loop as restarted. I can't find a workaround for that one unfortunately.
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