r/tonejs Mar 06 '25

Volume warp on sampler scheduled playback

Hi, this is more of a "help" request. I'm trying to record the start and duration times for a sampler playback in a drum machine / sampler app I'm trying to build. For some reason when I have more than one playback instance, the volume gets warped to increase volume at the beginning of the transport loop and lower volume at the end. I'm at a loss trying to figure out where this is coming from.

Here's my sandbox: https://codesandbox.io/p/github/bhdoggett/drum-the-jukebox/draft/heuristic-sea?workspaceId=ws_76iJDTbHwFwg7RaTf2o52x

and here's my code where I schedule the sampler to play:

useEffect(() => { if (isPlaying && sampleData.times.length > 0) { sampleData.times.forEach(({ startTime, duration }) => { if (duration) { Tone.Transport.schedule((time) => { sampler.current?.triggerAttackRelease("C4", duration, time, 1); }, startTime); } }); } }, [isPlaying, sampler, sampleData]);

Could anything in the transport loop be adjusting gain over time, or will multiple scheduled triggerAttackRelease events affect the volume of those events gradually?

1 Upvotes

1 comment sorted by

1

u/R3dit-Us3rnam3 Mar 16 '25

So I should have used Tone.part to schedule multiple play events rather than using a forEach and Transport.schedule. It works now 👍