• SoftwareFaust
  • My experience with Faust, and some more general observations

I am happy to say that Faust works fine on Bela, including MIDI, but that there are several things that can be improved.

The online compiler will produce a binary that runs, but the associated C++ source won't compile on Bela. This is because there have been changes in Bela since the Faust architecture file was written (easy to patch), but also because some Faust-specific libraries are missing (that's a lot more work).

Now if you download a binary and want to run it, you have to fool the IDE into believing that there is a full project there. So you rename the binary exactly like your project, as expected, but you also add phoney
render.cpp, build/render.o build/render.d files that are older than your binary. Then you can use the IDE run button, or the run-project.sh script and the Makefile will think everything is fine. But unfortunately if you use the former, the IDE stop button won't work, and you have to shut down the Bela to stop. Things will work if you run from a script, but naturally you won't get CPU monitoring.

The above leads me to suggest that in addition to the Faust-specific stuff I just mentioned, there should be a Wiki page about the nuts-and-bolts of Bela, like how a project is structured, the need for default_main.cpp, things like that. Some of the important material is already on the pages for scripts and Eclipse, but it is relevant to a lot more people than just those who use Eclipse.

And maybe there should be a flag for run_project.sh just for binaries, even if users can ssh and do ./MyProject anyway.

Thanks for your feedback.
It is great to see some interest in FAUST.

Some background:

The Bela architecture for FAUST has not seen much work in the past few months. It was originally developed for the old Bela API, mainly by Oli Larkin and Stephane Letz with our support back in March.
Ever since, the FAUST online compiler and the amazing Faust playground have been capable of producing binaries ready to be downloaded on Bela.
They did a great job but unfortunately have not yet found the time to port it to the latest API.

In the core Bela team there are no FAUST users, so we did not feel confident about porting the interface over to the new Bela API, as we would not be good enough at FAUST to be able to test it properly. We do, though, have a guide on how it can be done and we could really use a contribution from the community in this sense.

For all of these reasons, while FAUST code CAN run on Bela (as you have verified yourself), the workflow to do so is not the most straightforward ever. I will add an option for run_project.sh to run an existing binary.

I have tried to compile FAUST-generated C++ code on the board (I downloaded the C++ code from the FAUST online compiler). Though possible, it would sometimes require a very long time. We had this file that would take 3 minutes compiling with gcc and over 10 minutes with clang. I guess a 10k + lines file must require quite some CPU to be compiled, so a cross-build environment (or the online compiler) would be recommended for FAUST projects. This is the reason why there are no FAUST source files, executables and libraries on the board at the moment.

But unfortunately if you use the former, the IDE stop button won't work, and you have to shut down the Bela to stop.

This is probably caused by the fact that the "stop" button specifically looks for the running bela-audio thread, but in the binary you download it is called beaglert-audio. Still, you can kill the process from the IDE by typing

$ killall projetcName

in the console integrated in the IDE.

Alternatively, you can get CPU stats from the terminal (NOTE: this requires an actual terminal, you cannot run the watch command in the IDE. (I should probably create a script for that). To run it from within the IDE console you'll have to repeatedly run the following command cat /proc/xenomai/stat, surely not very convenient and while will not work ).

I take your point on the wiki: the Eclipse page is a bit stale. I am hoping to find the time to put together a reliable and portable (as in: downloadable) cross-compiling environment (without having to use the scripts I hacked together in the Eclipse page), and I am waiting for that moment to re-factor the page, but sure we can do better than it currently is.
Incidentally, the wiki is free to edit for any github user, so feel free to fill-in this page if you have time, or to amend existing documentation.

8 days later

I can help reviewing Faust/Bela architecture file change if needed...

    Hi sletz ,
    that'd be great thanks. If you could point me to the most up-to-date version of the Bela port, I will try to blindly patch it to the new API and then hand it over to you for testing, if that's alright.

    The latest bela.cpp file is simply in Faust Git. We did some changes back in july (is there something new since in Bela API ?), but I'm not sure Yann changed it in the online compiler yet. We'll check next week.

    Oh great to know, Stéphane!

    I actually didn't hear back from you back then and the online compiler had not changed since, so I assumed it had not
    been done.
    This is great news. The Bela API has not changed since then and is supposed to be stable for the foreseeable future (perhaps with additions but without breaking-changes).

    If Yann could update the code on the online compiler, that'd be great.

    👍 👍

    11 days later

    Just to let you know that Stéphane and Yann have updated the faust online services, so that they use the latest Bela API.
    Apart from bringing in the latest bug fixes, this also allows you to stop the running program from the IDE.

    I haven't done the run_project.sh thingy for binaries yet, but it's open here

    a year later

    OK, I installed openssl, LLVM and faust on my Bela board. I also cloned the bela-faust-jit repository. And now , what? I can't see any Faust options in the IDE, so I'm lost here. Help (possibly step-by-step explanation) is appreciated.

    The README says

    at runtime, pass the name of the .dsp file as a command-line argument: --faust faust.dsp

    this can be done from the IDE adding --faust faust.dsp to the "custom command line options".
    The included faust.dsp script exemplifies how to access Bela's analog and digitals.

    OK. I copied render.cpp to the IDE and set the cmd line parameters. Result:

    Building render.cpp...
    Makefile:411: recipe for target '/root/Bela/projects/faust/build/render.o' failed
    Build finished
    variable type 'BelaUI' is an abstract class column: 8, line: 310

    which is

    ...
    dsp* fDSP;
    BelaUI fUI;
    bela_midi fMIDI;
    MidiUI* fMidiUI;
    ...
    /usr/local/include/faust/gui/UI.h:71:22: note: unimplemented pure virtual method 'addSoundfile' in 'BelaUI'
            virtual void addSoundfile(const char* label, const char* filename, Soundfile** sf_zone) = 0;

    seems the code was too old to be compiled. Got the latest bela.cpp from git and now, this results:

    /**************************BEGIN USER SECTION **************************/
    
    <<includeIntrinsic>>
    
    <<includeclass>>
    
    /***************************END USER SECTION ***************************/
    
    /*******************BEGIN ARCHITECTURE SECTION (part 2/2)***************/
    
    std::list<GUI*> GUI::fGuiList;
    ztimedmap GUI::gTimedZoneMap;
    
    /**************************************************************************************
      Bela render.cpp that calls FAUST generated code
    ***************************************************************************************/
    
    unsigned int gNumBuffers = 0;   // the number of de-interleaved buffers for audio and analog i/o
    FAUSTFLOAT *gInputBuffers = NULL, *gOutputBuffers = NULL; //de-interleaved input/output buffers for the audio and analog inputs
    FAUSTFLOAT* gFaustIns[10];      // array of pointers to gInputBuffer data
    FAUSTFLOAT* gFaustOuts[10];     // array of pointers to gOutputBuffers data
    mydsp fDSP;

    Any idea, what's missing (sorry, I have no idea about faust infrastructure, because I can't get it to work neither offline or online).

      So I decided to compile faust.dsp with faust and inserted the created cpp code into bela.cpp (i.e. render.cpp). Result now:

      Building project...
      Building render.cpp...
       ...done
      Linking...
       ...done
      Build finished
      Running project...
      /root/Bela/projects/faust/faust: unrecognized option '--faust'
      Usage: 

      Am I missing something important here?

        DragonSF Am I missing something important here?

        if you compiled the FAUST-generated C++ code, then you would not be loading a .dsp file at runtime, therefore the --faust filename.dsp option is not supported, but that options is probably still in your IDE settings and you should remove it.

        DragonSF seems the code was too old to be compiled.

        Perhaps just adding virtual void addSoundfile(const char* label, const char* filename, Soundfile** sf_zone) {} inside class BelaUI : public UI would have fixed this (I got that by comparing with the bela.cpp file mentioned below)?

        DragonSF Got the latest bela.cpp from git and now, this results:

        I assume you mean this. This is a regular FAUST architecture file, that will not provide just-in-time compilation features, but should be suitable if you generate some C++ code with FAUST.

        DragonSF Any idea, what's missing (sorry, I have no idea about faust infrastructure, because I can't get it to work neither offline or online).

        What error do you get? The text you pasted seems to only be part of the source file?

          I have no problems with pre-compiled dsp code and to include that. But somehow the generated program doesn't run:

          After some editing , copying session, I came to this point:
          Building project...
          Build finished
          Running project...
          Trying to parse FAUST file: (null)
          Error: no audio callback defined. Make sure you set settings->render to point to your audio callback
          Error: unable to initialise audio
          Makefile:502: recipe for target 'runide' failed
          make: *** [runide] Error 255
          Bela stopped

          I can't see any settings->render. Please advise.

          After adding these lines:
          settings.setup = setup;
          settings.render = render;
          settings.cleanup = cleanup;
          to main.cpp, I got no error left, but also no sound. And no GUI. Do I need anything else?
          I can hear, that the audio is switched on and off, but that's it.

          Does this message mean anything: Trying to parse FAUST file: (null)
          When I stop Bela:
          Error in `/root/Bela/projects/nfaust/nfaust': corrupted size vs. prev_size: 0x00803840
          Aborted
          Makefile:502: recipe for target 'runide' failed
          make: *** [runide] Error 134
          Bela stopped

          There is no GUI to be expected at the moment.
          I have lost track of what your project folder looks like just now, so I can only guess as to why there is no sound. If you have a render() function somewhere that looks like this, then it means that the problem is most likely in the FAUST code in use.

          Maybe it requires some user input in order to generate sound?

            looks like --faust is not an option for main.cpp (I'll look at that later).

              DragonSF looks like --faust is not an option for main.cpp (I'll look at that later).

              correct:

              giuliomoro if you compiled the FAUST-generated C++ code, then you would not be loading a .dsp file at runtime, therefore the --faust filename.dsp option is not supported, but that options is probably still in your IDE settings and you should remove it.

                giuliomoro : yes, the flute example needs a GUI action. My folder (nfaust) is actually the same as your github folder. I replaced the main.cpp with the mentioned code and render.cpp with the bela.cpp code. In render.cpp I added $include "faust.,h", which contains the compiled faust.dsp code. That's it. If you want, I can upload the whole project. But without GUI, Faust is meaningless.
                Any idea, what's the problem with the GUI is?