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)
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>).
This project seems extremely cool! I’ve been trying to figure out how I might get started making some js sketches using this webassembly scsynth setup – any ideas as to how I might get started? Ideally, I’m hoping to be able to write in sclang, a la supercolliderjs, without needing supercollider installed on the machine (e.g., in order to deploy a react app that could act like a GUI for an instrument written as one or more SynthDefs in sclang, which doesn’t seem altogether different from the in|fibrillae example here, though I’m having trouble determining whether that was written in sclang and, if so, where that sclang is located)
and one simply spawns this synthdef as a synth with id 1000.
Currently one is limited to the raw Server Command Reference | SuperCollider 3.14.0-dev Help as there is no wasm port of sclang (which probably would be solved differently^^ - but I have a PR adding websockets to sclang, which would at least allow to control scsynth running in a local or remote browser).
The raw byte code of a SynthDef can be embedded into the site as well, so embedding a static patch and control it via sliders is indeed possible.