Debian Codegraph @

.cargo/vendor/wasm-bindgen/guide/src/examples/wasm-audio-worklet.md

raw
1 # Wasm audio worklet
2
3 [View full source code][code] or [view the compiled example online][online]
4
5 [online]: https://wasm-bindgen.netlify.app/exbuild/wasm-audio-worklet/
6 [code]: https://github.com/rustwasm/wasm-bindgen/tree/master/examples/wasm-audio-worklet
7
8 This is an example of using threads inside specific worklets with WebAssembly,
9 Rust, and `wasm-bindgen`, culminating in an oscillator demo. This demo should
10 complement the [parallel-raytrace][parallel-raytrace] example by
11 demonstrating an alternative approach using ES modules with on-the-fly module
12 creation.
13
14 [parallel-raytrace]: https://rustwasm.github.io/docs/wasm-bindgen/examples/raytrace.html
15
16 ### Building the demo
17
18 One of the major gotchas with threaded WebAssembly is that Rust does not ship a
19 precompiled target (e.g. standard library) which has threading support enabled.
20 This means that you'll need to recompile the standard library with the
21 appropriate rustc flags, namely
22 `-C target-feature=+atomics,+bulk-memory,+mutable-globals`.
23 Note that this requires a nightly Rust toolchain. See the [more detailed
24 instructions][build] of the parallel-raytrace example.
25
26 [build]: https://rustwasm.github.io/docs/wasm-bindgen/examples/raytrace.html#building-the-demo
27
28 ### Caveats
29
30 This example shares most of its [caveats][caveats] with the parallel-raytrace
31 example. However, it tries to encapsulate worklet creation in a Rust module, so
32 the application developer does not need to maintain custom JS code.
33
34 [caveats]: https://rustwasm.github.io/docs/wasm-bindgen/examples/raytrace.html#caveats
35
36 ### Browser Requirements
37
38 This demo should work in the latest Chrome and Safari versions at this time.
39 Firefox [does not support][firefox-worklet-import] imports in worklet modules,
40 which are difficult to avoid in this example, as `importScripts` is unavailable
41 in worklets. Note that this example requires HTTP headers to be set like in
42 [parallel-raytrace][headers].
43
44 [firefox-worklet-import]: https://bugzilla.mozilla.org/show_bug.cgi?id=1572644
45 [headers]: https://rustwasm.github.io/docs/wasm-bindgen/examples/raytrace.html#browser-requirements