Mads Kjeldgaard

Update February 2022: faust now comes with the faust2sc.py tool to make this all a lot easier. The instructions below have been updated to reflect that.

I recently started toying around with Faust. Faust is a functional programming language specifically designed for audio manipulation. One of the many strengths of Faust is it’s compiler backends that allows the user to compile Faust code to almost any end target - including microcontrollers, JUCE/VST plugin projects, Pure Data, Max and SuperCollider - with the same Faust code. It even works in the browser.

Another fantastic strength is the library of building blocks it comes with - these are extremely high quality and reflect a lot of the new developments in DSP technology and research in recent years. For you as a user this means you have a really solid toolbox for creating sound patches.

For SuperCollider users this means that Faust is probably the quickest way to create highly effective custom plugins / UGens for SuperCollider.

faust2supercollider: Creating a SuperCollider plugin using Faust

If you download and install faust on your computer(most Linux distributions probably have it in their package managers), you get a ton of compilation tools for free. These are all prefixed faust2<target>.

For SuperCollider there is a specific tool called faust2sc.py, this takes a Faust file as an input and compiles it as a SuperCollider UGen and produces a helpfile for it as well. The UGen part of it consists of two files: a compiled object and a .sc-file containing the sclang interface for it.

Let’s try a simple example. Create a file called Wah4.dsp (.dsp is the suffix for Faust-files) and put this code in it:

import("stdfaust.lib");

// Cutoff frequency argument
freq=vslider("cutoff",500,20.0,20000,1);

// Perform process on input sound
process= _: ve.wah4(freq) : _;

This imports the standard library for faust and then defines a parameter “cutoff” that we will use to control the cutoff frequency. Note that in Faust this is represented as a slider with a default value of 500 (hz), range from 20.0 to 20000.0 in steps of 1. When converting to a SuperCollider UGen, this will be interpreted as an argument for the UGen and show up as cutoff.

Now save the file and compile it to SuperCollider using the command line tool faust2sc.py:

faust2sc.py Wah4.dsp -o <targetfolder>

By specifying the you can output all of the plugin directly to your extensions folder (evaluate Platform.userExtenionDir in SuperCollider to see where that is on your system).

So for example, to output it to a folder in your extensions directory on Linux:

faust2sc.py Wah4.dsp -o ~/.local/share/SuperCollider/Extensions/MyFaustWah

Test the plugin

Now, test out your brand spanking new Wahwah-effect in a patch with a noise UGen modulating the cutoff frequency:

 
(
Ndef(\wahhhh, { |freq=150, amp=0.25| 
	var sig = Saw.ar(freq);
	var freq = LFNoise2.kr(10).exprange(25,2500);
	Wah4.ar(sig, freq) * amp;
}).play
)

That’s it. Now, all there’s left is to actually learn the faust programming language syntax, hehe.

Want more?

You can do lots of things with the faust2sc.py tool, and I recommend you run faust2sc.py --help to see all of the options.

Tags: