Home

Faust and the Web Audio API

Print
Published Date

The Web Audio API specification describes a high-level JavaScript API for processing and synthesizing audio in web applications. The primary paradigm is of an audio routing graph, where a number of AudioNode objects are connected together to define the overall audio rendering. The actual processing will primarily take place in the underlying implementation (typically optimized Assembly / C / C++ code), but direct JavaScript processing and synthesis is also supported.

The Faust2 branch has been updated with a new JavaScript backend that allows to generate code to be used in this context. New architecture files have been developed to embed this generated code and do Faust audio processing directly in a browser.

Use the following command to generate the JavaScript code :

faust -lang js foo.dsp

The new webaudio.js architecture file can be used to produce JavaScriptAudioNodes from Faust dsp.  For instance :

faust -lang js -a webaudio.js freeverb.dsp -o freeverb.js 

will produce a JavaScriptAudioNode freeverb. Note that each file will define a create_FOO constructor to be used to create the corresponding audio node, like for instance:  new create_freeverb(context, ui, meta, buffer_size); to create a freeverb audio node. The constructor expects:  the audio context, a UI builder and a Meta builder (see their abstract definition in faustui.js) and the buffer size. You can use :

make jsaudio

target in examples folder to compile all JavaScriptAudioNodes from Faust dsp. Web Audio API html pages can be generated to embed each Faust process. Run :

make webaudio

in examples folder to compile all html pages from Faust dsp.

The tool faust2webaudio can also be used to compile a Web Audio API html page from .dsp files, like :

faust2webaudio freeverb.dsp

Faust audio nodes then can also be "combined" directly using the WebAudio API, as demonstrated in webaudio-loader.html architecture file, where a karplus effect is sent in a freeverb.

We have tested with Safari and Chrome an OSX. Note that you'll need a development version of Safari available here. Note also that Chrome JavaScript implementation is *much faster* then Safari/Webkit one. Use Chrome for any "decent" performance. 

Because WebAudio API still does not have access to audio inputs, we just allow the user to load a sound file to be processed by the Faust effects (see the Soundfile button at the bottom of the generated page, the loaded file is supposed to be located in the same folder of the html web page)

Note that Chrome cannot access local files for some obscure security reason, so you'll have to open it with the --allow-file-access-from-files parameter, like the following on OSX:

open "/Applications/Google Chrome.app" --args --allow-file-access-from-files

An online example of Karplus can be tested here.

Known issues: 
- noise and osc generators still do not work correctly.
- implemented UI elements are : sliders, (but all will be displayed horizontally) buttons and num entries.
- layout is currently quite basic.

Buy cheap web hosting service where fatcow web hosting review will give you advices and please read bluehost review for more hosting information.
Copyright GRAME 2011 - Powered by Joomla!
Free Joomla Templates designed by Web Hosting Top