We are happy to publish a new and improved version of the Faust to Web Audio API development.
While faust1 version (= master branch on GIT) Emscripten SDK has to be installed before using the following scripts.
Whith faust2 development branch, a internal asm.js backend has been developed to directly generate the code starting from the DSP source. So you will be able to either generate the asm.js code using Emscripten (by adding the -emcc parameter in the following described commands), or using the internal asm.js backend.
Using DSP instances
When “faust.karplus” class is defined, instances can be created and used as regular Web Audio API nodes with the following code (assuming ‘dsp2’ is another Faust defined node):
var dsp = faust.karplus(audio_context, buffer_size); dsp.start(); dsp.scriptProcessor.connect(dsp2.scriptProcessor);
The list of all input controls can be retrieved with the following code:
var control_list = dsp.controls();
The user interface can change the value of any control using the following code, where ‘path_to_control’ denotes a complete path to the control (retrieved using ‘controls’ function), and ‘value’ the value to be changed:
The paramter value can ge read using the following code:
var value = dsp.getValue(path_to_control);
A user interface may have to be periodically updated when output controls (typically bargraphs) have changed. You can use the following code to setup a handler callback:
Where ‘update_handler’ is a function with a prototype (path_to_control, value) that will be called once at each audio cycle with output control values.
The JSON description of the DSP can be retrieved and typically parsed by the user interface builder with the following code :
var json = dsp.json();
For DSP with inputs, the client glue code would typically have to open the audio_context audio input and connect it with the node :
var audio_input = audio_context.createMediaStreamSource(device); audio_input.connect(dsp.scriptProcessor);
faust2asmjs -comb karplus.dsp freeverb.dsp zita_rev1.dsp
faust2webaudioasm -poly piano.dsp
The DSP has to be allocated and used with the following kind of code:
var dsp = faust.piano_poly(audio_context, buffer_size); dsp.start(); dsp.keyOn(channel, pitch, velocity); dsp.keyOff(channel, pitch);