cpal icon indicating copy to clipboard operation
cpal copied to clipboard

AudioWorklet based Host for web when Wasm atomics are enabled

Open kettle11 opened this issue 10 months ago • 0 comments

This pull request adds an optional feature-flagged Host that uses AudioWorklet on web when the atomics feature is enabled. When the web_audio_worklet and wasm-bindgen features are enabled and nightly Rust is compiled with the atomics flag enabled the WebAudioWorklet Host is available.

AudioWorklet should be lower latency, lower overhead, and less prone to jank. This implementations works pretty much the same as a native audio thread, allowing the implementation to be simpler than the existing WebAudio Host implementation.

To used shared memory it's also required (for security reasons) that the server hosting the Wasm to be configured with the correct CORS headers. I've added an example that shows how to build with the correct Rust flags and how to set the Cors headers in a test environment.

So far I've tested this in Chrome, Safari, and Firefox with the beep example and it seems to be working fine.

Edit: I'm not sure why a past merged PR shows up in Github's listed commits, but it seems to have no impact on this PR.

kettle11 avatar Mar 01 '25 19:03 kettle11