I didn't found anything like "How to setup midi output (as in .mid files) in linux" so I kinda wrote my own once I got my system working. It does need a bit of tweaking... Since awesfx works only for emu10k1 driver, and I have an Audigy2 card, this guide works only for cards covered by the emu10k1 driver.
First, soundcard driver is loaded and sound is working fine. Usually it does... But you can't play midi files, because the soundcard doesn't have any midi instruments loaded. This can be seen with the command
cat /proc/asound/card0/wavetableD1
Code:
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: 134176768
Allocated Blocks: 2
SoundFonts: 0
Instruments: 0
Samples: 0
Locked Instruments: 0
Locked Samples: 0
The instruments, samples and all that usually come in certain files, called soundfonts. These can be found on the driver cd that came with your soundcard (please tell me there's a website that has soundfonts). On my case, there was a file called "CT4MGM.SF2" on the cd, and it was just what I needed. Take a copy of it to your HD, no need to use the cd longer than necessary.
Then, you have the soundfont file, or even couple of them. But what to do with it? The soundfont must be installed to the soundcard's memory (which is empty after every reboot). Use yum to install a utility called
awesfx, and try loading the soundfont.
Code:
Loading single file:
# asfxload /path/to/soundfont.sf2
Got multiple soundfonts? Load the rest with the -N switch. (meaning incremental loading)
# asfxload -N /path/to/second-soundfont.sf2
# asfxload -N /path/to/more-soundfonts.sf2
Now midi should be set up on the cards end. There's still software to tweak.
cat /proc/asound/card0/wavetableD1 shows some numbers now:
Code:
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: 130154814
Allocated Blocks: 490
SoundFonts: 1
Instruments: 3560
Samples: 488
Locked Instruments: 3560
Locked Samples: 488
Before you can play midi files, you have to know the output ports.
aplaymidi -l prints available ports nicely.
Code:
Port Client name Port name
14:0 Midi Through Midi Through Port-0
16:0 Audigy MPU-401 #2 Audigy MPU-401 (UART)
16:32 Audigy MPU-401 #2 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
Great, there are the wavetable outputs, let's try them.
aplaymidi -p 17:0 song.mid should work. But this is really awkward to use, isn't it? Luckily ALSA_OUTPUT_PORTS variable exists. You can use it like this:
Code:
$ export ALSA_OUTPUT_PORTS="17:0 17:1 17:2 17:3"
$ aplaymidi song.mid
You might want to put that variable to your .bashrc or somewhere where it gets loaded always. And to get the soundfont installed at boot, put the line(s) you used to load the .sf2 file to /etc/rc.local
Theoretically, now all midi players using ALSA should be able to output some funky midi tunes. I don't have many applications to test this, but atleast aplaymidi and OpenTTD work fine.
Filesystem paths and midi output ports may vary on your system. Comments, notes, or feedback appreciated.