petersalomonsen / javascriptmusic

A.K.A. WebAssembly Music. Live coding music and synthesis in Javascript / AssemblyScript (WebAssembly)
https://petersalomonsen.com
GNU General Public License v3.0
382 stars 32 forks source link

new related project #58

Closed maks closed 3 years ago

maks commented 3 years ago

Hi @petersalomonsen just wanted to first say a big thank you for your awesome work on this project.

I was especially impressed with the asssemblyscript based synth work you have been doing, so was hoping to incorporate it in part in a project I'm working on for a RPI based "groovebox" connected to a dedicated midi controller (Akai Fire initially).

As I've been building my project with Dart, I started an initial prototyping project to see if I could even make this work reasonably so I wanted to let you know I've got a little bit of the way now.

I've looked a little bit through the repo heree, but f you would have an pointers on how I could setup compiling your AS synth code that would be most appreciated.

Also I couldn't see which license you are using for your AS code such as https://github.com/petersalomonsen/javascriptmusic/blob/master/wasmaudioworklet/synth1/assembly/synth/sineoscillator.class.ts ?

petersalomonsen commented 3 years ago

thanks @maks :) very nice to hear that you like the project.

webassembly synth in Raspberry PI groovebox sounds awesome ! would be fun to hear about how it evolves.

The easiest way to get the compiled version of an assemblyscript synth is actually through the web browser. There's a download button in the upper right to download the synth as a wasm file. You can also compile it from the terminal, but you need an entry file as input parameter to the compiler which would be the same as you see in the browser ( e.g. the one here: https://petersalomonsen.com/webassemblymusic/livecodev2/?gist=068e011b94f9d6e2372b0d6fa756e831 - right side is the assemblyscript file ). In case of compiling from the terminal start in this folder here: https://github.com/petersalomonsen/javascriptmusic/tree/master/wasmaudioworklet/synth1 and see the what commands to use for compiling inside package.json (scripts).

the license is GPL for now, hope that works for your project.

let me know if you need more pointers on compiling or another licens.

petersalomonsen commented 3 years ago

Also see this example from pywasm3 on playing wasm music files:

https://github.com/wasm3/pywasm3/blob/main/examples/pygame-audio3.py

maks commented 3 years ago

Brillant, thanks for the very quick reply @petersalomonsen !

And thanks for the link to the example python code, that really helps me quickly get my head around how to call into your wasm.

Thats really nice! sorry I had completely missed in your talk the mention that you can download a synth as a wasm file. This will be a great way to quickly test out your classes in "my runtime" but I'm not sure how I should handle samplerate which comes from ../environment ? the comment says:

// earlier this used to externally declared
export const SAMPLERATE: f32 = 44100;

for now that happens to match what I'm using, but later on I'd like to set it myself like the python code you linked to does - would that be a possible future change?

With the license, I don't plan to commercialise my project but I tend to use either BSD or MIT for my projects so Im not sure if they are compatable with GPL - would you be open to dual-licensing at least just your assemblyscript code for use with BSD/MIT code?

Sorry about having several topics in this one issue, I can split out into separate issues if you like?

petersalomonsen commented 3 years ago

you can set the samplerate yourself. again see the python example: https://github.com/wasm3/pywasm3/blob/main/examples/pygame-audio3.py#L61

as you can see here, when it is compiled from the web-app the environment.ts file is set to declare samplerate externally: https://github.com/petersalomonsen/javascriptmusic/blob/master/wasmaudioworklet/synth1/browsercompilerwebworker.js#L51

regarding the license, let's move that to another issue. I'll give it a thought, maybe it would be a good thing to change the license for the project.

maks commented 3 years ago

Ah thanks Peter and apologies, I just read that comment and didn't look at the actual code and wasm export, I think I can see how it works now. And thanks again for the link to the python example, it really helps to have that to refer to 👍🏻

maks commented 3 years ago

Hi @petersalomonsen just wanted to let you know I had a bit more time to work on this today and while I ran into some roadblocks due to the Dart Wasm support being so new (not even offically published yet) I did at least manage to get to a small milestone of being able to compile your sine oscillator to assemblycode, run the resulting wasm from Dart and then playback the resulting samples also from Dart (again using a FFI binding from Dart to the libao library) on Linux.

I've got the test repo here: https://github.com/maks/dart_synth though for now I have only included the compiled wasm file in that repo as all I did was compile your code (sine_osc, environment, maths TS modules) within a new AS project jsut to learn how asc works.

My eventual goal plan is to work out some sort of setup like you already have in your online editor, where I can run asc to compile bit of AS code "on the fly" on a RPI, somewhat like your run.sh, though my eventual plan is to be able to set or control synth variables, midinotes, etc all from a midicontroller, though to start with I'm just going to precompile oscillators, filters, etc and try to control their parameters and send midinotes via calls to wasm functions, when my control application receives midi notes/CC's from a controller.

This is lots of fun! thanks again for making your code available and your video talks/demos, which I've found really inspirational to learn about all this for myself.

petersalomonsen commented 3 years ago

that's awesome :) very happy to hear that you find my stuff useful, and very cool to hear about your plans on the RPI. Can think of many interesting use cases with RPIs installed here and there triggered by midi events ( which is maybe triggered by some sensors )

there's a midisynth implementation here btw: https://github.com/petersalomonsen/javascriptmusic/blob/master/wasmaudioworklet/synth1/assembly/midi/midisynth.ts

it listens to note events and control changes, and handles volume, pan and reverb out of the box.

maks commented 3 years ago

Brillant, thanks again Peter! This gives me so much to go on with and lots of new ideas as I hadn't spotted that you had all this midi handling code already too. I'll close this issue now and follow on any other things I run into wih more specific issues.