Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Fluidsynth randomly accepts or rejects a certain soundfont #1457

Closed
spessasus opened this issue Dec 26, 2024 · 8 comments · Fixed by #1458
Closed

[BUG] Fluidsynth randomly accepts or rejects a certain soundfont #1457

spessasus opened this issue Dec 26, 2024 · 8 comments · Fixed by #1458
Labels
Milestone

Comments

@spessasus
Copy link
Contributor

FluidSynth version

Execute fluidsynth --version and provide the output.

fluidsynth --version
ALSA lib pcm_dsnoop.c:567:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1000:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2722:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2722:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2722:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
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
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
ALSA lib pcm_oss.c:404:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pcm_oss.c:404:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pcm_a52.c:1036:(_snd_pcm_a52_open) a52 is only for playback
ALSA lib confmisc.c:160:(snd_config_get_card) Invalid field card
ALSA lib pcm_usb_stream.c:481:(_snd_pcm_usb_stream_open) Invalid card 'card'
ALSA lib confmisc.c:160:(snd_config_get_card) Invalid field card
ALSA lib pcm_usb_stream.c:481:(_snd_pcm_usb_stream_open) Invalid card 'card'
ALSA lib pcm_dmix.c:1000:(snd_pcm_dmix_open) unable to open slave
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 runtime version 2.4.1
Copyright (C) 2000-2024 Peter Hanappe and others.
Distributed under the LGPL license.
SoundFont(R) is a registered trademark of Creative Technology Ltd.

FluidSynth executable version 2.4.1
Sample type=double

Describe the bug

Okay, so this is a very strange bug:
The attached sf3 soundfont sometimes loads and sometimes doesn't as demonstrated in the video.
It reports "failed to read sample data" while other times it loads? Also the samples seem to be mismatched, especially the drums. Again, it's random.
I have set up a fallback soundfont and that's when the piano can be heard, meaning that Calm 4 has failed to load.
https://github.com/user-attachments/assets/35a15ffa-8506-468b-94f8-8fecef4b2179

Expected behavior

It should either fail 100% of the time or load 100% of the time. The file doesn't change (unless fluid modifies it somehow?) so it should be deterministic.

Steps to reproduce

  1. Calm 4.sf3.zip (remove .zip, it's just a soundfont, not an archive)
  2. Load it a few times.
  3. Sometimes it loads, sometimes it doesn't.

Note: I used this command: fluidsynth Downloads/Calm\ 4.sf3 Downloads/Persona4\ Specialist.mid -o audio.driver=pulseaudio
Omitting audio.driver or using a different MIDI file don't make a difference.

Additional context

This soundfont has mixed samples. Both compressed and uncompressed. And it crashes Polyphone, so it's probably a bit messed up. Though spessasynth loads it 100% of the time.

@spessasus spessasus added the bug label Dec 26, 2024
@derselbst
Copy link
Member

Which version of libsndfile are you using? I'll try to look into it in the following days.

@spessasus
Copy link
Contributor Author

pacman -Qi libsndfile
Name            : libsndfile
Version         : 1.2.2-2
Description     : A C library for reading and writing files containing sampled audio data
Architecture    : x86_64

@derselbst derselbst added this to the 2.4 milestone Dec 27, 2024
@derselbst
Copy link
Member

Interesting. So the loading of a Soundfont is parallelized in fluidsynth since version 2.2.0. This particular SF however uses multiple individual uncompressed samples, which hasn't been tested or considered before. Because of that, this function:

static int fluid_sffile_read_wav(SFData *sf, unsigned int start, unsigned int end, short **data, char **data24)

Will be called multiple times concurrently, where as for a regular SF2 file it would only be called once. The threads mess up the shared FILE handle of the SF file, because there is no synchronization built in here yet. If you set OMP_NUM_THREADS=1 it'll always work. I'll fix that.

@spessasus
Copy link
Contributor Author

Well, according to Fluid's own RFC, mixed compression is supported.

@derselbst
Copy link
Member

I know that. But Fluidsynth 2.2.0 was developed and released before that RFC was drafted. Hence, it has neither been considered, nor tested during development.

@spessasus
Copy link
Contributor Author

I see. Thanks.

Also just a quick, somewhat related question: Since fluidsynth uses sndfile, does that mean that it can load a soundfont containing any compression that libsndfile supports? (like flac or opus for example)

@derselbst
Copy link
Member

Since fluidsynth uses sndfile, does that mean that it can load a soundfont containing any compression that libsndfile supports?

I haven't tested it - but yes, to my knowledge, there are no restrictions in fluidsynth's code that should prevent that from working.

@derselbst
Copy link
Member

Merging it now, thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants