agraef / pure-lang

Pure programming language
https://agraef.github.io/pure-lang/
315 stars 20 forks source link

segfaults when trying to run pd-faust examples #11

Closed boqs closed 6 years ago

boqs commented 6 years ago

Managed to compile & run the pd-faust/examples/synth.pd patch. However segfaults immediately after loading what_a_friend.pd or bouree.pd. Also segfault when attempting to change [faust~ organ] to [faust~ bass] in the synth.pd patch.

Are these known bugs or some problem with my toolchain/setup? the problems are observed on arch linux 64 bit intel cpu, with pd vanilla & faust.

Tried many combinations/permutations of compiling from source, aur packages w/ yaourt, but couldn't get examples fully working. Currently have my machine in a state where faust, pd, all the pure stuff including pd-faust installed from aur (since that seems like the most repeatable setup)

agraef commented 6 years ago

What system you're on?

boqs commented 6 years ago

my system:

uninstalled/recompiled/reinstalled everything from the various github repos... trying now to use the faust2/llvm dynamic reloading feature (still without success)

agraef commented 6 years ago

One thing: You should really be using the master-dev branch from https://github.com/grame-cncm/faust, this is faust2 now. You can use my faust2-git package on AUR to get this. The faust2-old branch is stale and will go away at some point.

Other than that, the only difference to my setup that I see is that you're using the latest from puredata's git, I'll try that to see whether I can reproduce these crashes.

I'm also on Arch (using both Antergos and Manjaro), my students use Mac, Ubuntu and even Windows with vanilla Pd and Purr-Data on a wide range of different cpus, we're running pd-faust all the time in the courses and it works without hitches on any of these systems, so I suspect that it's a local problem on your side. Might be a miscompiled binary or some obscure library incompatibility, or some as yet undiscovered bug which just happens to be tripped on your system. Anyway, we're going to find out what it is. :)

agraef commented 6 years ago

Well, I installed the latest vanilla from git now and tried all I could to reproduce your crashes, but I couldn't. :/ Latest vanilla with pd-faust works without a hitch on Arch for me.

Can you please zip up your binaries and attach them here, so that I can see whether these are the culprit? Here's what I need (replace /usr/lib/pd/extra with the actual prefix under which you installed the Pure+Faust externals):

boqs commented 6 years ago

right I'm going to really thoroughly wipe out all my whole pure-lang & faust setup & try to recompile everything manually one more time using faust's master-dev. Then I will provide a detailed bug report & the binaries if I really can't get it straightened out...

agraef commented 6 years ago

One more idea: do you, by any chance, use the csound external in Pd, as well as Victor Lazzarini's faust plug-in inside csound? (Or maybe any other external that internally uses libfaust's LLVM bitcode compiler in some way?) I know from first-hand experience with the csound external that this can cause such immediate crashes, even if the csound external and pd-pure are linked against the same LLVM version.

boqs commented 6 years ago

ok so from a clean start (with the magic haskell config from https://github.com/agraef/pure-lang/issues/8 & llvm35 package from AUR) I recompiled the following repos from source using make clean; make; sudo make install; (making very sure at the outset there were no stale packages):

console output when loading examples/synth.pd (with export PURE_OPTION_FAUST2=true)

opened alsa client 130 in:1 out:1 pd-pure 0.24 (pure-0.66) (c) 2009-2017 Albert Graef aggraef@gmail.com pd-pure: compiled for pd-0.48 on Jan 9 2018 xfade.bc: No such file or directory midiseq: loaded midi/take5.mid faust~: error loading 'organ' faust~: error loading 'chorus' faust~: error loading 'freeverb' faust~: error loading 'amp' synth.pd 23 2 24 2 (faust~->faust~) connection failed synth.pd 24 2 25 2 (faust~->faust~) connection failed synth.pd 25 2 26 2 (faust~->faust~) connection failed synth.pd 26 2 5 1 (faust~->canvas) connection failed

console output when loading examples/synth.pd (without PURE_OPTION_FAUST2)

opened alsa client 130 in:1 out:1 pd-pure 0.24 (pure-0.66) (c) 2009-2017 Albert Graef aggraef@gmail.com pd-pure: compiled for pd-0.48 on Jan 9 2018 pdfaust.pure, line 92: lib/util: cannot open shared object file: No such file or directory pdfaust.pure, line 95: external symbol 'pdfaust_mix' cannot be found pdfaust.pure, line 98: external symbol 'pdfaust_fill' cannot be found pdfaust.pure, line 99: external symbol 'pdfaust_crossfade' cannot be found midiseq: loaded midi/take5.mid 1003-synth:organ/pan: ctrl 10 1003-synth:organ/vol: ctrl 7 1003-synth (organ): 0 inputs, 2 outputs, 8 voices fdsp~: error loading 'xfade' fdsp~: error loading 'xfade' 1003-fx3:amp/gain: ctrl 7 1003-fx3:amp/balance: ctrl 8 fdsp~: error loading 'xfade' synth.pd 23 2 24 2 (faust~->faust~) connection failed synth.pd 24 2 25 2 (faust~->faust~) connection failed synth.pd 25 2 26 2 (faust~->faust~) connection failed synth.pd 26 2 5 1 (faust~->canvas) connection failed

pd path (in preferences):

/usr/local/lib/pd/extra/pure /usr/local/lib/pure /usr/local/lib/pd/extra/faust /usr/local/lib/pd/extra/faust/lib /usr/local/lib/pd/extra/faust/midi

dump of binaries: http://rickvenn.com/pure-dbg.tgz

boqs commented 6 years ago

(and don't think I use llvm for anything else whatsoever)

boqs commented 6 years ago

managed to get the synth.pd example working again by adding the following objects to preferences->startup:

however the segfaults were totally repeatable. then a breakthrough! I tried disabling my hard-realtime jack setup & just firing up puredata using the alsa driver... I was able to run the bouree example without getting crazy segfaults (but it's very crackly at 512 sample buffer).

Anyway my conclusion is none of this stuff plays nice with jack realtime scheduling - I'd already relaxed my usual 128 sample buffers to 512, but it didn't make a difference.

boqs commented 6 years ago

Deleted the scope objects from the example scenes, now it seems I can run all the example patches low-latency, hard-realtime without PURE_OPTION_FAUST2. even with this change to the patches, CPU usage is pretty heavy on my laptop.

It still can't find xfade.bc when I use export PURE_OPTION_FAUST2=true - tried specifiying absolute paths for auxilliary .bc files in pdfaust.pure like this:

using "/usr/local/lib/pd/extra/faust/lib/util"; let xfade = faust_init "/usr/local/lib/pd/extra/faust/lib/xfade" samplerate;

(don't really understand pure-lang, the above changes are a total guess)... after this, the error message in puredata terminal is: xfade.bc: Invalid value

agraef commented 6 years ago

managed to get the synth.pd example working again by adding the following objects to preferences->startup:

pure fdsp~ fsynth~

No, no, that's not the right way to do it. As the README says, you need to load pure (that's all right) and then faust/pdfaust. Otherwise you're just loading the Pure scripts of these objects, that's not going to work.

Ok, let me quickly check your pd-faust binaries.

agraef commented 6 years ago

The binaries are all right. I can load both the pure.pd_linux and the pdfaust.pd_linux libs that you compiled without any hitches on my system, and all the sample patches like faust-help and bouree run fine, so the compiled Faust plugins in dsp/*.so are fine, too. (I didn't check the usr/local/lib/pure/ stuff, but I think that your Pure installation is all right as well, otherwise you'd be seeing crashes already when loading the pure.pd_linux lib.)

So the only thing that seems wrong on your system is your Pd startup lib configuration. First, launch Pd, go to Edit/Preferences/Startup in the menu and remove fdsp~ and fsynth~ there, then add faust/pdfaust after pure. Press OK, quit Pd and relaunch it. You should now see something like this in the log in the main window:

pd-pure 0.24 (pure-0.66) (c) 2009-2017 Albert Graef <aggraef@gmail.com>
pd-pure: compiled for pd-0.45 on Jan 13 2018
pd-faust 0.14 (c) 2011-2017 Albert Graef <aggraef@gmail.com>
pd-faust: registered with pd-pure

This indicates that both the pure and the pd-faust libs have been loaded all right. If you see something else then please post the contents of your log here (you can just copy this from Pd's main window by selecting the text in the log, pressing Ctrl+C there to copy, then paste it here), so that we can try to sort it out.

agraef commented 6 years ago

BTW, not sure whether you noticed this, I have a binary repo with ready-made packages for all this stuff over here: https://pureaur.bitbucket.io/. All the packages are in the AUR, too, so there's really no need to build this stuff straight from the source on Arch if you know how to install packages from the AUR or how to add a binary repo to your pacman.conf (see the link for instructions).

agraef commented 6 years ago

Ok, let me know how far you get after fixing up your Pd startup. Then I can walk you through running the sample patches and how to create your own.

boqs commented 6 years ago

think.... that... did it!

thanks so much for helping me out and apologies it was a README fail on my part! My only excuse is I'm trying to do this stuff immediately after moving continents - body clock is still a mess, probably just tired/impatient due to that. (but I do realise this is a terrible excuse)

I think everything's working now as expected. (no more error messages). Just managed to actually test dynamically recompiling/reloading one of my own faust codes via the .so route... Super, super awesome - thanks very much indeed!

Think I may have a few more questions soon - figured out how to hook up faust to a midi keyboard, but I am also looking at this technology for 'non-semitone' music instrument control.

Do you mind if I contact you via email with any questions on that? (if I run into problems)

agraef commented 6 years ago

@boqs no problems, glad I could help. And I discovered an actual crash bug along the way (#12, still working on that). So don't try the Faust2/LLVM bitcode interface just yet, it is broken after all. ;-) But going the .so route should work just as well until I get #12 fixed, it's just that compilation of the Faust dsps takes a little bit longer.

Also note that I just committed a faust2pure helper script to facilitate the compilation of Faust dsps to loadable Pure modules, so you can now also use that (as an alternative to pd-faust/examples/dsp/Makefile) to conveniently compile your own Faust programs for use with pd-faust. Just running faust2pure organ.dsp will create the module organ.so loadable with pd-faust. You can find the script here, but it's also in Faust git already, so next time you install Faust from git it will be installed along the way.

If you have any further questions, feel free to ask. You can send me an email, but it's better to use one of the related mailing lists, either the Pure mailing list on Google Groups (http://groups.google.com/group/pure-lang), or one of the Faust mailing lists on SourceForge (https://sourceforge.net/p/faudiostream/mailman/).

agraef commented 6 years ago

Note to self: TODO: Improve the installation instructions in the pd-faust README.

boqs commented 6 years ago

oh, faust2pure sounds handy. I just copy-pasted the makefile from faust-pd/examples/dsp into my project for now, which also works. The installation instructions are actually fine, but I have been really tired/distracted - somewhat embarassed how much trouble this gave me. Probably reflects a lack of experience with pd as much as anything else.

Anyway, all the physical modelling examples are very inspiring - I have been playing them all afternoon, and got back to hacking on my own faust DSP ideas a bit - the dynamic loading works really well for that. thanks again. Just light-years ahead of my previous workflow with faust2jack.

There are a couple of things about the instrument interface I'd like to tweak - for example the behaviour when n_voices=1. But we can pick up that discussion on the mailing list another time!

agraef commented 6 years ago

@boqs, FYI: If you can come to JGU@Mainz in Germany in July, that would be a splendid opportunity for us to talk about your ideas and all things Faust, and meet all the other Faust developers as well: http://www.ifc18.uni-mainz.de/

boqs commented 6 years ago

that would be awesome! I will try to make it in July for sure...