ircam-ismm / node-web-audio-api

Web Audio API for Node.js
BSD 3-Clause "New" or "Revised" License
91 stars 11 forks source link

`AudioWorklet` improvements #127

Open b-ma opened 1 month ago

b-ma commented 1 month ago

Remaining todos and ideas following #124

orottier commented 1 month ago

I added some more todos following the discussion over at https://app.slack.com/client/T04PVA27V/CGS5YDU0J

orottier commented 1 month ago

Ensure we run run_audio_worklet_global_scope and setImmediate only once per render quantum

I would rather not add something to the base lib to facilitate this. Instead, we could just add an unconnect custom AudioWorkletNode of our own in de the node lib to each AudioContext. It won't affect audio processing, and will tick exactly once per render quantum. This we can use to yield to V8.

b-ma commented 1 month ago

I understand your point, but can we be sure it will be called last? I'm a bit unsure of the graph sorting rules but I think in particular if we have a second user defined unconnected worklet, we might end up in a situation where the graph needs to wait for the JS tick to end, no? (that may be no huge deal and certainly better than the current situation in any case)

orottier commented 1 month ago

Yes indeed, we cannot guarantee it is called before or after the audio destination node. (unless we connect the destination node to the canary node - perhaps not a bad idea although the end user could theoretically disconnect them)

I agree that ideally these two operations run concurrently in their respective threads

But I think that is something to look into later. In any case we go from many event loop spins to 1 per render quantum, which is beneficial always.

Let me whip up some code and we can discuss further :)

b-ma commented 1 month ago

Hehe, yup let's go :)