craffel / pretty-midi

Utility functions for handling MIDI data in a nice/intuitive way.
MIT License
856 stars 151 forks source link

fluidsynth: error: Unknown integer parameter 'synth.sample-rate' #236

Open drscotthawley opened 10 months ago

drscotthawley commented 10 months ago

Hi Colin. I wonder if you might have any suggestions for the following.

I'm noticing an error on my Mac with new versions of pyfluidsynth, pretty-midi and fluidsynth, when I try to run the following code

import pretty_midi 
_SAMPLING_RATE = 16000
sample_file = 'maestro-v2.0.0/2013/ORIG-MIDI_03_7_6_13_Group__MID--AUDIO_09_R1_2013_wav--2.midi'
pm = pretty_midi.PrettyMIDI(sample_file) 
waveform = pm.fluidsynth(fs=_SAMPLING_RATE)   # <--- this line is where the error occurs

That code still works fine on Colab (e.g. in the Tensorflow RNN MIDI demo), but running on my Mac, I get:

fluidsynth: error: Unknown integer parameter 'synth.sample-rate'

On the Mac, I'm getting the error message with both pyfluidsynth versions 1.3.1 and 1.3.2.

Any idea how one might fix this? Thanks.

$ fluidsynth --version
FluidSynth runtime version 2.3.4

Screenshot from my notebook.

Screenshot 2023-11-03 at 6 12 50 PM
drscotthawley commented 10 months ago

Aha! As per this Closed pyfluidsynth Issue from earlier this year, setting the sample rate to be a float instead of an int makes the error go away.

i.e.

_SAMPLING_RATE = 16000.0

is the fix. Unclear to me why this only shows up on the Mac and not Colab. 🤔

Feel free to close this Issue.

craffel commented 10 months ago

Should we change this: https://github.com/craffel/pretty-midi/blob/0ada945d18d1cbc498db957a715ddee8944c64e6/pretty_midi/fluidsynth.py#L15 to a float then?

drscotthawley commented 10 months ago

What if you just multiplied the sample rate by 1.0 when calling fluidsynth itself? e.g. on line 60

synthesizer = fluidsynth.Synth(samplerate=fs*1.0)

? (To me, this strategy is just a workaround for an issue that "really" should be fixed on fluidsynth's end. )

craffel commented 10 months ago

Better to call float on it, but yes.

yawjalik commented 6 months ago

Hello there, this issue seems to be fixed on pyfluidsynth 1.3.3 now