DBraun / DawDreamer

Digital Audio Workstation with Python; VST instruments/effects, parameter automation, FAUST, JAX, Warp Markers, and JUCE processors
GNU General Public License v3.0
899 stars 65 forks source link

faust_processor.compile() results in segmentation fault #63

Closed hyakuchiki closed 2 years ago

hyakuchiki commented 2 years ago

I've been trying to get this working for a miniconda environment in LInux. Since I did not have sudo privilege, I had to build FAUST from source and install it locally. I edited the header and library search paths of DawDreamer.jucer to point at the miniconda python and Faust, and the installation went alright.

So far, it seems to work for sampling VSTs like Dexed, but fails to do anything Faust related. Initializing a Faust processor is fine, but calling functions like get_parameters_description() or compile() results in a segmentation fault. I'm guessing Faust isn't linked correctly or something, but is there any way of checking this? Here is the header and library search paths

/home/n_masuda/miniconda3/envs/daw/include/python3.9;
../../thirdparty/pybind11/include;
../../thirdparty/faust/architecture;
../../thirdparty/faust/compiler;
../../thirdparty/libsamplerate/src;
../../thirdparty/libsamplerate/include;
../../thirdparty/rubberband;
../../thirdparty/rubberband/rubberband;
../../thirdparty/rubberband/src/kissfft;
../../thirdparty/rubberband/src;
../../thirdparty/portable_endian/include;
/home/n_masuda/miniconda3/envs/daw/lib
/home/n_masuda/usr/local/lib (this is where Faust is)
/usr/local/lib
../../thirdparty/libsamplerate/build/src
DBraun commented 2 years ago

Hi, thanks for trying it out. I think we'll have to make sure you have the libfaust.so and the faustlibraries directory in the right locations.

The faustlibraries directory needs to be in at least one of a few places.

One option is sibling to dawdreamer.pyd/dawdreamer.so and faust.dll/faust.so (this is what the PyPI wheel should do automatically). For instance I have

Another option is cousin to the python binary. So if I have C:\Python39\python.exe I would rename faustlibraries to faust and put it at C:\share\faust

The Faust installation with apt-get is supposed to take care of the other options by putting them at /usr/local/share/faust.

Maybe you can give me more details about the faust-related files you see at /home/n_masuda/usr/local/lib, /usr/local/lib, and /usr/local/share/faust?

DBraun commented 2 years ago

Something a bit more tedious to try is to uncomment these lines https://github.com/DBraun/DawDreamer/blob/e4be8670e570e6b5fb187e1c9f50fdf584d32030/Source/FaustProcessor.cpp#L318-L328 and then try a basic faust expression that doesn't need any libraries.

faust_processor.set_dsp_string("process = 0, 0;")

Then it might print exactly all the locations where it's looking for faust libraries. Because it's using m_factory, it won't work if you're testing polyphonic faust processor.

hyakuchiki commented 2 years ago

Thanks for pointing me to the relevant code. It turns out that segfault was happening before those lines in FaustProcessor, but I found out that this was caused by FaustProcessor::getPathToFaustLibraries(). Specifically, the destructor of std::filesystem::path was causing segfault, since I was on g++ 8.3. I added -lstdc++fs as a linker flag in Projucer and this problem was probably solved. Then, uncommenting those lines told me where to put the faustlibraries files and I put them there. Simple stuff like fp.set_dsp_string('import ("stdfaust.lib"); process = no.noise <: _, _;'); seems to work now, but more complicated stuff like dx7 still results in segfault. I will update if I find out why.

hyakuchiki commented 2 years ago

Sorry, I just realized the dx7 had poly and m_factory doesn't exist, so the stuff needed to be commented out again. All solved for now I guess!

DBraun commented 2 years ago

Great, thank you. At some point I will add a method that returns the m_factory->getIncludePathnames() and m_poly_factory-getIncludePathnames().

One more thing, the Faust Processor by default imports stdfaust.lib. This makes set_dsp_string easier. You can disable it by doing faust_processor.auto_import = ""

By the way, I'm a big fan of flow_synthesizer. Good luck on your continued research!