nuchi / faust2cpp2wasm

Faust to wasm via the C++ backend

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Faust to C++ to wasm

A drop in replacement for the wasm file generated by faust2wasm, but with Faust's C++ backend instead of its wasm backend.

See this issue for more details and motivation.

Usage:

PATH="/path/to/wasi-sdk/bin:$PATH" ./faust2cpp2wasm mydsp.dsp -o mydsp.wasm

The generated wasm file can be used in place of the output generated by faust2wasm -worklet.

Requires the wasi-sdk and binaryen to be in your PATH.

Why?

Faust's wasm backend doesn't include implementations of math operations such as pow/sin/cos/tan/exp/log, so the browser's JS implementations are imported. This introduces quite a bit of runtime overhead. I have a dsp module which calls pow 800 times per sample. This is still fine on my machine in Firefox, which has fast wasm-to-js calls, and the module runs at 3.5x realtime. In Chrome, however, where wasm-to-js calls are slower, the same module runs at about 0.7x realtime, which means it's unusable. In Safari it also runs at around 0.7x realtime, also unusable.

The wasi sdk has native implementations of the math operators. When I compile the same module with faust2cpp2wasm, it runs at 14x and 20x realtime in Firefox and Chrome respectively. In Safari it runs at 3x realtime. Not only is that a huge speedup, with 4-, 28-, and 4-fold reduction in time, respectively, in Chrome and Safari in particular it makes the difference between my module being usable at all and not.

To-do

  • I haven't added support for buttons/checkboxes yet.
  • I haven't included support for polyphony.

About

Faust to wasm via the C++ backend


Languages

Language:C 75.9%Language:C++ 20.1%Language:Shell 4.0%