ALSA
From Gentoo Linux Wiki
ALSA is a major sound system for Linux. It consists of several parts, the most important of which is the driver. The drivers are available as part of the kernel, or in the package media-sound/alsa-driver Typically the drivers in the portage tree are newer than those in the kernel, but if you use them, you will have to re-emerge them each time you rebuild your kernel.
Contents |
[edit] Hardware Discovery
Use the lspci program(part of sys-apps/pciutils) to identify any sound cards on your system:
We see here, as an example, that this computer is equipped with a Creative SoundBlaster Live!:
0000:00:0a.0 Multimedia audio controller: Creative Labs SB Live! EMU10k1 (rev 06)
The output states the type of device, brand, model, and potentially the necessary ALSA driver. To verify the driver name, go to the ALSA sound card matrix. This information will be to build the proper drivers in the kernel.
[edit] Kernel Configuration
Refer to the official Gentoo Kernel Configuration Guide on other matters surrounding the kernel and recompilation. Select the devices for which you wish to build drivers under the Generic devices, PCI devices and USB devices. Include them as modules:
| Linux Kernel Configuration: Kernel Configuration |
Loadable module support --->
[*] Enable loadable module support
Device Drivers --->
Character devices --->
<*> Enhanced Real Time Clock Support
Sound --->
<M> Sound card Support
<M> Advanced Linux Sound Architecture --->
<M> Advanced Linux Sound Architecture
<M> Sequencer support
<M> Sequencer dummy client
<M> OSS Mixer API
<M> OSS PCM (digital audio) API
[M] OSS Sequencer API
<*> RTC Timer support
[*] Use RTC as default sequencer timer
[ ] Dynamic device file minor numbers
[ ] Support old ALSA API
[ ] Verbose procfs contents
[ ] Verbose printk
[ ] Debug
Generic devices --->
PCI devices --->
USB devices --->
System on Chip audio support --->
< > Open Sound System (DEPRECATED)
|
(Recompile and (re)install your kernel.
[edit] Module Configuration
ALSA does not typically need user configuration on a system with only one sound card; all necessary modules should be loaded by udev automatically with dmix enabled. If sound does not function for some reason, or if you need to configure multiple sound cards, read on.
[edit] ALSA Userspace
You will need some userspace utilities for ALSA to function properly, these are provided with the media-sound/alsa-utils package. Note that you probably don't want to set the minimal on this package, as it will then only install the ALSA init scripts:
When emerged it's a good idea to add alsasound to your boot runlevel(as advised by the post-emerge message):
Last but not least, edit /etc/conf.d/alsasound to your liking.
[edit] Plugins
media-libs/alsa-lib carries a special USE variable called ALSA_PCM_PLUGINS. These plugins take a raw sound stream and process it further, adding effects or filtering.
This feature is intended for embedded systems, so that the ALSA footprint can be reduced by installing only the necessary plugins. It is recommended that you leave all plugins on unless you know which plugins are required for your sound card or are willing to experiment with which plugins are optional. See the post from the developer of this feature.
For futher reading on ALSA's plugins, see the ALSA PCM Plugins section of the ALSA wiki.
[edit] Configuration
ALSA will for most single card users work out-of-the-box. If not, the following section might help.
[edit] alsaconf
The tool alsaconf(part of media-sound/alsa-utils) is probably the easiest way to configure your sound devices. It will try to detect your sound cards and then update v/etc/modprobe.d/alsa accordingly. So run as root:
[edit] Permissions
Users who want to have access to the sound card need to be in the audio group.
Replace <username> with the user you wish to grant access. If you are adding your user to the group, remember that you must log out and back in again before the changes will take effect.
[edit] Mixer
Most window managers have a mixer which interfaces directly with ALSA. Alternatively you can use alsamixer. If you only have one sound card:
To unmute channels use the m key.
If multiple:
ALSA sound cards start with 0, so 0 is the first card, 1 is the second card, etc.
[edit] Troubleshooting
[edit] Default Sound Device
If you have several sound devices you might want to set one as the default. Start with finding the (ALSA-)name of the device you want to set using the aplay command with the --list(list devices) argument. Note that aplay -l output more than we need here, so we grep for cards:
In the following example we find a Intel card and a SoundBlaster Live! card:
card 0: Live [SB Live! 5.1], device 0: emu10k1 [ADC Capture/Standard PCM Playback] card 0: Live [SB Live! 5.1], device 2: emu10k1 efx [Multichannel Capture/PT Playback] card 0: Live [SB Live! 5.1], device 3: emu10k1 [Multichannel Playback] card 2: nForce2 [NVidia nForce2], device 0: Intel ICH [NVidia nForce2] card 2: nForce2 [NVidia nForce2], device 2: Intel ICH - IEC958 [NVidia nForce2 - IEC958]
Don't mind that cards appear more than once here, we are just after the names, being in this case, marked bold in the example above, Live and nForce2. Now open /etc/asound.conf and add:
pcm.!default { type hw card Live }
ctl.!default { type hw card Live }
This sets the PCM and mixer devices of the SoundBlaster Live! card as the defaults. You'll need to restart any applications using ALSA for playback for this to take effect.
[edit] MIDI for Soundblaster Live! and Audigy
This section assumes you have audio working using the emu10k1 alsa module. First you need to grab one or more soundfonts. They are suffixed with .sf2, and may be compressed using a special lossless compression tool. Soundfonts can conveniently be found, gzipped, at here.
Install awesfx, a tool to load the soundfont(s):
To load soundfonts, use the asfxload command:
If you have more than one, add additional sound fonts with the -N option:
To see what ports you've got for midi, run aplaymidi with the -l switch:
Port Client name Port name 20:0 SB Live! 5.1 EMU10K1 MPU-401 (UART) 21:0 Emu10k1 WaveTable Emu10k1 Port 0 21:1 Emu10k1 WaveTable Emu10k1 Port 1 21:2 Emu10k1 WaveTable Emu10k1 Port 2 21:3 Emu10k1 WaveTable Emu10k1 Port 3
In this case the ports are 21:0 - 21:3. Theres also 20:0, but that is just a pass through to an external port that you probably don't have. Export these ports:
Playing music should now work:
If it works as it should, all that's left is to automate the process. It would probably be best to make a new rc script in /etc/init.d/: Here are working examples of /etc/init.d/emu10k1midi and /etc/env.d/99emu10kmidi:
SOUNDFONT_DIR=/usr/share/soundfonts
depend() {
need alsasound
after modules alsasound
}
start() {
ebegin "Starting MIDI services for SoundBlaster Live"
if lsmod | grep emu10k1 > /dev/null; then
einfo "Loading Sound Fonts in $FONT_DIR"
find $SOUNDFONT_DIR -name '*.sf2' -print -exec asfxload -N {} \; ||\
eerror "Unable to load Soundfont"
einfo "Sound Font(s) loaded"
else
eerror "emu10k1 module not loaded. Unable to Load Soundfonts"
fi
eend 0
}
stop() {
einfo "Unloading Sound Font samples"
asfxload -i
eend 0
}
restart() {
svc_stop
svc_start
}
#!/bin/sh
ALSA_OUTPUT_PORTS=$(aplaymidi -l | awk '/Emu10k1 WaveTable/ {print $1}')
