strudel
strudel copied to clipboard
superdough doesn't always play a sound when deadline is 0 (+ potential fix)
I'm trying use superdough for triggering on-shot synth sounds, e.g.
superdough({ note: "g1", s: "sawtooth", cutoff: 600 }, 0, 0.125);
(BTW, thanks for extracting this abstraction! It is a sweet way to play basic synths, as compared to WebAudios APIs)
However, the sound doesn't always play. The issue has to do with this check, because that's the log message I see on the console
if (ac.currentTime > t) {
logger('[webaudio] skip hap: still loading', ac.currentTime - t);
return;
}
I think what is happening is that that there is an await on the codepath
- We set
let t = ac.currentTime + deadline - There is an await
const soundHandle = await onTrigger(t, value, onended) - And then we do the check
if (ac.currentTime > t)
My guess is that ac.currentTime could (and does) potentially advance in between steps 1 and 3, causing the early return.
I think the fix for this would be to include an additional check, say
if (ac.currentTime > t && deadline !== 0) {
logger('[webaudio] skip hap: still loading', ac.currentTime - t);
...
But I'm not sure if that'll cause other downstream assumptions to fail.