A few months ago I posted 2 videos where I showed not only that the first Age of Empires was working fine on Linux using Wine, but also that I was able to get the MIDI playback to work with 2 different soundfonts. Here are the 2 videos:
- Age of Empires ·· Linux + Wine ·· Timidity + FluidR3
- Age of Empires ·· Linux + Wine ·· Timidity + Merlin GM v32
Recently I got a request on how to set up Wine and other native software to get a proper MIDI playback, so here is my reply that should work on any Linux distro (BSD too probably).
First let me list the software that I’m going to use:
- aconnect and aplaymidi (part of the alsa-utils package)
- Timdity++ or Fluidsynth (scroll until the end for Fluidsynth)
- Wine and a game/software MIDI support
- a soundfont (I’m going to list a few later)
As for the game I’m still going to use the first Age of Empires (pssssst you find it here…)
Now before starting I would like to make a comparison:
You can consider the 3 as an orchestra, where the score is the game/software MIDI signal, the conductor is Timidity and the ensemble is the soundfont.
So at this point you may end up having the score, the conductor but no ensemble to play it; the score, the ensemble but no one that directs or…
…having the conductor and the ensemble but nothing to play.
This is the case by default when trying a game/software with Wine as explained in this Wine wiki page dedicated to MIDI:
The MIDI mapper is the default device on MS-Windows that almost every MIDI playing application uses. It forwards MIDI commands to other MIDI devices, depending on its configuration. Most applications will not let you choose the MIDI output device — they simply assume that the mapper was correctly configured.
In Wine, the mapper forwards to the first device (number 0) by default. winmm:midiOutOpen uses these exact same numbers. Wine associates one device with every port (as known from aconnect). The order is shown in winecfg, with device #0 occuring topmost. If this happens to be the “MIDI through” port on your system with SW-only synthesizers, you need to change the configuration via the registry.
So by default on every new Wineprefix that you create you may have this issue regarding MIDI, but I will check this later, first let’s assure that the ensemble and the conductor can actually produce some sound.
So let’s begin by installing alsa-utils (should be already installed), Timidity and a soundfont. On arch I run :
# pacman -S timidity++
as for the soundfont there is a nice package on Arch called soundfont-fluid, you can go ahead and install that:
# pacman -S soundfont-fluid
If your distribution doesn’t have that soundfont you can install another one or just download one (if you download a .sfArk files you then need to extract it with a software called sfArk, you find it on the AUR or on GitHub)
here you can download one (.sf2 files no extraction required):
Btw you also need a midi file to reproduce, here is Mortal Kombat Soundtrack (or just search and download any .mid file):
Ok let’s test Timidity and the soundfont:
first open a terminal to check the connections with aconnect:
watch -n1 aconnect -l
should output something like this:
client 14: 'Midi Through' [type=kernel] 0 'Midi Through Port-0'
at this point open another terminal and run Timidity this way:
timidity -iA -Os -x soundfont /usr/share/soundfonts/FluidR3_GM.sf2
timidity -iA -Os -x soundfont 32MbGMStereo.sf2
timidity -iA -Os
Whatever the case aconnect should now output Timidity too:
client 14: 'Midi Through' [type=kernel] 0 'Midi Through Port-0' client 128: 'TiMidity' [type=user,pid=20521] 0 'TiMidity port 0 ' 1 'TiMidity port 1 ' 2 'TiMidity port 2 ' 3 'TiMidity port 3 '
Next is to check what client port number is Timidity (should be 128 by default), Timidity is now ready with its soundfont to playback a midi track, to play the downloaded .mid file run:
aplaymidi -p128 mortal-kombat.mid
Now the playback should’ve started and aconnect list another new port and connections:
client 14: 'Midi Through' [type=kernel] 0 'Midi Through Port-0' client 128: 'TiMidity' [type=user,pid=20521] 0 'TiMidity port 0 ' Connected From: 129:0 1 'TiMidity port 1 ' 2 'TiMidity port 2 ' 3 'TiMidity port 3 ' client 129: 'aplaymidi' [type=user,pid=20661] 0 'aplaymidi ' Connecting To: 128:0
Ok now I know that both Timidity and the soundfont are working, but if it doesn’t work you should:
- First check that aplaymidi is running pointing the correct port where the Timidity client is
- Try another soundfont
- Run timidity –help and try some other output or input (-i and -O)
- Check your soundcard(s) with alsamixer or pavucontrol
After that I can switch to Wine to understand if it is sending a MIDI signal or not. After you installed AoE (or any other game with MIDI) launch it, a MIDI track should start at the main menu. On aconnect you should have a new entry now:
client 14: 'Midi Through' [type=kernel] 0 'Midi Through Port-0' Connected From: 128:0 client 128: 'WINE midi driver' [type=user,pid=30732] 0 'WINE ALSA Output' Connecting To: 14:0 1 'WINE ALSA Input '
if you have no output you can apply that registry edit that was previously mentioned, here it is:
REGEDIT4 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Multimedia\MIDIMap] "CurrentInstrument"="#1"
you can save it and apply it this way:
WINEPREFIX=/path/to/prefix regedit filename
Now try to run Wine and see if something has changed, you can debug only the MIDI mapper with WINEDEBUG:
WINEDEBUG=-all,+msacm WINEPREFIX=/path/to/prefix wine app.exe
If everything is now working you can launch Timidity and it should play the MIDI tracks (better if you launch Timidity first):
client 14: 'Midi Through' [type=kernel] 0 'Midi Through Port-0' client 128: 'TiMidity' [type=user,pid=5746] 0 'TiMidity port 0 ' Connected From: 129:0 1 'TiMidity port 1 ' 2 'TiMidity port 2 ' 3 'TiMidity port 3 ' client 129: 'WINE midi driver' [type=user,pid=5901] 0 'WINE ALSA Output' Connecting To: 128:0 1 'WINE ALSA Input '
Hope it works! Enjoy the old-school vibes :)
To run Timidity as daemon (another method here):
Timidity -iAD -Os
You can use FluidSynth instead of Timidity this way:
fluidsynth -aalsa 32MbGMStereo.sf2
This is just an introduction and a quick guide to get MIDI to work, both Timidity and FluidSynth can be heavily customized to fit every needs, soon I’m going to write another similar post but using some external hardware.
Here are some links:
- Wine MIDI wiki
- MIDI arch-wiki
- Timidity arch-wiki
- FluidSynth arch-wiki
- Ubuntu MIDI how to
- Hammersound soundfonts
- Merlin soundfonts
- other soundfonts