Difference between revisions of "FluidSynth"

From ArchWiki
Jump to: navigation, search
m (remove intro header)
m (How to convert MIDI to OGG)
Line 40: Line 40:
 
  aplaymidi -p128:0 example.midi
 
  aplaymidi -p128:0 example.midi
 
== How to convert MIDI to OGG ==
 
== How to convert MIDI to OGG ==
 +
Simple command lines to convert midi to ogg:
  
 
  # fluidsynth -nli -r 48000 -o synth.cpu-cores=2 -F /dev/shm/midi_temp.raw /usr/share/soundfonts/fluidr3/FluidR3GM.SF2 example.MID
 
  # fluidsynth -nli -r 48000 -o synth.cpu-cores=2 -F /dev/shm/midi_temp.raw /usr/share/soundfonts/fluidr3/FluidR3GM.SF2 example.MID
 
  # oggenc -r -B 16 -C 2 -R 48000 /dev/shm/midi_temp.raw -o example.ogg
 
  # oggenc -r -B 16 -C 2 -R 48000 /dev/shm/midi_temp.raw -o example.ogg
 +
 +
Here's a little script to convert multiple midi files to ogg in parallel:
 +
 +
#!/bin/bash
 +
maxjobs=$(cat /proc/cpuinfo | grep processor | wc -l)
 +
#echo $maxjobs
 +
midi2ogg() {
 +
name=`echo $@ | sed s/[.][mM][iI][dD][iI]?$//g | sed s/^[.][/]//g`
 +
# echo "$name"
 +
for arg; do
 +
fluidsynth -nli -r 48000 -o synth.cpu-cores=$maxjobs -F "/dev/shm/$name.raw" /usr/share/soundfonts/fluidr3/FluidR3GM.SF2 "$@"
 +
oggenc -r -B 16 -C 2 -R 48000 "/dev/shm/$name.raw" -o "$name.ogg"
 +
rm "/dev/shm/$name.raw"
 +
done
 +
}
 +
export -f midi2ogg
 +
find . -regex '.*[.][mM][iI][dD][iI]?$' -print0 | xargs -0 -n 1 -P $maxjobs bash -c 'midi2ogg "$@"' --

Revision as of 19:47, 20 April 2010

FluidSynth is a real-time software synthesizer based on the SoundFont 2 specifications.

Installing FluidSynth

The first step is to install FluidSynth itself. It can be installed via pacman from the extra repository:

# pacman -S fluidsynth

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.

How to use fluidsynth

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/FluidR3GM.SF2 example.midi

Assuming than you installed fluidr3.

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

Alsa daemon mode

If you want fluidsynth to run as ALSA daemon, edit /etc/config.d/fluidsynth and modify FSYNTH_SOUNDFONT with de sound sample you want to use, for fluidr3:

FSYNTH_SOUNDFONT="/usr/share/soundfonts/fluidr3/FluidR3GM.SF2"

After that, you can start fluidsynth with:

# /etc/rc.d/fluidsynth start

If you want to have permanent MIDI support, add timidity to your daemon list in /etc/rc.conf:

DAEMONS=(... fluidsynth ...)

This 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 OGG

Simple command lines to convert midi to ogg:

# fluidsynth -nli -r 48000 -o synth.cpu-cores=2 -F /dev/shm/midi_temp.raw /usr/share/soundfonts/fluidr3/FluidR3GM.SF2 example.MID
# oggenc -r -B 16 -C 2 -R 48000 /dev/shm/midi_temp.raw -o example.ogg

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

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