Saturday, May 5, 2012

Creating DSP units using Faust

Today we tackle writing DSP code, and then compiling it into a format that is usable for your platform & workflow. That means writing the DSP code once, and compiling it for each platform as nessisary, a big time saver. To do this we have Faust: Functional AUdio STream. Its a high level domain specific programming language to write audio processing code in :)

Best bit: there's an online compiler for you to play with before any commitment! http://faust.grame.fr/index.php/online-examples

So you want to compile plugins locally? Good! Grab the faust package from your distro, it will install the compiler & some extra bits we need.

Now go to your faust programming folder, and lets get started:
touch test1.dsp
grab one of the simple examples from the Online Examples, and copy the Faust code into your .dsp file


First we need to compile from the Faust code into valid C++: that means that we needs to have access to all Faust specific things like architecture files etc. An architecture file is a "template" for building a program, JACK + console is one example. Jack & GTK is another. JACK & QT, LADSPA, LV2 etc are also all architecture examples.

Since I'm on Linux with GTK, I'm using the jack-gtk.cpp architecture file like so:
faust -a jack-gtk.cpp bitcrush.dsp -o bitcrush.cpp

Now we run the generated .cpp file trough g++, a standard C++ compiler, and provide it with the nessisary info to link the executable. Simple huh??
g++ -I/usr/lib/faust/ -lpthread `pkg-config --cflags --libs jack gtk+-2.0` bitcrush.cpp  -o bitcrush

Note: I've added an include path there so that the compiler knows what where to look for the architecture files etc, its needed! If you don't you'll get an error like so:
[munch]   fatal error: gui/FUI.h: No such file or directory

Once that's fixed by adding the relevant include paths, it should work :D
Enjoy! -Harry

No comments:

Post a Comment