4.1 Interface to scsynth
In order to compile a Faust plugin for the SuperCollider3
synthesis architecture, you have to use the corresponding architecture file:
$ faust -a supercollider.cpp \
-o noise.cpp noise.dsp
For compiling the plugin on Linux you can use the provided pkg-config specification, which is installed automatically when you pass DEVELOPMENT=yes to scons
when building SuperCollider:
$ g++ -shared -o noise.so \
'pkg-config --cflags libscsynth' \
noise.cpp
The resulting plugin should be put in a
place where scsynth can find it, e.g. into
-/share/SuperCollider/Extensions/Faust
on Linux.
Unit-generator plugins in SuperCollider are referenced by
name on the server; the plugin generated by Faust currently
registers itself with the C++ filename sans extension. In future versions of Faust the plugin name will be definable in the
process specification itself.
4.2 Interface to sclang
Faust can produce an XML description of a plugin, including various meta data and the structural layout of the user
interface.
This information is used by faust2sc in the Faust distribution to generate a SuperCollider class file, which can be
compiled and subsequently used from within sc lang.
For example,
$ faust -xml -o /dev/null noise.dsp
$ faust -xml -o /dev/null karplus.dsp
$ faust2sc -p Faust -o Faust.sc \
noise.dsp.xml karplus.dsp.xml
generates a SuperCollider source file, that, when compiled by
sclang, makes available the respective plugins for use in synth
definitions.
Now copy the source file into sclang's search path, e.g.
-/share/SuperCollider/Extensions/Faust on
Linux.
Since scsynth doesn't provide GUI facilities, UI elements in Faust specifications are mapped to control rate signals on the synthesis server. The argument order is determined by the order of appearance in the (flattened) block diagram specification; audio inputs (named inl... inN) are
expected before control inputs. The freeverb example plugin has the following arguments to the ar instance creation
method when used from sclang:
inl in2 damp(0.5) roomsize(0.5) wet(0.3333)
i.e. first the stereo input pair followed by the control inputs
including default values.
4.3 Examples
Unsurprisingly plugins generated by Faust can be used
just like any other unit generator plugin, although the argument naming can be a bit verbose, depending on the labels
used in UI definitions.
Assuming the server has been booted, the "noise" example found in the distribution can be tested like this:
{ Pan2.ar(
FaustNoise.ar(0.2),
LFTri.kr(0.1) * 0.4)
}.play
A more elaborate example involves the "karplus" example
plugin and shows how to use keyword arguments.
FaustKarplus.ar(
play: { |il
Impulse.kr(
exprand(10/6*(i+1), 20)
* SinOsc.kr(0.1).range(0.3, 1)
}! 6,
duration_samples: LFSaw.kr(0.1).range(80, 128),
attenuation: LFPar.kr(0.055, pi/2).range(0.1, 0.4).squared,
level: 0.05
).clump(2).sum
}.play
Note that the trigger button in the jack-gkt example has
been replaced by a control rate impulse generator connected
to the play input.
Rewriting the monophonic synth example from section
3.3 in SuperCollider is a matter of recompiling the plugin,
$ faust -a supercollider.cpp \
-o synth.cpp synth.dsp
$ g++ -shared -o synth.so \
'pkg-config --cflags libscsynth' \
synth. cpp
$ faust -xml -o /dev/null synth.dsp
$ faust2sc -p Faust -o FaustSynth.sc \
synth.dsp.xml
and installing synth. so and Faust Synth. sc to the appropriate places.
The corresponding SynthDef just wraps the Faust plugin:
698