Difference between revisions of "FluidSynth"

From ArchWiki
Jump to: navigation, search
(How to convert MIDI to MP3/OGG: Added requirements and some additional info)
m (Added missed pipe parameters to simple example, without which fluidsynth trying to write raw result to soundfonts)
 
(6 intermediate revisions by 5 users not shown)
Line 3: Line 3:
 
[http://www.fluidsynth.org/ FluidSynth] is a real-time software synthesizer based on the SoundFont 2 specifications. It is required by {{Pkg|gst-plugins-bad}}, and thus is installed as a dependency of the {{Grp|gnome}} group.
 
[http://www.fluidsynth.org/ FluidSynth] is a real-time software synthesizer based on the SoundFont 2 specifications. It is required by {{Pkg|gst-plugins-bad}}, and thus is installed as a dependency of the {{Grp|gnome}} group.
  
== Installing FluidSynth ==
+
== Installation ==
  
 
The first step is to [[install]] the {{Pkg|fluidsynth}} package.
 
The first step is to [[install]] the {{Pkg|fluidsynth}} package.
Line 9: Line 9:
 
'''However, FluidSynth will not produce any sound yet'''. This is because FluidSynth does not include any instrument samples. To produce sound, instrument patches and/or soundfonts need to be installed and fluidsynth configured so it knows where to find them. You can install [[Timidity#SoundFonts|SoundFont sample]].
 
'''However, FluidSynth will not produce any sound yet'''. This is because FluidSynth does not include any instrument samples. To produce sound, instrument patches and/or soundfonts need to be installed and fluidsynth configured so it knows where to find them. You can install [[Timidity#SoundFonts|SoundFont sample]].
  
== How to use FluidSynth ==
+
== Usage ==
  
 
There are two ways to use FluidSynth. Either as MIDI player or as daemon adding MIDI support to ALSA.
 
There are two ways to use FluidSynth. Either as MIDI player or as daemon adding MIDI support to ALSA.
Line 16: Line 16:
  
 
You can simply use fluidsynth to play MIDI files:
 
You can simply use fluidsynth to play MIDI files:
  $ fluidsynth -a alsa -m alsa_seq -l -i /usr/share/soundfonts/FluidR3_GM2-2.sf2 example.midi
+
  $ fluidsynth -a alsa -m alsa_seq -l -i /usr/share/soundfonts/FluidR3_GM.sf2 example.midi
 
assuming than you installed {{Pkg|soundfont-fluid}}.
 
assuming than you installed {{Pkg|soundfont-fluid}}.
  
Line 27: Line 27:
 
If you want fluidsynth to run as ALSA daemon, edit {{ic|/etc/conf.d/fluidsynth}} and add your soundfont along with any other changes you would like to make. For e.g., fluidr3:
 
If you want fluidsynth to run as ALSA daemon, edit {{ic|/etc/conf.d/fluidsynth}} and add your soundfont along with any other changes you would like to make. For e.g., fluidr3:
  
  SOUND_FONT=/usr/share/soundfonts/FluidR3_GM2-2.sf2
+
  SOUND_FONT=/usr/share/soundfonts/FluidR3_GM.sf2
 
  AUDIO_DRIVER=alsa
 
  AUDIO_DRIVER=alsa
 
  OTHER_OPTS='-is -m alsa_seq -r 48000'
 
  OTHER_OPTS='-is -m alsa_seq -r 48000'
  
After that, you can [[start/enable]] the fluidsynth service. Be aware of bug https://bugs.archlinux.org/task/50122 when using pulseaudio driver
+
After that, you can [[start/enable]] the fluidsynth service. Be aware of bug https://bugs.archlinux.org/task/50122 when using the pulseaudio driver.
 +
 
 +
Note that you can't use root to restart the fluidsynth service, if you're using the pulseaudio driver. Pulseaudio won't allow root to connect, since the pulseaudio server is usually started by the user (and not root). You can solve it by creating a [[systemd/User]] service (replacing {{ic|multi-user.target}} with {{ic|default.target}} in the copied {{ic|fluidsynth.service}}).
  
 
The following will give you an output software MIDI port (in addition of hardware MIDI ports on your system, if any):
 
The following will give you an output software MIDI port (in addition of hardware MIDI ports on your system, if any):
Line 48: Line 50:
 
Requires [https://www.archlinux.org/packages/?sort=&q=soundfont-fluid&maintainer=&flagged= soundfont-fluid] or any other soundfont of your choice.  
 
Requires [https://www.archlinux.org/packages/?sort=&q=soundfont-fluid&maintainer=&flagged= soundfont-fluid] or any other soundfont of your choice.  
  
/usr/share/soundfonts is the default location of FluidR3_GM
+
{{ic|/usr/share/soundfonts}} is the default location of FluidR3_GM
  
 
Simple command lines to convert midi to mp3:
 
Simple command lines to convert midi to mp3:
  
  $ fluidsynth -l -T raw -F /usr/share/soundfonts/FluidR3_GM.sf2 example.mid | twolame -b 256 -r example.mp3  
+
  $ fluidsynth -l -T raw -F - /usr/share/soundfonts/FluidR3_GM.sf2 example.mid | twolame -b 256 -r - example.mp3  
  
 
Requires [https://www.archlinux.org/packages/?sort=&q=twolame&maintainer=&flagged= twolame]
 
Requires [https://www.archlinux.org/packages/?sort=&q=twolame&maintainer=&flagged= twolame]
Line 58: Line 60:
 
Simple command lines to convert midi to ogg:
 
Simple command lines to convert midi to ogg:
  
  $ fluidsynth -nli -r 48000 -o synth.cpu-cores=2 -T oga -F example.ogg /usr/share/soundfonts/fluidr3/FluidR3GM.SF2 example.MID
+
  $ fluidsynth -nli -r 48000 -o synth.cpu-cores=2 -T oga -F example.ogg /usr/share/soundfonts/FluidR3_GM.sf2 example.MID
  
 
Here's a little script to convert multiple midi files to ogg in parallel:
 
Here's a little script to convert multiple midi files to ogg in parallel:
Line 67: Line 69:
 
  name=$(echo $@ | sed -r s/[.][mM][iI][dD][iI]?$//g | sed s/^[.][/]//g)
 
  name=$(echo $@ | sed -r s/[.][mM][iI][dD][iI]?$//g | sed s/^[.][/]//g)
 
  for arg; do  
 
  for arg; do  
  fluidsynth -nli -r 48000 -o synth.cpu-cores=$maxjobs -F "/dev/shm/$name.raw" /usr/share/soundfonts/fluidr3/FluidR3GM.SF2 "$@"
+
  fluidsynth -nli -r 48000 -o synth.cpu-cores=$maxjobs -F "/dev/shm/$name.raw" /usr/share/soundfonts/FluidR3_GM.sf2 "$@"
 
  oggenc -r -B 16 -C 2 -R 48000 "/dev/shm/$name.raw" -o "$name.ogg"
 
  oggenc -r -B 16 -C 2 -R 48000 "/dev/shm/$name.raw" -o "$name.ogg"
 
  rm "/dev/shm/$name.raw"
 
  rm "/dev/shm/$name.raw"
Line 76: Line 78:
 
  export -f midi2ogg
 
  export -f midi2ogg
 
  find . -regex '.*[.][mM][iI][dD][iI]?$' -print0 | xargs -0 -n 1 -P $maxjobs bash -c 'midi2ogg "$@"' --
 
  find . -regex '.*[.][mM][iI][dD][iI]?$' -print0 | xargs -0 -n 1 -P $maxjobs bash -c 'midi2ogg "$@"' --
 +
 +
== Troubleshooting ==
 +
 +
=== Conflicting with PulseAudio ===
 +
 +
If your ''fluidsynth'' application is set to use alsa as driver, the sound card will be accessed directly and pulseaudio and applications using pulseaudio will not be able to work properly. You can modify the  configuration file {{ic|/etc/conf.d/fluidsynth}} and change the driver to PulseAudio, then restart ''fluidsynth'' and PulseAudio:
 +
 +
{{hc|/etc/conf.d/fluidsynth|
 +
output=AUDIO_DRIVER=pulseaudio
 +
OTHER_OPTS='-m alsa_seq -r 48000'
 +
}}

Latest revision as of 23:17, 7 October 2017

FluidSynth is a real-time software synthesizer based on the SoundFont 2 specifications. It is required by gst-plugins-bad, and thus is installed as a dependency of the gnome group.

Installation

The first step is to install the fluidsynth package.

However, FluidSynth will not produce any sound yet. This is because FluidSynth does not include any instrument samples. To produce sound, instrument patches and/or soundfonts need to be installed and fluidsynth configured so it knows where to find them. You can install SoundFont sample.

Usage

There are two ways to use FluidSynth. Either as MIDI player or as daemon adding MIDI support to ALSA.

Standalone mode

You can simply use fluidsynth to play MIDI files:

$ fluidsynth -a alsa -m alsa_seq -l -i /usr/share/soundfonts/FluidR3_GM.sf2 example.midi

assuming than you installed soundfont-fluid.

There are many other options to fluidsynth; see manpage or use -h to get help.

One may wish to use pulseaudio instead of alsa as the argument to the -a option.

ALSA daemon mode

If you want fluidsynth to run as ALSA daemon, edit /etc/conf.d/fluidsynth and add your soundfont along with any other changes you would like to make. For e.g., fluidr3:

SOUND_FONT=/usr/share/soundfonts/FluidR3_GM.sf2
AUDIO_DRIVER=alsa
OTHER_OPTS='-is -m alsa_seq -r 48000'

After that, you can start/enable the fluidsynth service. Be aware of bug https://bugs.archlinux.org/task/50122 when using the pulseaudio driver.

Note that you can't use root to restart the fluidsynth service, if you're using the pulseaudio driver. Pulseaudio won't allow root to connect, since the pulseaudio server is usually started by the user (and not root). You can solve it by creating a systemd/User service (replacing multi-user.target with default.target in the copied fluidsynth.service).

The following will give you an output software MIDI port (in addition of hardware MIDI ports on your system, if any):

$ aconnect -o
client 128: 'FLUID Synth (5117)' [type=user]
   0 'Synth input port (5117:0)'

An example of usage for this is aplaymidi:

$ aplaymidi -p128:0 example.midi

How to convert MIDI to MP3/OGG

Requires soundfont-fluid or any other soundfont of your choice.

/usr/share/soundfonts is the default location of FluidR3_GM

Simple command lines to convert midi to mp3:

$ fluidsynth -l -T raw -F - /usr/share/soundfonts/FluidR3_GM.sf2 example.mid | twolame -b 256 -r - example.mp3 

Requires twolame

Simple command lines to convert midi to ogg:

$ fluidsynth -nli -r 48000 -o synth.cpu-cores=2 -T oga -F example.ogg /usr/share/soundfonts/FluidR3_GM.sf2 example.MID

Here's a little script to convert multiple midi files to ogg in parallel:

#!/bin/bash
maxjobs=$(grep processor /proc/cpuinfo | wc -l)
midi2ogg() {
	name=$(echo $@ | sed -r s/[.][mM][iI][dD][iI]?$//g | sed s/^[.][/]//g)
	for arg; do 
	fluidsynth -nli -r 48000 -o synth.cpu-cores=$maxjobs -F "/dev/shm/$name.raw" /usr/share/soundfonts/FluidR3_GM.sf2 "$@"
	oggenc -r -B 16 -C 2 -R 48000 "/dev/shm/$name.raw" -o "$name.ogg"
	rm "/dev/shm/$name.raw"
	## Uncomment for replaygain tagging
	#vorbisgain -f "$name.ogg" 
	done
}
export -f midi2ogg
find . -regex '.*[.][mM][iI][dD][iI]?$' -print0 | xargs -0 -n 1 -P $maxjobs bash -c 'midi2ogg "$@"' --

Troubleshooting

Conflicting with PulseAudio

If your fluidsynth application is set to use alsa as driver, the sound card will be accessed directly and pulseaudio and applications using pulseaudio will not be able to work properly. You can modify the configuration file /etc/conf.d/fluidsynth and change the driver to PulseAudio, then restart fluidsynth and PulseAudio:

/etc/conf.d/fluidsynth
AUDIO_DRIVER=pulseaudio
OTHER_OPTS='-m alsa_seq -r 48000'