Fluidsynth music driver patch renewed

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
sirdeiu
Engineer
Engineer
Posts: 4
Joined: 19 Jul 2014 19:56

Fluidsynth music driver patch renewed

Post by sirdeiu »

Hey there, wannabe tycoons 8) : I've updated a bit this patch to include a fluidsynth music driver, originally posted here:
Tested, patch, compile, run with latest rev 26702.

Specifics:

Install instructions for fluidsynth music driver: Copy patch file to openttd folder, patch with: patch -p0 -i svn-fluidsynth-music-driver.patch, compile openttd with: configure --with-fluidsynth to enable fluidsynth driver (fluidsynth-devel needed).
Then when starting OpenTTD use ./openttd -m fluidsynth to select the music driver.

Parameters for it are: driver can be alsa or jack or pulseaudio etc. (what fluidsynth supports), defaults now to pulseaudio. soundfont with path/to/soundfont.sf2 uses that soundfont file. Finally audio-period-size, specifies the audio.period-size (audio buffer size) for fluidsynth to prevent underruns. Defaults to 512. values are 64-4096. I've added this because when I've tested this driver, with the default period size (64 I think on Linux), I got clipping in the audio and distortion. Both with alsa and pulseaudio as drivers for fluidsynth. I did google a bit this problem, and that led to allowing to specify the audio.period-size. 1024 seems to be a OK value also.

So for example: ./openttd -m fluidsynth:audio-period-size=1024,driver=pulseaudio,soundfont=/usr/share/soundfonts/FluidR3_GM.sf2

I've tested this, compiled and ran on Fedora 20 x64 with fluidsynth 1.1.6 installed and the default FluidR3_GM.sf2 soundfont file. Works great, has volume control for the music in game. I've tested the modern music set, got some warnings on some songs about missing instruments or misconfigured ones, but playing OK.

Using this though, I've noticed openttd using about 2% CPU (gnome system-monitor) and ~220MB RAM, while with timidity got 0-1% CPU and ~80 MB RAM usage. (CPU is Q6600 4core).

So please test and report any issues. Credits for it should go to the original author found in the thread above. Maybe if this is OK it can be added to trunk.
Attachments
svn-fluidsynth-music-driver.patch
SVN diff patch to implement Fluidsynth music driver for OpenTTD.
(11.54 KiB) Downloaded 87 times
Kernigh
Engineer
Engineer
Posts: 5
Joined: 05 Aug 2014 19:49

Re: Fluidsynth music driver patch renewed

Post by Kernigh »

Trying this with svn r26720 on my OpenBSD system. By default, it fails:

Code: Select all

$ ./openttd -m fluidsynth                                                      
dbg: [driver] Fluidsynth: audio driver pulseaudio, soundfont (null), audio.period-size 512
fluidsynth: error: Couldn't find the requested audio driver pulseaudio. Valid drivers are: file, sndio.
Error: Unable to load driver 'fluidsynth'. The error was: Could not open fluidsynth audio driver
The minimum that works here is ./openttd -m fluidsynth:driver=sndio,soundfont=/usr/local/share/generaluser-gs/GeneralUser_GS.sf2

I suggest to keep the default value of audio.driver and not change it to pulseaudio. It might also help to add this .sf2 to the list of default fonts. This .sf2 is from an OpenBSD package: pkg_add generaluser-gs-soundfont

I already use Fluidsynth with OpenTTD, through the extmidi driver. The OpenBSD package of OpenTTD calls the midiplay(1) command, and my own builds use ./configure --with-midi=midiplay to do the same. Now midiplay(1) needs a MIDI device. I open an extra terminal and run "fluidsynth /usr/local/share/gen*/*.sf2" so Fluidsynth attaches itself as a MIDI device.

With this fluidsynth driver, I no longer need to run fluidsynth in an extra terminal. The only other difference is that OpenTTD's volume meter now works, and the music is much louder. When I run fluidsynth in a terminal, it sets synth.gain to 0.2, but when I use this driver, it sets synth.gain much higher, because OpenTTD's volume meter defaults to MAX. The music is so loud that I have trouble hearing the sound effects. To fix this problem, I must open the jukebox and lower the music volume, while leaving the sound-effects volume at MAX.
sirdeiu
Engineer
Engineer
Posts: 4
Joined: 19 Jul 2014 19:56

Re: Fluidsynth music driver patch renewed

Post by sirdeiu »

Hey there. Thanks for the feedback. I'm not running OpenBSD so have no way to test it on that. For Linux pulseaudio as default seems like a good idea. Maybe I can add a check to see what runtime OS there is and adjust to that. So that's an issue pending.
2nd issue regarding the sf, likewise needs to be OpenBSD specific I guess.

Can you post details about the fluidsynth version you have installed please? The volume thing seems to be specific to it.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 7 guests