strudel icon indicating copy to clipboard operation
strudel copied to clipboard

superdough doesn't always play a sound when deadline is 0 (+ potential fix)

Open mnvr opened this issue 1 year ago • 0 comments

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

  1. We set let t = ac.currentTime + deadline
  2. There is an await const soundHandle = await onTrigger(t, value, onended)
  3. 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.

mnvr avatar Jan 19 '24 09:01 mnvr