How tp play MIDI files [emu10k1]

First off this how-to is for sound cards that use the emu10k1 driver,meaning SoundBlasters and compatible (I have an Audigy card). Playing midi’s natively can be a real plus.
Particulary for playing older games in dosbox or wine.
O.K. your sound card driver is loaded and sound is working fine
exept that you can’t play midi files. Don’t panic, all this means is that there’s no sound fonts loaded. You can see this in a terminal with the command:

cat /proc/asound/card/wavetableD1

The output will look something like this:

lindys:~ > cat /proc/asound/card0/wavetableD1
Device: Emu10k1
Ports: 4
Addresses: 17:0 17:1 17:2 17:3
Use Counter: 0
Max Voices: 64
Allocated Voices: 0
Memory Size: 134217728
Memory Available: 134213632
Allocated Blocks: 1
SoundFonts: 0
Instruments: 0
Samples: 0
Locked Instruments: 0
Locked Samples: 0

See, no sound fonts, instruments, and such it’s empty, and just waiting for us to load something up. First we’re going to need some sound fonts There ought to be some on the installation media that came with your card. There was for my card so that’s what I used. Lacking that, Google around for free/public domain sound fonts that you can live with. Now that you have some soundfonts you need a place to put them, and a way to load them. I put my fonts in /opt/sfbank. At the terminal(as root):

 mkdir /opt/sfbank

then copy your soundfonts to your sf folder (again as root):

 cp /your/soundfont.sf2 /opt/sfbank (repete for additional fonts).

Use YaST to install a utility called awesfx, then at the terminal (as root) load up a font.

asfxload /path/to/soundfont.sf2

Have more than one you want to load? No
problem, use the -N option to load them incrementally.

asfxload -N /path/to/next/soundfont.sf2

Now ==>cat /proc/asound/card0/wavetableD1 should show us some numbers:

lindys:~ # cat /proc/asound/card0/wavetableD1
Device: Emu10k1
Ports: 4
Addresses: 17:0 17:1 17:2 17:3
Use Counter: 0
Max Voices: 64
Allocated Voices: 0
Memory Size: 134217728
Memory Available: 120896488
Allocated Blocks: 1402
SoundFonts: 3
Instruments: 8507
Samples: 1401
Locked Instruments: 8507
Locked Samples: 1401

Now were in business, but there’s still some work to be done
yet.Let’s see what output ports are available. At the terminal type:

aplaymidi -l

The output should look something like this:

lindy@lindys:~> aplaymidi -l
 Port    Client name                      Port name
 14:0    Midi Through                     Midi Through Port-0
 16:0    Audigy 1 [Unknown]               Audigy MPU-401 (UART)
 16:32   Audigy 1 [Unknown]               Audigy MPU-401 #2
 17:0    Emu10k1 WaveTable                Emu10k1 Port 0
 17:1    Emu10k1 WaveTable                Emu10k1 Port 1
 17:2    Emu10k1 WaveTable                Emu10k1 Port 2
 17:3    Emu10k1 WaveTable                Emu10k1 Port 3

The wavetable ports are the ones were looking for. lets try one out. At the terminal:

aplaymidi -p 17:0 /path/to/.mid

Let’s make it a bit easier by not having to specify one of the wavetable ports every time. At the terminal(as root):

export ALSA_OUTPUT_PORTS="17:0 17:1 17:2 17:3"


aplaymidi /path/to/.mid

O.K. So you’ve made it this far without having a psychotic episode? Congratulations we’re in the home stretch! This last part covers how to have your soundfonts load at boot.
At the terminal su - to root, and open your favorite text editor, kwrite, gedit, whatever, and put in the asfxload lines you used to load the soundfonts, and put in the “export ALSA” line as well and save the file as /etc/bash.bashrc.local .Here’s mine as an example:

#This is the place to put stuff 
#you want to load at boot but shouldn't put
#in bash.bashrc since it can be overwritten
#by system upgrades

#loads soundfonts and sets output ports
asfxload /opt/sfbank/2GMGSMT.SF2
asfxload -N /opt/sfbank/4GMGSMT.SF2
asfxload -N /opt/sfbank/8MBGMSFX.SF2
export ALSA_OUTPUT_PORTS="17:0 17:1 17:2 17:3"

This should do it! The acid test is of course to reboot and see what (if anything) blows up on you! No puff of smoke? No nasty warnings? No kernel panic? Excelent! Play midi’s to your hearts content!

Note: The use of Theremin soundfonts can cause cerebral hemorrhages in laboratory
animals,use with caution. No laboratory animals were harmed in the making of this how-to (just ruffed up a bit).

Wow, seeing this makes me wish I had an Audigy card that everyone else has. I think I’m the only person I’ve seen whose Audigy uses ca0106 instead of the emu10k1 module.

This makes me sad, however, good job on the tutorial.

Thanks Lysdestic (sorry about your Audigy card).

Gaaa! Where’s the edit button? In the first code box I show the command:

cat /proc/asound/card/wavetableD1

It should read:

cat /proc/asound/card0/wavetableD1

My bad for the typo, sorry.:o