Nepherte (dot) be

Howto: Compile ALSA Drivers

0. Contents

  1. Introduction
  2. Prerequisites
  3. Compilation and Installation
  4. Uninstall
  5. Troubleshooting

1. Introduction

Advanced Linux Sound Architecture, known by the acronym ALSA, is a linux kernel component providing device drivers for sound cards. It replaced the original Open Sound System (OSS) since v2.6 of the linux kernel, while still providing backwards compatibility for it. Among the ALSA features you find:

  • Efficient support for all type of audio interfaces, covering most sound cards from consumer sound cards to professional audio interfaces.
  • Fully modularized sound drivers.
  • SMP and thread-save design.
  • User space library (alsa-lib)

On a side note I have to mention that OSS, now developed by 4Front Technologies, is not a deprecated project at all as some of you may think. The latest version as of writing is OSSv4 and a full alternative for ALSA. You might want to use it if you are using a Creative X-Fi sound card. These sound cards are not supported by alsa yet. OSSv4 on the contrary already supports it with beta drivers.

Most linux distributions, including Ubuntu, have ALSA packages, which you can install/reinstall with the package manager that comes with your distribution. These packages should already have been installed since ALSA is by default the sound component in the kernel as mentioned before. In some cases, the sound on a newly installed or updated system doesn’t work and as a last resort you might have to install the drivers manually. Other sound cards require a later version of ALSA to work. Before you go all the way into freak mode and compile the alsa drivers manually (not that it is hard by the way), I suggest you troubleshoot your current setup first. See the Troubleshooting Section at the end of this guide for more information.

This guide is intended on compiling the alsa drivers manually as a last resort. This should not interfere with the current installed alsa packages. The effects are completely reversible and are explained in the Uninstall Section. Now let’s head on with the actual installation.

2. Prerequisites

Step 1 Download the latest version of the following components from the alsa-project website (do not pick the release candidates unless it is really the first version that includes support for your sound card):

  • alsa-driver
  • alsa-lib
  • alsa-utils

Step 2 Install the required packages and kernel headers:
sudo aptitude install build-essential libncurses-dev gettext linux-headers-`uname -r`

Step 3 Setup the installation directory, navigate to the it, copy and unpack the archives (I will be assuming you have downloaded the archives in your home directory, otherwise replace it with the directory where the packages are located in):
sudo mkdir -p /usr/src/alsa
cd /usr/src/alsa
sudo cp ~/alsa* .
sudo tar xvfj alsa-driver*
sudo tar xvfj alsa-lib*
sudo tar xvfj alsa-utils*

3. Compilation and Installation

Step 4 Look up your sound card in the sound card matrix on the alsa-project site. On the page of your sound card you will find specific information on how to compile alsa for your card. Take note of ./compile –with-cards=<yourmodel> for now. We will use this to configure the alsa driver, the first of three components:
cd alsa-driver*
sudo ./configure --with-cards=<valueyoulookedupearlier> --with-kernel=/usr/src/linux-headers-$(uname -r) --with-sequencer
sudo make
sudo make install

Pay attention to the last output of each command above. Possible errors are always listed as last. There’s no point in continuing if the above didn’t work. ./configure mostly spits out not satisfied package requirements, which we normally did satisfy in the first point.

When no errors occured continue compiling alsa-lib:
cd ../alsa-lib*
sudo ./configure
sudo make
sudo make install

When no errors occurred continue compiling and installing alsa-utils:
cd ../alsa-utils*
sudo make
sudo make install

Step 5 Now go back to the sound card page on the alsa-project website. Somewhere on that page there’s a code section to insert (modprobe) the modules in the kernel somewhat resembling to:
sudo modprobe snd-yourcard ; sudo modprobe snd-pcm-oss ; sudo modprobe snd-mixer-oss ; sudo modprobe snd-seq-oss
Copy and paste that section of the alsa website and paste it into the terminal. Be sure that snd-yourcard matches your sound card.

You should now have sound working for this session. If you don’t have sound, be sure to check that no channels are muted. You can adjust/check your sound channel level with alsamixer from the alsa-utils package:
alsamixerYou can unmute the sound with the m key and raise the volume with the arrow keys.

If you still have no sound, we might correct it with manually specifying the parameters in /etc/modprobe.d/alsa-base. We are doing this later on, so just continue with this guide.

Step 6 To make sure you have sound when you start up your computer again, we will automatically load the correct modules for your sound card (the ones we inserted in the kernel earlier). Open up /etc/modules
gksudo gedit /etc/modules

To see what you have to put in this file, you will have to go to the sound card page on alsa-project again. There’s a section “setting up modprobe and kmod support”. Copy the code and paste it at the bottem of /etc/modules. The code you have to insert resembles to:
# ALSA portion
alias char-major-116 snd
alias snd-card-0 snd-<yourcard>

# module options should go here
<insert the modules we modprobed earlier in here!!!>

# OSS/Free portion
alias char-major-14 soundcore
alias sound-slot-0 snd-card-0

# card #1
alias sound-service-0-0 snd-mixer-oss
alias sound-service-0-1 snd-seq-oss
alias sound-service-0-3 snd-pcm-oss
alias sound-service-0-8 snd-seq-oss
alias sound-service-0-12 snd-pcm-oss

Step 7 Reboot your computer. You should have sound by now. If not, don’t worry. We will manually specify the model of your card in /etc/modprobe.d/alsa-base. This mostly resolves issues with headphone & mic jacks not working. Find out what model of sound card you have:
cat /proc/asound/card0/codec#* | grep Codec

It will return the chipset model of your sound card(s), for example: “Codec: Realtek ALC260″, so your sound card is ALC260. Now browse to the alsa documentation page: “http://www.mjmwired.net/kernel/Documentation/sound/alsa/ALSA-Configuration.txt Search this document for (a part of) your model, for example ALC260. You will find one or more model options resembling to:
hp HP machines
hp-3013 HP machines (3013-variant)
fujitsu Fujitsu S7020
acer Acer TravelMate
basic fixed pin assignment (old default model)
auto auto-config reading BIOS (default)

Pick the one that comes closest to the one you have. Say you have an fujitsu laptop, choose fujutsu. Paste the following at the end of /etc/modprobe.d/alsa-base:
options snd-yourcard model=MODEL

In our example, MODEL is replaced by fujitsu. Now reboot your computer and you should have sound fully functional.

4. Uninstall

You can revert the whole installation process very easily if you still have the /usr/src/alsa folder where we compiled everything. Just type this command in /usr/src/alsa:
cd /usr/src/alsa
sudo make uninstall

5. Troubleshooting

Some cards still might not work after following the steps in this guide. These are very card specific problems and I’m not going to cover them all here. LordRaiden posted a Comprehensive Sound Problem Solutions Guide on the Ubuntu Forums. I suggest you go look into it if you want a complete trouble shooting guide.

Muted channels
Sometimes you just forget that every channel is still muted. Slide the volume up with alsamixer or any other volume manager:
alsamixer

Setting system > preferences > sound
Navigate to system > preferences > sound and explicitly configure it to use PulseAudio or alsa. PulseAudio should normally work as it is a sound server, a background process accepting sound input from one or more sources (processes or capture devices) and redirecting it to one or more sinks, in this case our alsa.

Playing with probe_mask.
A lot of cards suffer from the headphone/mic channel not working. First you have to check if it is enabled. You can do this by right clicking on the sound icon in the notification area, choosing open volume mixer. Choose the switches tab and verify that internal mic is checked. If that is already the case, you could change the options line in /etc/modprobe.d/alsa-base to look something like this:
options snd-yourcard model=MODEL probe_mask=1
You might want to change the number of probe_mask if it doesn’t work rightaway.

Get help
If you still don’t get sound working, you should check dmseg on messages with snd_ entries. Run through the Comprehensive Sound Problem Solutions Guide, open up a new thread on Ubuntu Forums and post the following information:

  • dmesg (or dmesg | grep snd)
  • aplay -l
  • lspci or lsusb (in case you have a usb sound card)
  • your attempts from the problem solutions guide
  • other information or attempts

People will try and help you out with your problem.

Leave a Reply