Gentoo Linux ALSA Guide
1. Introduction
ALSA, which stands for Advanced Linux Sound Architecture, provides audio and MIDI (Musical Instrument Digital Interface) functionality to the Linux operating system. ALSA is the default sound subsystem in the 2.6 kernel thereby replacing OSS (Open Sound System), which was used in the 2.4 kernels.
ALSA's main features include efficient support for all types of audio interfaces ranging from consumer sound cards to professional sound equipment, fully modularized drivers, SMP and thread safety, backward compatibility with OSS and a user-space library alsa-lib to make application development a breeze.
One of Gentoo's main strengths lies in giving the user maximum control over how a system is installed/configured. ALSA on Gentoo follows the same principle. There are two ways you can get ALSA support up and running on your system. We shall look at them in detail in the next chapter.
2. Installing ALSA
Warning: The methods shown below are mutually exclusive. You cannot have ALSA compiled in your kernel and use media-sound/alsa-driver. It will fail. |
The two options are:
- Use ALSA provided by your kernel. This is the preferred/recommended method.
- Use Gentoo's media-sound/alsa-driver package.
The in-kernel drivers and the alsa-driver package can vary a little; it's possible that features and fixes found in one might not yet be incorporated into the other. The upstream developers are aware of this, but the two drivers are effectively separate branches of the ALSA project; they are not entirely identical. You should be aware that they might function slightly differently, so if one doesn't work for you, try the other! We shall take a peek into both before finally deciding on one.
If you were to use ALSA provided by the kernel, the following are the pros and cons:
Kernel ALSA | Pros and Cons |
+ | No need to emerge yet another package; drivers are integrated into kernel. |
+ | One shot solution, no repeating emerges. |
- | Might be a slightly different version than alsa-driver. |
And, if you were to use alsa-driver,
alsa-driver | Pros and Cons |
+ | Possibly the latest drivers from the ALSA Project. |
+ | Useful if you intend to develop audio drivers. |
- | Every kernel recompile requires a re-emerge of alsa-driver. |
- | Needs certain kernel config options disabled to work correctly. |
The differences between alsa-driver and the in-kernel ALSA drivers are quite subtle, as mentioned earlier. Since there are not any huge differences, you are encouraged to go through the process of using the ALSA provided by the kernel first for ease of use. Before reporting any sound related issues to Gentoo Bugzilla, please try to reproduce them using alsa-driver and file the bug report no matter what the result.
Whichever method of install you choose, you need to know what drivers your sound card uses. In most cases, sound cards (onboard and otherwise) are PCI based and lspci will help you in digging out the required information. Please emerge sys-apps/pciutils to get lspci, if you don't have it installed already. In case you have a USB sound card, lsusb from sys-apps/usbutils might be of help. For ISA cards, try using sys-apps/isapnptools. Also, the following pages may help users with ISA based sound cards:
Note: For ease of use/explanation, we assume the user has a PCI based sound card for the remainder of this guide. |
We now proceed to find out details about the sound card.
Code Listing 2.1: Soundcard Details |
# lspci -v | grep -i audio |
We now know that the sound card on the machine is a Sound Blaster Live! and the card manufacturer is Creative Labs. Head over to the ALSA Soundcard Matrix page and select Creative Labs from the list. You will be taken to the Creative Labs matrix page where you can see that the SB Live! uses the emu10k1 module. That is the information we need for now. If you are interested in detailed information, you can click on the link next to the "Details" and that will take you to the emu10k1 specific page.
If you intend to use MIDI, then you should add midi to your USE flags in /etc/make.conf before emerging any ALSA packages. Later in the guide, we will show you how to set up MIDI support.
Using ALSA provided by your Kernel
If you're a person who likes to keep things simple, then this is the way to go.
Note: Since the 2005.0 release, Gentoo Linux uses 2.6 as the default kernel. Please check that your kernel is a 2.6 series kernel. This method will not work on a 2.4 kernel. |
Let us now configure the kernel to enable ALSA.
Important: genkernel users should now run genkernel --menuconfig all and then follow the instructions in Kernel Options for ALSA. |
Code Listing 2.2: Heading over to the source |
# cd /usr/src/linux |
Note: The above example assumes that /usr/src/linux symlink points to the kernel sources you want to use. Please ensure the same before proceeding. |
Now we will look at some of the options we will have to enable in the 2.6 kernel to ensure proper ALSA support for our sound card.
Please note that for ease of use, all examples show ALSA built as modules. It is advisable to follow the same as it then allows the use of alsaconf which is a boon when you want to configure your card. Please do not skip the Configuration section of this document. If you still like to have options built-in, ensure that you make changes to your config accordingly.
Code Listing 2.3: Kernel Options for ALSA |
Device Drivers ---> |
Now that your options are set, you can (re)compile the kernel and ALSA support for your card should be functional once you reboot into the new kernel. Don't forget to update your GRUB configuration to use the newly built kernel. You can now proceed to ALSA Utilities and see if everything is working as it should.
So you've decided to go the alsa-driver way. Let's get started then. There are a few minor things to be done to ensure only the drivers for your sound card are compiled. Although this is not really necessary, it cuts down on the unnecessary drivers that will be compiled otherwise.
If you don't have an idea of what drivers your sound card might need, please take a look at the lspci section of this guide. Once you have your driver name (emu10k1 in our example), edit /etc/make.conf and add a variable, ALSA_CARDS.
Code Listing 2.4: Adding ALSA_CARDS to make.conf |
(For one sound card) |
If you have compiled your kernel and want to use alsa-driver, please ensure the following before proceeding, else alsa-driver is likely to fail. The next code listing gives you one way of performing the checks.
Note: genkernel users can proceed with Installing alsa-driver as their configuration is in sync with the one shown below by default. |
- CONFIG_SOUND is set. (Basic Sound support enabled)
- CONFIG_SOUND_PRIME is not set. (In-built OSS support disabled)
- CONFIG_SND is not set. (In-built ALSA support disabled)
- /usr/src/linux points to the kernel you want ALSA working on.
Code Listing 2.5: .config checks |
(Assuming the linux symlink points to the correct kernel) |
Now all you have to do is type the magic words... and no, it's not abracadabra.
Code Listing 2.6: Installing alsa-driver |
# emerge alsa-driver
|
Important: Please note that you will have to run emerge alsa-driver after every kernel (re)compile, as the earlier drivers are deleted. To make this task easier, you may want to emerge the module-rebuild package, which will keep track of module packages and rebuild them for you. First run module-rebuild populate to create the list, and then after every kernel (re)compile, you just run module-rebuild rebuild, and your external modules will be rebuilt. |
3. Configuring/Testing ALSA
alsa-utils forms an integral part of ALSA as it has a truckload of programs that are highly useful, including the ALSA Initscripts. Hence we strongly recommend that you install alsa-utils
Code Listing 3.1: Install alsa-utils |
# emerge alsa-utils
|
Note: If you activated ALSA in your kernel and did not compile ALSA as modules, please proceed to the ALSA Initscript section. The rest of you need to configure ALSA. This is made very easy by the existence of the alsaconf tool provided by alsa-utils. |
Recent versions of udev (>=udev-103) provide some degree of kernel-level autoconfiguration of your sound card. If possible, try to rely on just letting your kernel automatically setup your sound card for you. Otherwise, use alsaconf to configure your card, as shown below.
Note: Please shut down any programs that might access the sound card while running alsaconf. |
To configure your sound card just type alsaconf in a shell as root.
Code Listing 3.2: Invoking alsaconf |
# alsaconf
|
You will now see a neat menu guided interface that will automatically probe your devices and try to find out your sound card. You will be asked to pick your sound card from a list. Once that's done, it will ask you permission to automatically make required changes to /etc/modules.d/alsa. It will then adjust your volume settings to optimum levels, run update-modules and start the /etc/init.d/alsasound service. Once alsaconf exits, you can proceed with setting up the ALSA initscript.
We're now almost all setup. Whichever method you chose to install ALSA, you'll need to have something load your modules or initialize ALSA and restore your volume settings when your system comes up. The ALSA Initscript handles all of this for you and is called alsasound. Add it to the boot runlevel.
Code Listing 3.3: Adding ALSA to the boot runlevel |
# rc-update add alsasound boot |
Next, just check the /etc/conf.d/alsasound file and ensure that SAVE_ON_STOP variable is set to yes. This saves your sound settings when you shutdown your system.
Before we move on to testing, there's one last important thing that needs to be setup. Rule of thumb in a *nix OS: Do not run as root unless needed. This applies here as well ;) How? Well, most of the times you should be logged in as a user and would like to listen to music or access your soundcard. For that to happen, you need to be in the "audio" group. At this point, we'll add users to the audio group, so that they won't have any issues when they want to access sound devices. We'll use gpasswd here and you need to be logged in as root for this to work.
Code Listing 3.4: Adding users to the audio group |
(Substitute <username> with your user) |
We've completed all the setups and prerequisites, so let's fire up ALSA. If you ran alsaconf, you can skip this step, since alsaconf already does this for you.
Code Listing 3.5: Start the service |
# /etc/init.d/alsasound start
|
Now that the required things have been taken care of, we need to check up on the volume as in certain cases, it is muted. We use alsamixer for this purpose.
Code Listing 3.6: Starting alsamixer |
(Opens up a console program. Only required settings are shown) |
Important: If you have issues starting up alsamixer and get errors such as alsamixer: function snd_ctl_open failed for default: No such file or directory, this is usually an issue with udev setting up the devices. Run killall udevd; udevstart to reload /dev entries and fire up alsamixer. It should solve the issue. |
This is how the ALSA Mixer might look the first time you open it. Pay attention to the Master and PCM channels which both have an MM below them. That means they are muted. If you try to play anything with alsamixer in this state, you will not hear anything on your speakers.
Figure 3.1: The Alsa Mixer Main Window, Muted |
Now, we shall unmute the channels, and set volume levels as needed.
Warning: Both Master and PCM need to be unmuted and set to audible volume levels if you want to hear some output on your speakers. |
- To move between channels, use your left and right arrow keys. (<- & ->)
- To toggle mute, move to the specific channel, for example Master and press the m key on the keyboard.
- To increase and decrease the volume levels, use the up and down arrow keys respectively.
Note: Be careful when setting your Bass and Treble values. 50 is usually a good number for both. Extremely high values of Bass may cause jarring on speakers that are not designed to handle them. |
After you're all done, your ALSA Mixer should look similar to the one below. Note the 00 instead of the MM and also the volume levels for some optimum settings.
Figure 3.2: Alsa Mixer ready to roll |
Finally. Some music. If everything above is perfect, you should now be able to listen to some good music. A quick way to test is to use a command line tool like media-sound/madplay. You could also use something more well known like mpg123. If you are an ogg fan, you could use ogg123 provided by media-sound/vorbis-tools. Use any player you are comfortable with. As always, emerge what you need.
Code Listing 3.7: Getting the software |
(Install the applications you want) |
And then play your favorite sound track...
Code Listing 3.8: Playing Music |
# madplay -v /mnt/shyam/Music/Paul\ Oakenfold\ -\ Dread\ Rock.mp3 |
You can now add the alsa use flag to /etc/make.conf to ensure that your applications that support ALSA get built with it. Some architectures like x86 and amd64 have the flag enabled by default.
If for some reason you're unable to hear sound, the first thing to do would be to check your alsamixer settings. 80% of the issues lie with muted channels or low volume. Also check your Window Manager's sound applet and verify that volumes are set to audible levels.
/proc is your friend. And in this case, /proc/asound is your best friend. We shall just take a short look at how much info is made available to us there.
Code Listing 3.9: Fun with /proc/asound |
(First and foremost, if /proc/asound/cards shows your card, ALSA has |
The other most common issue users face is the dreaded "Unknown symbol in module" error. An example of the same is shown below.
Code Listing 3.10: Unknown Symbol in module error |
# /etc/init.d/alsasound start |
And when you take a look at dmesg as suggested, you're quite likely to see:
Code Listing 3.11: dmesg output |
(Only relevant portions are shown below) |
The above issue is caused when you switch from alsa-driver to in-kernel ALSA because when you unmerge alsa-driver the module files are config protected and hence get left behind. So, when you switch to in-kernel drivers, running modprobe gives you a mix of alsa-driver and in-kernel modules thus causing the above errors.
The solution is quite easy. We just need to manually remove the problem causing directory after you unmerge alsa-driver. Be sure to remove the correct kernel version and not the current one!
Code Listing 3.12: Removing the alsa-driver modules |
# rm -rf /lib/modules/$(uname -r)/alsa-driver
|
Another reason for error messages similar to the ones above could be a file in /etc/modules.d supplying a device_mode parameter when it isn't required. Confirm that this is indeed the issue and find out which file is the culprit.
Code Listing 3.13: Confirming and searching for device_mode |
(Check dmesg to confirm) |
Usually it is a file called alsa with the line options snd device_mode=0666. Remove this line and restart the alsasound service and that should take care of this issue.
4. Other things ALSA
First, check to make sure that you enabled the midi USE flag in /etc/make.conf. If you didn't, go ahead and add it now. You will also need to re-emerge any ALSA packages that use the midi flag, such as alsa-lib, alsa-utils, and alsa-driver.
If your sound card is one of those that come with on-board MIDI synthesizers and you would like to listen to some .mid files, you have to install awesfx which is basically a set of utilities for controlling the AWE32 driver. We need to install it first. If you don't have a hardware synthesizer, you can use a virtual one. Please see the section on Virtual Synthesizers for more information.
Code Listing 4.1: Installing awesfx |
# emerge awesfx
|
Note: You will need to copy over SoundFont (SF2) files from your sound card's driver CD or a Windows installation into /usr/share/sounds/sf2/. For example a sound font file for the Creative SBLive! card would be 8MBGMSFX.SF2. |
After copying over the Soundfont files, we can then play a midi file as shown. You can also add the asfxload command to /etc/conf.d/local.start, so that the sound font is loaded every time the system starts up.
Note: /mnt paths mentioned in the code listing(s) below will not be the same in your machine. They are just an example. Please be careful to change the path to suit your machine. |
Code Listing 4.2: Loading Soundfonts |
(First, copy the Soundfont) |
You can now play midi files using a program like aplaymidi. Run aplaymidi -l to get a list of available ports and then pick one to play the file on.
Code Listing 4.3: Playing MIDI |
(Check open ports) |
If your sound card lacks a hardware synthesizer, you could use a virtual one like timidity++. Installation is a breeze.
Code Listing 4.4: Installing timidity++ |
# emerge timidity++
|
For timidity to play sounds, it needs a sound font. Fortunately, the ebuild will install some sound font packages for you. There are a few other font packages available in Portage, such as timidity-freepats and timidity-eawpatches. You can have multiple sound font configurations installed, and you can place your own in /usr/share/timidity/. To switch between different timidity configurations, you should use eselect.
Code Listing 4.5: Changing configurations |
# eselect timidity list |
Don't forget to add timidity to the default runlevel.
Code Listing 4.6: Adding timidity to the default runlevel |
# rc-update add timidity default |
You can now try out Playing MIDI files.
Some specific sound cards can benefit from certain tools provided by the alsa-tools and alsa-firmware packages. You may install either with a simple emerge.
Code Listing 4.7: Installing ALSA Tools |
# emerge alsa-tools
|
You can have more than one sound card in your system simultaneously, provided that you have built ALSA as modules in your kernel (or have installed alsa-driver instead). You just need to specify which should be started first in /etc/modules.d/alsa. Your cards are identified by their driver names inside this file. 0 is the first card, 1 is the second, and so on. Here's an example for a system with two sound cards.
Code Listing 4.8: Two sound cards in /etc/modules.d/alsa |
options snd-emu10k1 index=0 |
Or, if you have two cards that use the same driver, you specify them on the same line, using comma-separated numbers. Here's an example for a system with three sound cards, two of which are the same Intel High Definition Audio card.
Code Listing 4.9: Multiple sound cards in /etc/modules.d/alsa |
options snd-ymfpci index=0 |
You may want to install some plugins for extra functionality. alsa-plugins is a collection of useful plugins, which include: PulseAudio output, a sample rate converter, jack (a low-latency audio server), and an encoder that lets you output 6-channel audio through digital S/PDIF connections (both optical and coaxial). You can choose which of its plugins you want installed by adding their USE flags to /etc/portage/package.use.
Code Listing 4.10: Installing alsa-plugins |
# emerge -avt alsa-plugins
|
Everyone who contributed to the earlier version of the Gentoo ALSA Guide: Vincent Verleye, Grant Goodyear, Arcady Genkin, Jeremy Huddleston, John P. Davis, Sven Vermeulen, Benny Chuang, Tiemo Kieft and Erwin.
# lspci -v | grep -i audio
00:14.5 Multimedia audio controller: ATI Technologies Inc IXP SB400 AC'97 Audio Controller (rev 02)
# /etc/make.conf
ALSA_CARDS="atiixp"
출처 : http://www.gentoo.org/doc/en/alsa-guide.xml#doc_chap2_pre3
'Study > Linux' 카테고리의 다른 글
Gnomem KDE 단축키 (0) | 2008.01.18 |
---|---|
MY System Infomation (0) | 2008.01.17 |
시스템 마운트 (0) | 2007.12.03 |
하드 디스크 마운트 (0) | 2007.12.03 |
리눅스 데몬의 종류와 정의 (0) | 2007.12.03 |