nwhitehead / pyfluidsynth

Python bindings for FluidSynth
GNU Lesser General Public License v2.1
197 stars 56 forks source link

fs.program select and fs.note_on keep returning 0's with no sound #22

Closed DJ-Hayden closed 3 years ago

DJ-Hayden commented 5 years ago

I'm using a custom SF2 file from the internet (clean electric guitar). However, when I use either fs.program_select(0, sfid, 0, 0) or fs.noteon(0, 60, 30) it prints a 0 to the Python terminal and does not play a sound.

Do you have the "example.sf2" file you call in the tutorial script? I want to make sure there's not something wrong with my drivers/set up. Thanks!

DJ-Hayden commented 5 years ago

Update: I just saw the test folder with the sf2 file and tests. I ran test1.py and test3.py with no errors (didn't try test2.py because I don't have pyaudio installed). However, they didn't play sounds. Any ideas as to what's going on?

SpotlightKid commented 5 years ago

Can you provide a link to the soundfont? Maybe you are just using the wrong program number?

You can list all presets in a soundfont by loading it with the fluidsynth command line program and then using the command inst <sfid>, for example:

$ fluidsynth ~/sf2/guitar/SampleSmith_Free_G1-v1.sf2
> fonts
ID  Name
 1  /home/chris/sf2/guitar/SampleSmith_Free_G1-v1.sf2
> inst 1
001-000 Open Long  Rings
001-002 Open Muted
DJ-Hayden commented 5 years ago

For details of the installation on an Ubuntu 18.04 system:

1) sudo apt-get install fluidsynth 2) activate my conda environment 3) pip install numpy 4 save GitHub version of pyfluidsynth from https://github.com/nwhitehead/pyfluidsynth/pull/17 5) navigate to Downloads and unpack, then navigate inside the folder 6) python setup.py install 7) cd test 8) python 9)

import time
import fluidsynth

fs = fluidsynth.Synth()
fs.start()

sfid = fs.sfload("example.sf2")

# after these two, the python terminal displays 0 and no sound is played
fs.program_select(0, sfid, 0, 0)
fs.noteon(0, 60, 30)

As for the question about the sounds, when I'm in that same test folder and run fluidsynth example.sf2 I get:

FluidSynth version 1.1.9
Copyright (C) 2000-2018 Peter Hanappe and others.
Distributed under the LGPL license.
SoundFont(R) is a registered trademark of E-mu Systems, Inc.

fluidsynth: warning: No preset found on channel 9 [bank=128 prog=0]
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
exec of JACK server (command = "/usr/bin/jackd") failed: No such file or directory
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
fluidsynth: error: Failed to connect to Jack server.
Failed to create the audio driver

I haven't read anything about setting up a Jack driver (fairly certain Ubuntu 18.04 is ALSA), so maybe that's the problem?

Thanks for the help!

DJ-Hayden commented 5 years ago

P.S. I'm also noting that the FluidSynth version is 1.1.9, whereas the newest is 2.0.5. That might explain why https://github.com/nwhitehead/pyfluidsynth/pull/21 didn't work when I used that to install pyfluidsynth instead.

albedozero commented 3 years ago

The driver selection is fixed by 54ede290d53a5e7db919066bd643fffaf6f913fc and fluidsynth 2.x compatibility is fixed by de3baa1b311996045b8ee8a2c659afb272d26723.

For reasons, the FluidSynth team made the default driver on linux JACK, but that requires you to set up a jack server using qJackCtrl or similar. ALSA is much easier out of the box on Ubuntu, and you can use that by changing fs.start() to fs.start(driver='alsa').