faustgen~ : LLVM powered Faust embedded compiler as an external for Max/MSP

    Nov 16 2012 | 4:45 pm
    Thanks to the awesome LLVM technology (http://llvm.org/) combined with "libfaust", the new library version of the Faust compiler, Faust DSP programs can now directly be compiled and executed on the fly at full speed. The Faust DSP source, compiled by libfaust using the LLVM backend, produces an intermediate representation (as LLVM IR : http://llvm.org/docs/LangRef.html), to be compiled and executed as native machine code directly in memory (using LLVM JIT technology). The LLVM IR can itself be optimized (using "optimization passes" in LLVM terminology), and the JIT component can be configurated to produce the best possibly native machine code.
    This compilation chain has been experimented in faustgen~, an external for Max/MSP. Faustgen~ allows to easily use Faust source code inside a Max/MSP patcher, edit it, change compilation options, and even produce the processor flow chart as an SVG diagram. Preliminary tests show that the resulting native code runs at speed comparable to what the previous static compilation model was achieving.
    A package containing the faustgen~external as well as faustgen~.maxhelp file, can be downloaded on the Faust site here: https://sourceforge.net/projects/faudiostream/files/

    • Nov 16 2012 | 8:24 pm
      as far as i am concerned, this is a major moment in computer dsp processing, let alone in max. as big as gen~. congratulations. i'd heard this was on the cards, and quite awesome it has appeared so quickly. i'll be getting stuck in as soon as possible. thanks.
    • Nov 16 2012 | 9:56 pm
      Indeed. I knew this was coming, but that fast !...
    • Nov 16 2012 | 11:37 pm
      great stuff! but obviously OsX only :-( can we expect a Windows version? thanks
    • Nov 17 2012 | 7:20 am
      Concerning Windows version, we had problems with "dynamic" inlets/outlets (the faustgen~ object has to change the number of ins/outs when the DSP source is changed). This was just crashing on Windows when we tried.
    • Nov 17 2012 | 8:46 am
      thanks for the info sletz. couldn't this bug be addressed by cycling74 ? Could be a Max6 bug related to windows only? thanks
    • Nov 17 2012 | 11:06 am
      very cool. I notice that when I double click a faustgen~ object the menu always seems to appear in the same place on the screen, far from my cursor. Could I suggest a usability improvement? I think that double click should just opens the "DSP code" text editor, which is how other max objects with text editors work. The other options are probably used less and could be accessed by sending messages to the object.
    • Nov 20 2012 | 9:56 am
      hi sletz. could be a bug solving problem for cycling74? i think that dynamic changing of inlets and outlets seems a problem for Max ( if it works on Mac should work on Windows to i guess? ) thanks
    • Nov 20 2012 | 10:16 am
      Cycling74 (thanks for them!) send us some code that should work on Windows also.
    • Nov 20 2012 | 11:30 am
      yeah! thanks sletz and cycling74 ! i'll patiently wait for a win release to test!
    • Nov 20 2012 | 2:34 pm
      Go Stéphane, go! (Stéphane is the brains behind Jack on OS X and Windows, FYI).
      Great work. The Faust stuff is really cool, and having it available directly within Max is a big win. Will check it out ASAP!
    • Nov 20 2012 | 5:12 pm
    • Nov 20 2012 | 5:35 pm
      thanks sletz! is the new version compiled for Windows to ? thanks. a.
    • Nov 20 2012 | 6:04 pm
      is there such thing as a changelog ?
    • Nov 20 2012 | 9:54 pm
      file 'Install faustgen~.rtf' inside the folder.
    • Nov 20 2012 | 10:55 pm
      obviously. i was stupid. thanks
    • Nov 26 2012 | 11:43 am
      hi stephane! any progress on a windows version for faustgen~? thanks and all the best a.
    • Nov 27 2012 | 10:20 pm
      Windows version for faustgen~ : in progress...
    • Nov 27 2012 | 11:46 pm
      great! thanks stephane for the info.
    • Dec 03 2012 | 5:11 pm
      Version 0.81b available with faustgen~ for Windows. Please test and report.
    • Dec 03 2012 | 6:59 pm
      Stéphane se développe à pas de loup, et nous en musique assistée par ordinateur sont tous profondément dans sa dette!
      Merci, Stéphane. cb
    • Dec 03 2012 | 11:47 pm
      great ! thanks Stephane! did a quick test. everything seems to work except opening the block diagram file. do we need to have othe faust stuff for it to be open. When i try i have a kindo of "program not found " error. in a couple of days i'll run more detailed tests.
    • Dec 04 2012 | 7:43 am
      Opening SVG (dynamically generated) or PDF (documentation) or even text files (for Faust libraries), is currently done by launching a command to open the given file. It means an application has to be associated with the file. SVG files are supposed to be displayed by a browser (like Firefox, Chrome....)
    • Dec 04 2012 | 10:10 am
      i'll try to do the file association manually. but i suspect that the shell command given by the faustgen~ external is not correct. i'll do a test in a couple of hours and report back right away. thanks for info stephane!
    • Dec 04 2012 | 11:35 am
      Here is the kind of command that is done: "start /b file:///E:/faustgen-111-svg/process.svg"
      Please report if you know a better/safer way to do.
    • Dec 04 2012 | 1:12 pm
      hi stephane, these are the error that i have trying to open the SVG and the PDF files from doubleclicking on faustgen~. I have the same error as the PDF one while trying to view libraries. But the error is repeated several times.
    • Dec 04 2012 | 2:33 pm
      Well, those look suspisiously like the "Spaces in path passed to unix style commandline" error. Since the default win path to Cycling74 is in C:Program Files ( with a space), perhaps a whitespace escape should be applied to path before sending it to commandline call?
      just guessin'... if that's it, oh, those win/*nix differences...how annoying.
    • Dec 04 2012 | 3:24 pm
      1) Have you correctly copied the "faustgen-resources" folder along with the faustgen~.mxe object? (as explained in the "Install faustgen~.rtf" file)
      2) SVG files (actually inside a folder) will be dynamically generated in this "faustgen-resources" folder : can you see them?
    • Dec 04 2012 | 4:14 pm
      "Stéphane se développe à pas de loup, et nous en musique assistée par ordinateur sont tous profondément dans sa dette!"
      Hum the (automatic ??) french translation smells like "poetry" ((-; what was the original sentence?
    • Dec 04 2012 | 8:59 pm
      "à pas de loup" = "with wolf's steps"...a phrase my ancient parisian french teacher taught some 35+ years ago, with the implied meaning of great rapidity, of a almost scary sort....soooo..... "Stephane develops at a remarkably speedy pace, and all of us in the computer music community are deeply in his debt." just trying to be supportive in a grandiose , perhaps even amusing way...
      *clunk*, ...hmmm...k, 'nother lose...:,-(...
      good work, keep it up, Stephane...
    • Dec 04 2012 | 11:31 pm
      Hi Stephane, yes i do have the faustgen-resources folder in the msp-externals one. Since i am on Windows 7 64 bit the default location of my Max 6.0.8 install is C:Program Files (x86)Cycling '74Max 6.0 so the faustgen-resource folder is C:Program Files (x86)Cycling '74Max 6.0Cycling '74msp-externalsfaustgen-resources
      when i try to view the svg files i get the error but two folders are created containing the svg files that i can actually open with Chrome.
    • Dec 05 2012 | 12:37 pm
    • Dec 05 2012 | 1:11 pm
      thanks stephane! now svg and pdf works perfectly. what's in the .lib files and with wich app is good to open those ?
    • Dec 05 2012 | 1:15 pm
      The ".lib" are the Faust libraries: those are simply text files.
    • Dec 05 2012 | 1:20 pm
      are those supposed to be open the same way we open the code to be edited with "Edit DSP code" ?
    • Dec 05 2012 | 1:28 pm
      i mean....wouldn't be nice to have another line similar to "max fileformat .dsp TEXT 0 "Faust DSP language file" dspfile;" for the .lib files to be open ?
    • Dec 05 2012 | 1:31 pm
      nahh.. 'cause they aren't not to be edited...sorry for the stupid things i said above :-)
    • Dec 05 2012 | 1:36 pm
      a question about the web-compiler. Stephane, do you think we can have SuperCollider Ugen and Csound opcode compilation on Windows ? thanks
    • Dec 05 2012 | 1:46 pm
      And since my curiosity is piqued: those strangely truncated paths in the error popups? Symptom of path string issue, or something else? ( I only ask since debugging other developer's code is my major daily activity...at least recently, :) ). And RE: "on tiptoe": this explains why my memory of the meaning of the phrase involving fear...the 15y.o. Charlie was deeply impressed with the large number of odd phrases she (my ancient teacher,the only formal contact w/ the language I ever had ) used involving the wolf as metaphor...which is why I tried to use the expression: it seemed the 'most fun' of the idiomatic translations I looked up, and I recalled her treasure trove of wolf idioms: they seemed so strange and interesting at the time. thanks again for your "awesome" coding efforts!
    • Dec 05 2012 | 2:44 pm
      1) We know use coding like : start "" "file:///E:/faustgen-111-svg/process.svg" (because start command requite a "title")
      2) "do you think we can have SuperCollider Ugen and Csound opcode compilation on Windows ?" ==> possibly at on point in the future..
    • Dec 05 2012 | 3:33 pm
      thanks Stephane. I see in the quick start .pdf that at page 47 table 5.2 reports SC Ugens and Csound opcodes as available audio architecture on Windows. So are they implemented in Faust ( i.e. FaustWorks ) but not in the online compiler ? many thanks for your great coding effort and infos!
    • Jan 04 2013 | 4:09 pm
      We are happy to announce the first distribution of Max/MSP oriented FAUST examples, by Christophe Lebreton, © GRAME www.grame.fr
      Get them here : maxmsp_faust_examples_v1.zip file at https://sourceforge.net/projects/faudiostream/files/
    • Mar 11 2013 | 11:20 pm
      - 09/03/2013 : Version 0.83b : add "write" message to save DSP in external files - possibly fix for LLVM related bugs
    • Mar 15 2013 | 10:15 am
      15/03/2013 : Version 0.84b : crashing bug correction in LLVM code generation
    • Mar 15 2013 | 2:20 pm
      hi stephane, on sourceforge there is still the 0.83b version. and no 0.84b. thanks for your great work! a.
    • Mar 15 2013 | 2:52 pm
      15/03/2013 : Version 0.85b : memory management corrections in LLVM code generation
      (still 32 bits only for now… version 64/32bits to be used with latest Max/MSP 6.1 in test)
    • Mar 15 2013 | 3:18 pm
    • Apr 05 2013 | 5:05 pm
      - 04/05/2013 : Version 0.86b : fix recursion limitation bug in Faust
      (still 32 bits only for now… version 64/32bits to be used with latest Max/MSP 6.1 in test)
    • Apr 17 2013 | 1:59 pm
      great ! this faust language is so powerful !
      I have a question... is it possible to dynamically change the number of processors in the resonator example ? like with the CNMAT resonator ? it would be very nice, or at least being able to selectively mute some processors... thank you.
    • May 06 2013 | 1:15 pm
      - 06/05/2013 : memory management correction in Faust. New "write" message to save DSP files. 64/32 bits version on OSX.
    • Nov 06 2013 | 8:47 pm
      Does anyone know whether faustgen~ works with Max4Live? Does it need gen~? Cheers!
    • Nov 06 2013 | 8:56 pm
      Nevermind. The answers are "yes, it does work in Max4Live" (I had to restart a couple times before it would show up), "No, it does not require gen~" :)
    • Nov 07 2013 | 9:46 am
      Hi. I'm a bit confused about the *.lib files. There is a subfolder in the Windows installation folder which contains a few, but no mention in the installation instructions. I'm on a mac and the "imports" don't seem to be complaining about their absence. Are they embedded in the faustgen mxo file?
      I'm trying to add one from the stk-faust lib. Does it just need to go in the PATH somewhere?
    • Nov 07 2013 | 11:20 am
      Also is there a reference anywhere for those included libs?
    • Nov 08 2013 | 4:50 pm
      On OSX, Faust libraries files are located in the mxo file, in Contents/Resources folder. You can possibly add you own files here. We'll probably improve the libraries files location system in a future version.
    • Nov 08 2013 | 6:53 pm
      Thanks. I ended up adding the stk port in an "stk/" subfolder. Then I can just simple do import("stk/instrument.lib") etc...
      Many thanks for this @sletz. It is awesome...I'm so excited! Working on a synthesiser version of my iOS app (soundwandapp.com) and this will help things considerably...
    • Nov 25 2013 | 3:50 pm
      I'm having some trouble with inputs into faustgen. It seems that sliders/flonums/live.dial's messaged to input parameters aren't translating correctly. Even the with faustgen help file, with the "gain" example, as you scroll through values, it seems to toggle gain between 0 and 1 judging by the meter. If you type entries in manually some map to 1 and others to 0. Has anyone else experienced this?
    • Dec 07 2013 | 12:57 am
      First off, great external, a good entryway to faust.
      Second, I'm also trying to use the faust-stk, like Harikaram. I've put the instrument.lib in Contents/Resources, but am running into a problem. faustgen~ crashes Max everytime I try to load a function which relies on the ffunction() call, such as modalBar.dsp.
      ex. Max: "read modalbar.dsp" program crashes console log reads
      12/6/13 4:45:14 PM Max[3100] Max: db update complete 12/6/13 4:46:33 PM [0x0-0x72072].com.cycling74.Max[3100] LLVM ERROR: Program used external function 'readMarmstk1' which could not be resolved! 12/6/13 4:46:33 PM [0x0-0x72072].com.cycling74.Max[3100] StartNotification name = default 12/6/13 4:46:33 PM com.apple.launchd.peruser.501[118] ([0x0-0x72072].com.cycling74.Max[3100]) Exited with exit code: 1
      call from instrument.lib is: "readMarmstk1 = ffunction(float readMarmstk1 (int), ,"");"
      and "readMarmstk1" is a cpp function in instrument.h which I've added to the same folder.
      Any idea why this isn't working?
    • Jan 20 2014 | 1:45 pm
      Yes, linking to code defined in external .h or .c or .cpp files is not currently supported. This would require faustgen~ to "embed" the entire C/C++ ==> LLVM IR ==> executable machine code compilation chain. Note that supporting arbitrary C/C++ code compilation could indeed become rapidly tricky. In the case of STK instruments, C headers files are currently used to access parameters tables. This may be doable directly in Faust with the new "waveform" syntax that now allows to define data tables directly in the .dsp source. We'll have to update faustgen~ to use this new "waveform" syntax.
    • Apr 18 2014 | 11:02 pm
      How are you supposed to get the samplerate inside faustgen? if i use the SR constant it is wrong (allways 44100)
    • Sep 08 2014 | 12:04 am
      Thanks for all of your help on this wonderful project. I can tell that you put in a lot of hard work, and it works like a charm in OS X!
      One of my students would like to use faustgen~ with Windows, so I'm trying to figure out what the situation is. It seems that the faustgen v0.87 archive only contains a 32-bit version, so I went back and installed the 32-bit version of Max 6.1.8 for Windows. Then I was able to instantiate the faustgen~ object. However, when I don't think that it's finding the lib files. I get the error "Unable to open file math.lib" when I try to compile a simple DSP file using it.
      I tried having the lib files in the same directory as the currently open patch, adding the directory of lib files to the Max path, and directly putting them inside the msp-externals directory. Still it doesn't find the lib files.
      Best, Edgar
      PS. Also there is the error "Cannot read "version" key, so ignore bitcode, force recompilation and use default compileoptions.
    • Jan 19 2015 | 10:20 pm
      @Edgar I'm on a mac but I had to place them inside of the faustgen~.mxo "package" (an app on a mac is usually a folder which looks like a file until you choose "Show package contents"). I'm not sure how it's structured on the PC but basically I'd guess you need them in the same path as the faustgen~ executable.
    • Oct 18 2015 | 9:43 pm