severely distorted audio playback using "fluidsynth" and soundfonts

Bug #347307 reported by Dave Roberts
4
Affects Status Importance Assigned to Milestone
fluidsynth (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

Binary package hint: fluidsynth

Using "fluidsynth" v 1.08 as a soft synth in Intrepid results in a severely distorted sound.
The same replay in Hardy is ok.

ProblemType: Bug
Architecture: i386
DistroRelease: Ubuntu 8.10
ExecutablePath: /usr/bin/yelp
Package: yelp 2.24.0-0ubuntu2
ProcEnviron:
 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
 LANG=en_GB.UTF-8
 SHELL=/bin/bash
SourcePackage: yelp
Uname: Linux 2.6.27-8-eeepc-lean i686

Tags: apport-bug
Revision history for this message
Dave Roberts (drob-blueyonder) wrote :
Revision history for this message
David Henningsson (diwic) wrote :

If you render the output to a file, is it still distorted?
Will changing synth.gain help (try adding option -o synth.gain=0.02)?

Changed in fluidsynth (Ubuntu):
status: New → Incomplete
Revision history for this message
Dave Roberts (drob-blueyonder) wrote :

option -o synth.gain=0.02 only made the volume lower with same distorted output.
I rendered to a file (raw) but I am unable to play it.
Tried conversion sox -r 44100 -w -c 2 -s fluidsynth.raw fluidsynth.wav to convert but sox gve me a list of the full help file, that wasn't that much help!

Revision history for this message
David Henningsson (diwic) wrote :

Okay, thanks.

The proper sox command should probably be:

sox -b 16 -c 2 -s -r 44100 fluidsynth.raw fluidsynth.wav

Can you specify what command line you used to call fluidsynth?

Does this problem apply to all midi files and all soundfonts, or is it just one combination in particular that causes this problem?

Revision history for this message
Dave Roberts (drob-blueyonder) wrote :

The command I used to call Fluidsynth was:-
fluidsynth ~/Guitar/Soundfonts/32MbGMStereo.sf2 ~/snooker.mid
which gives severe distortion

also tried :-
fluidsynth -o synth.gain=0.02 ~/Guitar/Soundfonts/32MbGMStereo.sf2 ~/snooker.mid
same distortion, although much lower level output.

Played to file using:-
fluidsynth -i -a file ~/name.raw ~/Guitar/Soundfonts/32MbGMStereo.sf2 ~/snooker.mid

converted to .wav using:- (thanks for info BTW)
sox -b 16 -c 2 -s -r 44100 fluidsynth.raw fluidsynth.wav
The resulting .wav file is lower quality than the .mid replay and it has timing errors, however it does not suffer the
distortion of the direct options.

I first noticed this problem using Fluidsynth as a Tuxguitar plugin sound playback tool, distorted in Intrepid and Jaunty but clean in Hardy.

Revision history for this message
Dave Roberts (drob-blueyonder) wrote :

Sorry forgot to answer Soundfonts question.

Tried 3 soundfonts

8MBGMSFX.SF2 surprisingly 8MB in size

32MbGMStereo.sf2 31 MB

FluidR3GM.SF2 141 MB

The smallest file was definately better but still horribly distorted in parts (it did warn of 4 invalid generators so may have droppeds some instruments)

The 31 MB and 141 MB files were as badly distorted as each other.

Thanks very much

Revision history for this message
David Henningsson (diwic) wrote :

Hmm...could you be suffering from alsa underruns?

What if you specify

-o audio.period-size=4096

...that will probably give timing errors as well, but does it help against the distortions? If so, you could try changing 4096 to the smallest possible value that does not cause distortions (to get less and less timing problems). There is more information on the subject here:

http://fluidsynth.resonance.org/trac/wiki/LowLatency

Revision history for this message
Dave Roberts (drob-blueyonder) wrote :

Right on both counts with -o audio.period-size=4096
The timing is awful but the distortion goes away.

Eventually a reduction in size does not eradicatic bad timing without bringing in other audio errors.
Better on smaller soundfont.
I feel it has more of a tendancy to eat cpu with the audio period adjusted.

Tried Fluidsynth playback using Tuxguitar and the Fluidsynth Plugin on Hardy again just to make sure its clean, and it is.
Jaunty has not worked out of the can as Hardy is doing.

Thanks for the info on Latency link.
BTW its not so much latency with Jaunty it justs sounds like the band has aquired a VERY POOR rythmn section with the audio size adjusted.

Revision history for this message
David Henningsson (diwic) wrote :

It's hard to know if the problem is Fluidsynth's fault. It could just as well be the alsa subsystem, or anything else eating CPU. But it could also be that Fluidsynth 1.0.8 eats more CPU than 1.0.7, causing underruns. If you like, you can try out 1.0.9 for Jaunty in my ppa, https://launchpad.net/~diwic/+archive/ppa , to see if that helps.

On the latency webpage, did you also read the section about bypassing pulseaudio/dmix (-o audio.alsa.device=plughw:0)? Or do you perhaps do not use pulseaudio or dmix at all?

About the bad timing, that has been fixed in Fluidsynth SVN and will work better in next release of Fluidsynth (which will be 1.1.0), so whether or not that will reach Karmic depends on when that next version is released.

Revision history for this message
Dave Roberts (drob-blueyonder) wrote :

Things going worse.
I linked into your PPA and dowlnloaded the 1.09 Fluidsynth.
Unfortuanately I not get the following error when trying to run a .mid through Fluidsunth.

lash_open_socket: could not connect to host 'localhost', service '14541'
lash_comm_connect_to_server: could not create server connection
lash_init: could not connect to server 'localhost' - disabling LASH
fluidsynth: warning: Failed to pin the sample data to RAM; swapping is possible.
fluidsynth: error: Jack server not running?
Failed to create the audio driver

The RAM error is not new however the rest is, I reverted back to 1.08 and still the same error.
Do i need to install Jack?
Didn`t need it before though.

I don`t use Pulse deliberately, could it be that calling (-o audio.alsa.device=plughw:0) will bypass it.
Or will an uninstall be needed.

Many thanks

Revision history for this message
Dave Roberts (drob-blueyonder) wrote :

Found the problem with reverting back, libfluidsynth1 needed to revert to 1.08 as well.

Revision history for this message
David Henningsson (diwic) wrote :

You need to specify -a alsa with version 1.0.9 as it uses jack as default, whereas 1.0.8 uses alsa per default.

Yes, setting the option -o audio.alsa.device=plughw:0 will bypass both pulseaudio and dmix if they're being used by default.

Revision history for this message
Dave Roberts (drob-blueyonder) wrote :

Reinstalled Fluidsynth 1.09 from your PPA David and called a .mid file using the following:-

fluidsynth ~/Guitar/Soundfonts/32MbGMStereo.sf2 ~/snooker.mid -a alsa o audio.alsa.device=plughw:0

also used :-

fluidsynth ~/Guitar/Soundfonts/32MbGMStereo.sf2 ~/snooker.mid -a alsa

First the bad news I got the following errors before playback from both files :-

dave@dave-laptop:~$ fluidsynth ~/Guitar/Soundfonts/32MbGMStereo.sf2 ~/snooker.mid -a alsa
lash_open_socket: could not connect to host 'localhost', service '14541'
lash_comm_connect_to_server: could not create server connection
lash_open_socket: could not connect to host 'localhost', service '14541'
lash_comm_connect_to_server: could not create server connection
lash_open_socket: could not connect to host 'localhost', service '14541'
lash_comm_connect_to_server: could not create server connection
lash_open_socket: could not connect to host 'localhost', service '14541'
lash_comm_connect_to_server: could not create server connection
lash_open_socket: could not connect to host 'localhost', service '14541'
lash_comm_connect_to_server: could not create server connection
lash_open_socket: could not connect to host 'localhost', service '14541'
lash_comm_connect_to_server: could not create server connection
lash_init: could not connect to server 'localhost' - disabling LASH
fluidsynth: warning: Failed to pin the sample data to RAM; swapping is possible.
fluidsynth: ALSA driver: Using format s16, rw, interleaved
FluidSynth version 1.0.9
Copyright (C) 2000-2006 Peter Hanappe and others.
Distributed under the LGPL license.
SoundFont(R) is a registered trademark of E-mu Systems, Inc.

Type 'help' for information on commands and 'help help' for help topics.

>

But now the good news both files played at first well with no distortion or timing errors.
So it would appear to me that pulseaudio and dmix are not causing problems.

The only playback issue seemed display screen related.
When I switched screens "ctrl alt left arrow" or scrolled the screen the distortion reapeared for the duration of the screen interuption.
This is another problem I have when using tuxguitar-fluidsynth 1.08 as a plugin to tuxguitar as a playback tool the output goes all distorted with screen activity.

I have not tried tuxguitar-fluidsynth 1.09 with Tuxguitar as I dont have Jack installed or is there a way to force alsa playback with tuxguitar-fluidsynth.

Fluidsynth 1.09 would require a change in the way packages are installed for tuxguitar.
At the moment if tuxguitar and tuxguitar-fluidsyth are installed with apt-get or synaptic, fluidsynth 1.08 and libfluidsynth1 (1.08) are loaded as dependencies. Its then just a case of pointing tuxguitar at a soundfont for playback. With fluidsynth 1.09 installation of Jack or an alsa work around would be necessary.

Revision history for this message
David Henningsson (diwic) wrote :

1) As using 1.0.9 fixes the issue, it is likely that it is fixed in Karmic (which runs 1.0.9), so I'm marking it as "fix released".

2) About the LASH errors - you can disable LASH connection with the -l switch, so this behavior is by design (although a bit annoying!).

3) Screen related distortions can probably be avoided by selecting a larger period size ( -o audio.period-size ).

4) About tuxguitar-fluidsynth's default output driver, someone should test it in Karmic to see if it is fixed there and if it is not, file a separate bug for that issue.

Changed in fluidsynth (Ubuntu):
status: Incomplete → Fix Released
Revision history for this message
Dave Roberts (drob-blueyonder) wrote :

David I can confirm playback of the line below produces distortion free time consistant output with no interference from screen scrolling etc.

dave@dave-laptop:~$ fluidsynth ~/Guitar/Soundfonts/32MbGMStereo.sf2 ~/snooker.mid -a alsa -l -o audio.period-size=1024

I have installed Jack and used the newer version of fluidsynth with Tuxguitar using tuxguitar-fluidsynth.
It plays distortion free until there is screen movement or a cursor shift, I suspect if I could change the default audio.period-size=1024 it would play without glitches.

Thanks for your help will install Karmic and try soon.

Revision history for this message
Raymond (superquad-vortex2) wrote :

>> On the latency webpage, did you also read the section about bypassing pulseaudio/dmix (-o audio.alsa.device=plughw:0)? Or do you perhaps do not use pulseaudio or dmix at all?

it also depend on the sample rate of the soundfonts in sf2 match with the sample rate of audio.alsa device

if the soundfonts are 44100Hz , you may need to change the defaults.pcm.dmix.rate from 48000 to 44100Hz

e.g. PA server use 44100Hz , so there is no need for resampling

The other factor is the size of the soundfont

fluidsynth: warning: Failed to pin the sample data to RAM; swapping is possible.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.