ALSA Configuration

From Elvanör's Technical Wiki
Jump to navigation Jump to search

ALSA

ALSA (Advanced Linux Sound Architecture) is the new Linux sound system, replacing the deprecated OSS. Alsa offers advanced features such as software mixing for audio cards that don't support hardware mixing. It is thus important to get it properly working.

Kernel Installation

  • The first step is to follow the official Gentoo ALSA guide to get ALSA basically installed and working. The ALSA sources are now included in the kernel, which is very nice. In the normal case, it just consists of running:
emerge -a alsa-utils
rc-update add alsasound boot
  • If you have an Intel HDA soundcard (very frequent), you need to build the correct codec on the kernel. Running alsamixer usually gives you the codec used on your card. Without the correct codec, the soundcard will not work.
  • UPDATE: alsamixer can give a wrong codec it seems (or a codec name that is not clear). In that case the best method is to enable ALL codecs at first, then run alsamixer which will give you a different codec name (the right one). You can then disable the unneeded ones.
  • On Gentoo, if you compile the ALSA driver directly in the kernel (not as module), you may need to edit /etc/conf.d/alsasound to change some settings in order to avoid a warning at boot saying that the driver cannot be found / loaded.

USB headsets or microphones

  • You need to compile ALSA support for USB devices in the kernel. After that it will appear as a separate sound device in alsamixer for instance. Be careful that many USB devices (such as webcams) also provide sound recording, so you may end up with quite a few sound devices on the system.

Configuration

  • After that, you need to get dmix working, both for ALSA and for OSS (through ALSA emulation). dmix is a plugin to get software sound mixing. Follow this guide on the Gentoo Wiki. Be careful so that you get dmix working correctly with OSS, else some important applications using OSS (Firefox) won't work properly with ALSA applications (Amarok). On AMD64, make sure the 32-bits ALSA emulation libraries are new enough (last section of the wiki).
  • Note that since version 9, Flash Player uses ALSA. There is no more reason to setup Firefox to use OSS. By the way, Firefox by itself does not know at all about sound.
  • To get audio recording working correctly, you need to unmute levels correctly in alsamixer. You also need to choose the correct input sources. In alsamixer, type tab to get to the capture PCMs, else you don't see them in the basic view. Make sure everything is setup correctly and unmuted. You can then test if your microphone is correctly working by running the command:
arecord -f cd -d 2 -t wav -N test.wav

Be careful to specify a record source such as (hw0:0). Sometimes the default record source will not work.

  • IMPORTANT: you need to set to "Capture" your correct source. This means the word CAPTURE in red should appear below, not "----". To toggle the capture status, hit the space bar. If you don't do that, the mic will be unmuted but the computer won't capture/record the sound.
  • If you use dmix, to record correctly you need to setup the asym plugin and the dsnoop plugin. dsnoop is for input what dmix is for output, eg it should mix several input sources into one. I don't think it is as useful as dmix (the really important thing is to have the asym plugin setup), however I've configured it on my system. For Skype to work with dsnoop you need to add some magic values to your /etc/asound.conf file, as shown below.
  • My sample asound.conf file:
# etc/asound.conf:

# We route OSS through dmix

pcm.dsp0 {
    type plug
    slave.pcm "duplex"
}

ctl.dsp0 {
     type plug
     slave.pcm "duplex"
}

# This is just an alias for hw:0,0

pcm.sound_card {
     type hw
     card 0
     device 0
}

# We route everything through the asym plugin by default

pcm.!default {
     type plug
     slave.pcm "duplex"
}

pcm.duplex {
        type asym
                capture.pcm "input"
                playback.pcm "output"
}

# Dmix plugin

pcm.output {
     type dmix
     ipc_key 1024
     slave.pcm "sound_card"

     slave {
          # This stuff provides some fixes for latency issues.
          # buffer_size should be set for your audio chipset.
          period_time 0
          period_size 1024
          buffer_size 8192
     }

     bindings {
          0 0
          1 1
     }
}

# Dsnoop plugin

pcm.input {
        type dsnoop
                ipc_key 1133
                #slave.pcm "sound_card"
                slave {
      # "Magic" buffer values to get Skype audio to work
      # If these are not set, Skype recording (microphone) WILL NOT WORK.
                pcm "sound_card"
                period_size 256
                periods 16
                buffer_size 16384
                }
        bindings {
        0 0
        1 1
        }
}
  • For Wine to work correctly with ALSA, you apparently need to change some sections, reproduced below:
ctl.!default {
        @args [ CARD ]
        @args.CARD {
                type integer
                default 0
        }

        type hw
        card $CARD
}

pcm.!default {
        @args [ CARD DEVICE ]
        @args.CARD {
                type integer
                default 0
        }
        @args.DEVICE {
                type integer
                default 0
        }
        type plug
        slave.pcm "duplex"
}

Note that it is very important that the ctl.!default has only the CARD argument, and that the pcm.!default has both CARD and DEVICE.

ALSA Input Sources

  • They are located at the end of the playback view. Be sure that the Input Source (the first one) is set to whatever you need. You can switch sources by pressing the 'w' or 'x' keys.

ALSA Mixer Levels

  • Everything marked as IEC958 is for digital sound output / input. You usually don't need this.
  • Analog Mix is *not* necessary for recording with a microphone.

Recent drivers

  • For recent ALSA drivers (1.0.14/1.0.15), everything seems to work better "by default". dmix is activated, Skype and OSS apps just work without any configuration.
  • dsnoop is not yet active by default! This means that recording on the default input source may not work out of the box.

Sound Frameworks

  • Because of a bug in Phonon (present in phonon-4.4.x), the Xine backend does not access correctly the dmix (default ALSA) device. Thus until that bug is resolved it is mandatory to use the gstreamer backend in Phonon (or use PulseAudio).
  • Bug link.