WebAssembly support

Hi there,

I wanted to raise attention to a topic I’ve started working on - getting scsynth to compile with emscripten, targetting wasm (WebAssembly). Since my C(++) skills are very small, I won’t be able to do this by myself, so I’m looking for people who are more proficient here. What I managed so far, is make a branch off current HEAD and see how far I get. This is the status:

Basically, as far as I can see, emscripten pthread support might actually be good enough, we just have to patch some unsupported holes like getting and setting thread priority, and then the main work is to add another Audio API back-end for OpenAL (which seems to be the API supported by emscripten). While it might also be possible to bypass that and target WebAudio API directly (not sure). Edit: Or, as Claude mentions in the ticket from experience with PD and wasm, one might look at the SDL2 port in emscripten.

With QT and libsndfile disabled, I think there is few other things that would need to be worked on apart from this audio API bridge.

(I have no idea yet, how OSC would work from a presumed client running on the JavaScript side)

4 Likes

Appetizer :slight_smile:

7 Likes

This is amazing! please keep going with this great work.

Well, it’s working now (minus libsndfile support):

https://www.sciss.de/temp/scsynth.wasm/ (currently needs Chrome/Chromium)

Happy New Year 2021 SuperCollider :fireworks:

6 Likes

Thank you for sharing this, it works beautifully here!
How does the client development look like?

Happy new year to you too!!

3 Likes

Hey,

I have slightly refactored the client interface to be more symmetric (just pushed). Basically you have a global JS object Module.oscDriver which is just a dictionary from virtual port numbers to OSC “end points”. And end point is again a JS object which responds to receive with a function(addr, data); addr is the sender’s virtual port number (in case one wants to reply), and data is the raw OSC packet in a Uint8Array. If you are writing in JavaScript, you can use the osc.js library that I included, but of course you can use any other library that can encode/decode from Uint8Array.

When the server boots, it registers such an endpoint (default port 57110), so you can send it a packet using Module.oscDriver[57110].receive(<your-port>, <raw-data>).

Are you having a particular client in mind?

Best, .h.h.

ScalaCollider can be used as client now: https://www.sciss.de/temp/scalacollider.js/ . Check out example('walters'), one of my favourites (credits: Tim Walters)

5 Likes

in|fibrillae is a web sound poem using scsynth.wasm.

2 Likes