Compiling Faust code for Bela - BelaPlatform/Bela GitHub Wiki

The Bela Wiki has moved to learn.bela.io. This material has been superseded. Click here for the maintained version.

To be able to run Faust on Bela, you need to do some setup on your computer and on the Bela board. Faust generates some very large C++ files that may take forever (many minutes) to compile on the Bela board. It is therefore highly recommended that - before using Faust on Bela - you go through setting up distcc to get cross-builds happening, offloading the compilation task to the host computer. This is explained here. However, this step is optional and for very small Faust projects you may be fine without it.

So, here we go:

Host configuration

Pre-requisites: cmake, PkgConfig. Install them with your favourite package manager / googling skills.

On a Mac with brew installed, it would be something like:

brew install cmake PkgConfig

On Ubuntu 18.04:

sudo apt update
sudo apt install cmake pkg-config

Download Faust, build, install

git clone https://github.com/grame-cncm/faust.git &&\
cd faust &&\
make -j4 &&\
sudo make install

(note: the development of Faust proceeds at a very high pace, so occasionally things are broken. The latest known working commit is c2a6f90c50b1815e0e9d8eddcaec8640148856a4, so if you get a compilation error while building the Bela program below, try to add git checkout c2a6f90c50b1815e0e9d8eddcaec8640148856a4 before make -j4 above, and re-run the two make lines).

If you do want to set up the distcc cross-compiling environment, optional but recommended (see above), follow the instructions here.

Board configuration:

There is no compulsory step to do to prepare the board. There are two optional steps, both recommended:

  • you may want to setup distcc to speed up builds (yes it's optional, but it's the third time we recommend it, so please do it!), see notes above and follow the instructions here if you are interested.
  • install a library on the board that will allow you to interact with the Faust GUI in the browser:

Install the libraries for the Faust GUI

  • download this file, a pre-compiled version of the http library that comes with Faust
unzip libHTTPDFaust.zip
ssh [email protected] rm -rf /usr/local/lib/libHTTPDFaust.*
scp libHTTPDFaust.so.*.* libHTTPDFaust.a [email protected]:/usr/local/lib/
ssh [email protected] "cd /usr/local/lib && ldconfig && ln -s libHTTPDFaust.so.? libHTTPDFaust.so"

Install libmicrohttpd-dev on the board:

  • connect the board to the internet and run
apt-get install libmicrohttpd-dev

Usage

Great, at this point all should be done and ready to go. On the host, go into faust/examples/bela and run:

faust2bela -tobela simpleFX_Analog.dsp

this should build and run the project. (If it takes forever to build, maybe it's about time you consider setting up distcc, as "suggested" above.) Plug some signal into your Bela and you will hear it processed through drive, flanger, reverb! Bela's analog inputs will be controlling some of the parameters.

Now, if you did the optional step of installing the library for the GUI, you can repeat the above but with the -gui option:

faust2bela -tobela -gui simpleFX_Analog.dsp

Then find the GUI at http://192.168.7.2:5510 . Some of the parameters displayed are controlled by Bela's analog inputs, and cannot be modified through the GUI. The others can be controlled in real-time through the GUI. Here is an example of what a Faust GUI looks like: Images/faust-gui.jpg

If you are looking into using external MIDI devices, you will need to pass the -midi -nvoices option, as per regular Faust, e.g.:

faust2bela -tobela -midi -nvoices 4 -gui /path/to/faust/file.dsp

Some Bela-specific examples can be found in the faust/examples/bela folder of faust (online version), and an illustrated README file is also there

Learn all about Faust:

The great Faust manual and the Faust playground: an online playground to experiment with connecting together Faust patches.

Interfacing with Bela's analog and digital pins

To interface Bela's analog and digital inputs, you need to edit the labels to follow the naming scheme: [BELA:ANALOG_0] or [BELA:DIGITAL_0]:

freq     = hslider("[1]Frequency[BELA:ANALOG_0]", 440 ,460, 1500, 1)
    :smooth(0.999);
pressure = hslider("[2]Pressure[style:knob][BELA:ANALOG_4]", 0.96, 0.2, 2.0, 0.01)
    :smooth(0.999):min(0.99):max(0.2);
gate     = hslider("[0]ON/OFF (ASR Envelope)[BELA:DIGITAL_0]",0,0,1,1);

See also this dsp file as an example.

An alternative, probably not working, discouraged, convoluted way of doing things:

This is a bit more convoluted and requires installing and compiling faust on your board and using a special Bela project. Follow the instructions here: https://github.com/giuliomoro/bela-faust-jit