Fluidsynth error on Big Sur/M1 machine

Hey there—this might not be a SCAMP issue per se, but does anyone know why I might be getting this error when I fire up a script written using SCAMP?

WARNING:root:Fluidsynth could not be loaded; synth output will not be available.

This is happening on a new machine running macOS Big Sur with an Apple M1 chip. Wondering if that might have anything to do about it? I’m also still on SCAMP 0.8.6 (because I’m a little nervous about updating Abjad).

Anyway, I’m just a bit unsure of how to troubleshoot this, so I thought see if this rings a bell for anyone on here. Thanks!

Yeah… it’s probably the M1 or Big Sur. Can you try installing
fluidsynth via homebrew?

I’m guessing you’ve used homebrew before, but if not here’s the
installation instructions: https://docs.brew.sh/Installation

SCAMP comes bundled with an old version of fluidsynth, and I’m not
surprised that it’s causing issues, to be honest. Hoping that the
homebrew version works!

(Let me know how it goes — I’d like to know how to get things up and running on an M1/Big Sur machine)

That didn’t do the trick, sadly. I tried installing via homebrew but it told me that the most recent version of fluidsynth was already installed. For good measure I went ahead and reinstalled the whole thing with homebrew. Still got the same error when I ran my SCAMP script, though. :frowning_face:

Have you tried installing the Intel-based homebrew using rosetta? Perhaps this is helpful?

Oh, also, what happens of you run fluidsynth from the terminal? And what happens if you run:

import logging
logging.getLogger().setLevel(logging.DEBUG)
import scamp

It should print some useful messages.

Oof, okay, this has been a bit of a saga, but I think I’ve got it working now. First of all, thank you so much for the suggestions, Marc—they were extremely helpful.

So the first thing I did was run those three lines of debug code with the M1 versions of homebrew/fluidsynth installed, and I got this:

DEBUG:root:Trying to load copy of pyfluidsynth from within SCAMP package.
DEBUG:root:Trying to load fluidsynth DLL/DYLIB from within SCAMP.
DEBUG:root:Encountered error during load: ‘dlopen(/Users/aes/.virtualenvs/comp/lib/python3.9/site-packages/scamp/_thirdparty/libfluidsynth.1.5.2.dylib, 6): no suitable image found. Did find:
/Users/aes/.virtualenvs/comp/lib/python3.9/site-packages/scamp/_thirdparty/libfluidsynth.1.5.2.dylib: no matching architecture in universal wrapper
/Users/aes/.virtualenvs/comp/lib/python3.9/site-packages/scamp/_thirdparty/libfluidsynth.1.5.2.dylib: no matching architecture in universal wrapper’
DEBUG:root:Loading of SCAMP’s copy of fluidsynth DLL/DYLIB failed.
DEBUG:root:Trying to load system copy of fluidsynth DLL/DYLIB.
DEBUG:root:Could not find system copy of fluidsynth DLL/DYLIB.
DEBUG:root:Loading of pyfluidsynth failed.
DEBUG:root:Trying to load system copy of pyfluidsynth.
DEBUG:root:Loading of pyfluidsynth failed again.
WARNING:root:Fluidsynth could not be loaded; synth output will not be available.

The “matching architecture” message seemed very telling, so then I tried installing the Intel homebrew, and then fluidsynth via that homebrew, using the steps in the Medium post you linked. That gave me this:

DEBUG:root:Trying to load copy of pyfluidsynth from within SCAMP package.
DEBUG:root:Trying to load fluidsynth DLL/DYLIB from within SCAMP.
DEBUG:root:Loading of SCAMP’s copy of fluidsynth DLL/DYLIB succeeded.
DEBUG:root:Loading of pyfluidsynth succeeded.
Testing for working audio driver…
fluidsynth: error: Couldn’t find the requested audio driver alsa. Valid drivers are: coreaudio.
fluidsynth: error: Error setting the audio callback. Status=-66748
fluidsynth: error: Couldn’t find the requested audio driver dsound. Valid drivers are: coreaudio.
fluidsynth: error: Couldn’t find the requested audio driver Direct Sound. Valid drivers are: coreaudio.
fluidsynth: error: Couldn’t find the requested audio driver oss. Valid drivers are: coreaudio.
fluidsynth: error: Couldn’t find the requested audio driver pulseaudio. Valid drivers are: coreaudio.
fluidsynth: error: Couldn’t find the requested audio driver jack. Valid drivers are: coreaudio.
fluidsynth: error: Couldn’t find the requested audio driver portaudio. Valid drivers are: coreaudio.
fluidsynth: error: Couldn’t find the requested audio driver sndmgr. Valid drivers are: coreaudio.
WARNING:root:No working audio driver was found; synth output will not be available.

Which was different, at least. The “Status=-66748” thing led me here, where a few fluidsynth users are speculating that Core Audio has some sort of permissions-related issue on Big Sur: https://www.mail-archive.com/fluid-dev@nongnu.org/msg05491.html

So I figured that maybe the path of least resistance was to try to get fluidsynth to use a different audio driver. I installed portaudio (or maybe it was already installed, but it was just being masked from me at the time?), but I kept getting the same errors as above—the only “valid driver” being printed out was coreaudio and I was being told that portaudio couldn’t be found despite the fact that I had just installed it.

Finally I realized that maybe the problem was with the fluidsynth dll’s/dynlib’s in SCAMP’s _thirdparty folder. I tried deleting those, and voila! It worked. I can get synth playback from SCAMP now. I guess maybe SCAMP’s older, local version of fluidsynth was hard coded to only accept coreaudio, or something? Not sure. Anyway, I have sound now!

Hopefully this will be helpful to others, especially as the M1 chip continues to roll out… thanks again for all of the help, Marc!

1 Like

Oh weird! Had you installed Rosetta 2 before, or did you do it in the process of installing the Intel-based homebrew?

If so, it sounds like maybe before you installed Rosetta 2, it couldn’t load the Intel-based copy of libfluidsynth packaged with SCAMP. And then, once you installed Rosetta2, it was able to load it but ran into some other error with that (fairly old) copy of libfluidsynth.dylib. Then, once you deleted those dylibs, it just loaded the more modern version you installed using Homebrew (intel-based), which now works. Maybe?

By the way, you don’t have to delete the dylibs: all you actually have to do is run:

import scamp
scamp.playback_settings.try_system_fluidsynth_first = True
scamp.playback_settings.make_persistent()

This makes SCAMP try the system copy before the one bundled with scamp. (See scamp.settings.PlaybackSettings — scamp 0.8.7 documentation)

Anyway, so glad you got it working! I may have more questions for you in the future, since I want to make things as seamless as possible. :slight_smile:

Yeah, I think that’s probably pretty much exactly what happened. I hadn’t installed Rosetta 2 before running into the original error and going through this process, no. I think there probably really is some sort of issue with Core Audio on Big Sur, though—I didn’t clarify this, but I was getting that permissions error even when I fired up the up-to-date fluidsynth directly from my Rosetta terminal. (It wasn’t just a matter of my SCAMP script falling back on an older version of fluidsynth, in other words.)

Thanks for the tip re: the playback settings—that is very handy and much better than my shoestring-and-bubblegum approach of just moving the files. :wink: And thanks again for the help. I definitely felt like I was grasping around in the dark on this one and needed a good push in the right direction. Feel free to fire away with questions anytime!!

Dear SCAMPters!

I am currently learning Python and I tried to install SCAMP via Terminal, but I encountered on the same error on my Mac M1 Monterey while using Visual Studio Code. I succeeded to install SCAMP with Thonny so I can use that, but I would like to manage these errors.

I tried to add these lines on my Python-app code on Visual Studio Code:

import logging
logging.getLogger().setLevel(logging.DEBUG)

import scamp
scamp.playback_settings.try_system_fluidsynth_first = True
scamp.playback_settings.make_persistent()

I got following error on Terminal:

/usr/local/bin/python3 /Users/XXX/Documents/AUDIO_PROCESSING/SCAMP-testit/test4.py
DEBUG:root:Trying to load copy of pyfluidsynth from within SCAMP package.
DEBUG:root:Trying to load fluidsynth DLL/DYLIB from within SCAMP.
DEBUG:root:Encountered error during load: ‘dlopen(/Users/XXX/Library/Python/3.10/lib/python/site-packages/scamp/_thirdparty/mac_libs/libfluidsynth.3.0.1.dylib, 0x0006): tried: ‘/Users/XXX/Library/Python/3.10/lib/python/site-packages/scamp/_thirdparty/mac_libs/libfluidsynth.3.0.1.dylib’ (mach-o file, but is an incompatible architecture (have ‘x86_64’, need ‘arm64e’)), ‘/usr/lib/libfluidsynth.3.0.1.dylib’ (no such file)’
DEBUG:root:Loading of SCAMP’s copy of fluidsynth DLL/DYLIB failed.
DEBUG:root:Trying to load system copy of fluidsynth DLL/DYLIB.
DEBUG:root:Could not find system copy of fluidsynth DLL/DYLIB.
DEBUG:root:Loading of pyfluidsynth failed.
DEBUG:root:Trying to load system copy of pyfluidsynth.
DEBUG:root:Loading of pyfluidsynth failed again.
WARNING:root:Fluidsynth could not be loaded; synth output will not be available.
WARNING:root:pynput was not found; mouse and keyboard input will not be available.
Traceback (most recent call last):
File “/Users/XXX/Documents/AUDIO_PROCESSING/SCAMP-testit/test4.py”, line 4, in
import scamp
File “/Users/XXX/Library/Python/3.10/lib/python/site-packages/scamp/init.py”, line 26, in
from .session import Session
File “/Users/XXX/Library/Python/3.10/lib/python/site-packages/scamp/session.py”, line 22, in
from .transcriber import Transcriber
File “/Users/XXX/Library/Python/3.10/lib/python/site-packages/scamp/transcriber.py”, line 20, in
from .performance import Performance
File “/Users/XXX/Library/Python/3.10/lib/python/site-packages/scamp/performance.py”, line 33, in
from .instruments import Ensemble, ScampInstrument
File “/Users/XXX/Library/Python/3.10/lib/python/site-packages/scamp/instruments.py”, line 26, in
from ._soundfont_host import get_best_preset_match_for_name, print_soundfont_presets
File “/Users/XXX/Library/Python/3.10/lib/python/site-packages/scamp/_soundfont_host.py”, line 34, in
class PlayAndRecSynth(fluidsynth.Synth):
AttributeError: ‘NoneType’ object has no attribute ‘Synth’
XXX@XXX-MacBook-Air AUDIO_PROCESSING %

I am a bit confused about how to fix these problems so I would be happy for any advice!

Based on the error, it looks like the issue is that you don’t have rosetta 2 installed, which is the translation layer that let’s non-native programs and libraries work on the new chip. Try opening a terminal and running:

softwareupdate --install-rosetta

(see How to Install Rosetta 2 on Apple Silicon Macs)

Does that help?

Thank you, Marc, for your help, but this did not help.

But it works on Thonny, so I am okay with that.

And thank you for the great work you have done with Scamp!

With my best regards,
Susa

Hello, I just spent a few hours on this on a new M1 mac. I did a couple things differently than described above, so here’s what’s working for me:

  1. Install rosetta 2 so you can run x86_64 applications
    /usr/sbin/softwareupdate --install-rosetta --agree-to-license

  2. Create a second installation of homebrew for x86_64 per the instructions found here (top answer):
    zsh - How can I run two isolated installations of Homebrew? - Stack Overflow
    When you’re done with the instructions you will have an aliased command for the x86_64 version of brew, which in the article is ‘brow’

  3. Install fluidsynth via the x86_64 hombrew using the aliased command

brow install fluidsynth
  1. Change playback settings to try system fluidsynth first per Marc’s instructions
import scamp
scamp.playback_settings.try_system_fluidsynth_first = True
scamp.playback_settings.make_persistent()
  1. Now a working installation of fluidsynth is present, and scamp knows to look for the system version first, but it defaults to looking in the arm64 homebrew, so I have to specify the architecture on the command line when running a script like so:
arch -x86_64 python3 <your_scamp_script>.py

I’m curious to know if you had to do that aestephe?

Still getting this error, but not sure if that is or will become a problem.

WARNING:root:pynput was not found; mouse and keyboard input will not be available.

Also, I removed libfluidsynth.3.0.1.dylib from mac_libs just to see what would happen and it stopped working, so proceed with caution.

Anyway, seems like I can proceed from here so we’ll see how it goes. Excited to start tinkering.

Just an update on this: I think I can package together a fat dylib that contains both architectures, which would solve these issues. It’s just going to take a sec, because my wife is out of town and she’s the one with an M1 mac!

1 Like

Just a +1 for the fat dylib so I can avoid all the rigamarole in this post.

Enjoying using scamp with MIDI and Logic for the moment but would love to have it working with FluidSynth on my M1 and M2 Macs running Monterey without having to mess with Rosetta and Homebrew. Then I could run all the examples out of the box.

Please post when that is ready!

Thanks.

1 Like

Just a note to everyone: the most recent release of SCAMP (it’s a post-release: 0.9.1.post5) makes things a little easier, because it makes it possible to just install fluidsynth with the native M1 version of homebrew instead of messing with rosetta.

It turns out that Homebrew installs the native packages to a different location that pythons find_library function doesn’t know about, so I had to add some code to look specifically in that location.

So for now, all you should need it a homebrewed fluidsynth and no messing with rosetta! I’m still trying to figure out the steps to make a fat dylib and remove all impediments :slight_smile:

1 Like

This is awesome! Works like a charm. Thanks!

1 Like

Marc,
I´m using Mac M2 and did as advised in your last post, but python does not find FluidSynth (“ModuleNotFoundError: FluidSynth not available.”). Scamp version is 0.9.2.
When starting FluidSynth from the terminal, I get the below,
Can you please help?
Thanks, Peter

FluidSynth runtime version 2.3.3

Copyright (C) 2000-2023 Peter Hanappe and others.

Distributed under the LGPL license.

SoundFont(R) is a registered trademark of Creative Technology Ltd.

fluidsynth: error: fluid_sfloader_load(): Failed to open ‘/usr/local/Cellar/fluid-synth/2.3.3/share/soundfonts/default.sf2’: File does not exist.

fluidsynth: error: Unable to open file ‘/usr/local/Cellar/fluid-synth/2.3.3/share/soundfonts/default.sf2’

fluidsynth: error: Failed to load SoundFont “/usr/local/Cellar/fluid-synth/2.3.3/share/soundfonts/default.sf2”

How exactly did you install fluidsynth? Using the native homebrew with no rosetta?

Can you run:

import logging
logging.getLogger().setLevel(logging.DEBUG)
import scamp

And let me know what happens?

When looging “import scamp” as advised I realized, that I had installed the Intel version of FluidSynth :frowning_face:
Today I installed M2 native Homebrew with no Rosetta as described in https://brew.sh/#install and brew FluidSynth again.
Now it´s working !
Thank you for your feedback, Peter