Difference between revisions of "Advanced Linux Sound Architecture"

From ArchWiki
Jump to navigation Jump to search
Line 50: Line 50:
  
 
===Method 1===
 
===Method 1===
Just run alsaconf as root. When prompted choose the sound card you want to set as default from the list. Alsaconf will automatically write the necessary configuration files to /etc/modprobe.d/
+
Just run <code>alsaconf</code> as root. When prompted choose the sound card you want to set as default from the list. Alsaconf will automatically write the necessary configuration files to /etc/modprobe.d/
  
 
===Method 2===
 
===Method 2===

Revision as of 22:08, 20 June 2009

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n links end

Introduction

The Advanced Linux Sound Architecture (ALSA) is a Linux kernel component intended to provide device drivers for sound cards.

See OSS if you are looking for alternatives.

This document tells how to get ALSA working with 2.6 kernels. Also see how to allow multiple programs to play sound at once.

Installation

Kernel drivers

ALSA has been included in the 2.6 kernels and is included in all arch kernel26* packages. If you build a custom kernel, do not forget to enable the correct ALSA driver.

All necessary modules should be detected and loaded automatically by udev. No special configuration has to be done unless you use ISA cards. NEVER use alsaconf if you have a PCI or ISAPNP sound card, as the entries alsaconf adds to the modprobe.conf file might break udev's autodetection.

Userspace utilities

  • Required for native ALSA programs and administration
# pacman -Sy alsa-lib alsa-utils
  • Recommended if you want to use applications with OSS sound support in combination with dmix:
# pacman -S alsa-oss

All ALSA programs will most likely have alsa-lib as a dependency.

Configuration

Set the default sound card

Multiple sound cards (USB audio, PCI sound cards, integrated cards) can sometimes conflict for the default sound card slot. Here are some methods to define the default card.

Method 1

Just run alsaconf as root. When prompted choose the sound card you want to set as default from the list. Alsaconf will automatically write the necessary configuration files to /etc/modprobe.d/

Method 2

Telephony-capable modems and snd-pcsp (the internal PC speaker ALSA module) can conflict with the sound card for the default sound card slot. (pcspkr is another, non-ALSA PC speaker module. It will not conflict with ALSA sound cards.) To prevent this, discover your sound card model name with lspci(8) and your ALSA driver module names with ls(1):

$ ls -l /sys/module/snd/holders
total 0
lrwxrwxrwx 1 root root 0 2009-06-02 23:49 snd_ac97_codec -> ../../snd_ac97_codec
lrwxrwxrwx 1 root root 0 2009-06-02 23:49 snd_intel8x0 -> ../../snd_intel8x0
lrwxrwxrwx 1 root root 0 2009-06-02 23:49 snd_intel8x0m -> ../../snd_intel8x0m
lrwxrwxrwx 1 root root 0 2009-06-02 23:49 snd_pcm -> ../../snd_pcm
lrwxrwxrwx 1 root root 0 2009-06-02 23:53 snd_pcsp -> ../../snd_pcsp
lrwxrwxrwx 1 root root 0 2009-06-02 23:49 snd_timer -> ../../snd_timer

Then add the name of your sound card module to:

Template:File

This entry ensures that the Intel 82801DB-ICH4 sound card will become card 0. Since the sound card order is module load dependent, an alternative, if less robust method, of loading snd-pcsp last adds the following to:

Template:File

If you do not want snd-pcsp to load at all you can add the following to:

Template:File


Note: You will need to unload all your sound modules and reload them for the changes to take affect. It might be easier to reboot. Your choice.

Making sure the sound modules are loaded

You can assume that udev will autodetect your sound properly, including the OSS compatibility modules. You can check this with the command

$ lsmod|grep '^snd' | column -t
snd_usb_audio          69696  0 
snd_usb_lib            13504  1 snd_usb_audio
snd_rawmidi            20064  1 snd_usb_lib
snd_hwdep               7044  1 snd_usb_audio
snd_seq_oss            29412  0 
snd_seq_midi_event      6080  1 snd_seq_oss
snd_seq                46220  4 snd_seq_oss,snd_seq_midi_event
snd_seq_device          6796  3 snd_rawmidi,snd_seq_oss,snd_seq
snd_pcm_oss            45216  0 
snd_mixer_oss          15232  1 snd_pcm_oss
snd_intel8x0           27932  0 
snd_ac97_codec         87648  1 snd_intel8x0
snd_ac97_bus            1792  1 snd_ac97_codec
snd_pcm                76296  4 snd_usb_audio,snd_pcm_oss,snd_intel8x0,snd_ac97_codec
snd_timer              19780  2 snd_seq,snd_pcm
snd                    43776  12 snd_usb_audio,snd_rawmidi,snd_hwdep,snd_seq_oss,snd_seq,snd_seq_device,snd_pcm_oss,snd_mixer_oss,snd_intel8x0,snd_ac97_codec,snd_pcm,snd_timer
snd_page_alloc          7944  2 snd_intel8x0,snd_pcm

If the output looks similar, your sound drivers have been successfully autodetected (note that in this case, snd_intel8x0 and snd_usb_audio are the drivers for the hardware devices). You might also want to check the directory /dev/snd for the right device files:

$ ls -l /dev/snd
total 0
crw-rw----  1 root audio 116,  0 Apr  8 14:17 controlC0
crw-rw----  1 root audio 116, 32 Apr  8 14:17 controlC1
crw-rw----  1 root audio 116, 24 Apr  8 14:17 pcmC0D0c
crw-rw----  1 root audio 116, 16 Apr  8 14:17 pcmC0D0p
crw-rw----  1 root audio 116, 25 Apr  8 14:17 pcmC0D1c
crw-rw----  1 root audio 116, 56 Apr  8 14:17 pcmC1D0c
crw-rw----  1 root audio 116, 48 Apr  8 14:17 pcmC1D0p
crw-rw----  1 root audio 116,  1 Apr  8 14:17 seq
crw-rw----  1 root audio 116, 33 Apr  8 14:17 timer

If you have at least the devices controlC0 and pcmC0D0p or similar, then your sound modules have been detected and loaded properly.

If this is not the case, your sound modules have not been detected properly. If you want any help on IRC or the forums, please post the output of the above commands. To solve this, you can try loading the modules manually:

  • Locate the module for your soundcard: ALSA Soundcard Matrix The module will be prefixed with 'snd-' (for example: 'snd-via82xx').
  • Load modules:
 # modprobe snd-NAME-OF-MODULE
 # modprobe snd-pcm-oss
  • Check for the device files in /dev/snd (see above) and/or try if alsamixer or amixer have reasonable output.
  • Add snd-NAME-OF-MODULE and snd-pcm-oss to the list of MODULES in Template:Filename to ensure they are loaded next time (make sure snd-NAME-OF-MODULE is before snd-pcm-oss).

Unmute the channels and test

In this section, we assume that you are logged in as root. If you want to perform these steps as an unprivileged user, you have to skip to the next section Setup Permissions first.

  • Unmute Soundcard

The current version of ALSA installs with all channels muted by default, so even if installation completes successfully and all devices are working properly you will hear no sound. You will need to unmute the channels manually. It is recommended to use Template:Codeline to accomplish this. From the alsamixer text ui, the label "MM" below a channel indicates that the channel is muted, and "00" indicates that it is open. Press the 'm' key to toggle MM/00. Use arrow-keys left and right to navigate through the channels and the arrow-keys up and down to adjust the volume. Such things as Master and PCM and possibly Speaker will need to unmuted for your sound to work.

Note: When using Template:Codeline, be sure to unmute as well as bring volumes up to a specific level in percent, i.e you need to use that % sign. Template:Codeline understands the percent sign (%), not numbers. If you use a number (say, 90) then Template:Codeline will take it as 100%, which can harm your speakers.
 # amixer set Master 90% unmute
 # amixer set PCM 85% unmute
  • Try to play a WAV file
 # aplay /usr/share/sounds/alsa/Front_Center.wav
Note: Some cards need to have digital output muted/turned off in order to hear analog sound. For the Soundblaster Audigy LS mute the IEC958 channel.

If you cannot hear anything, double check your mixer settings, being sure to unmute PCM, MASTER (and some machines such as the IBM Thinkpad have an additional 'SPEAKER' channel) and try the alsaconf utility as root:

# alsaconf

Setup Permissions

To be able to use the sound card as a user, follow these steps:

  • Add your user to the audio group:
# gpasswd -a USERNAME audio
  • Log your user out and back in to ensure the audio group is loaded.

Restore ALSA Mixer settings at startup

# alsactl store
  • Edit Template:Filename and add Template:Codeline to the list of daemons to start on boot-up. This will store the mixer settings on every shutdown and restore them when you boot.
  • If the mixer settings are not loaded on boot-up, add the following line to Template:Filename:
# alsactl restore

Getting SPDIF output

(from gralves from the Gentoo forums)

  • In GNOME Volume Control, under the Options tab, change the IEC958 to PCM. This option can be enabled in the preferences.
  • If you don't have GNOME Volume Control installed,
    • Edit /etc/asound.state. This file is where alsasound stores your mixer settings.
    • Find a line that says: 'IEC958 Playback Switch'. Near it you will find a line saying value:false. Change it to value:true.
    • Now find this line: 'IEC958 Playback AC97-SPSA'. Change its value to 0.
    • Restart ALSA.

Alternative way to enable SPDIF output automatically on login (tested on SoundBlaster Audigy):

 # Use COAX-digital output
 amixer set 'IEC958 Optical' 100 unmute
 amixer set 'Audigy Analog/Digital Output Jack' on

You can see the name of your card's digital output with:

 $ amixer scontrols

System-Wide Equalizer

Note: This method requires the use of a ladspa plugin which might use quite a bit of CPU when sound plays. In addition, this was made with stereophonic sound (e.g. headphones) in mind.
  • You will need, in addition to the aforementioned userspace utilities, alsa-plugins.
# pacman -S alsa-plugins
  • Get the ladspa and swh-plugins packages too if you don't already have them.
# pacman -S ladspa swh-plugins
$ vim ~/.asoundrc

Template:File

  • Reload your alsa settings (as root).
# /etc/rc.d/alsa restart
  • You should be good to go (if not, ask in the forum).

Advanced Configuration

For the most part a basic ALSA configuration will get you sound up and running. If you need to do advanced configuration take look at the official Alsa Module Configuration for your kernel and read over the details.

Model Settings

Alsa may have specific model settings for you chipset. The chip can be found in alsamixer (e.g. ALC662) and the model can be set in Template:Filename. For example:

options snd-hda-intel model=MODEL

There are other model settings too. For most cases Alsa defaults will do. If you want to look at more specific settings for your soundcard take a look at the Alsa Soundcard List find your model, then Details, then look at the "Setting up modprobe..." section. Enter these values in Template:Filename. For example, for an Intel AC97 audio:

# ALSA portion
alias char-major-116 snd
alias snd-card-0 snd-intel8x0
# module options should go 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

Troubleshooting

Specify a Specific Model Type

Alsa may have specific model settings for you chipset. This is auto-detected from your BIOS by Alsa but sometimes it needs to specified. The chip can be found in alsamixer (e.g. ALC662) and the model can be set in Template:Filename. For example:

options snd-hda-intel model=MODEL

Conflicting PC Speaker

Remember, ALSA installs with all channels muted by default (see previous section, unmuting your soundcard).

However, if you're sure nothing is muted, that your drivers are installed correctly, and that your volume is right, but you still do not hear anything, then try blacklisting snd-pcsp from your modules array in rc.conf:

MODULES=(!snd-pcsp ... )

Note that this will disable your PC's internal speaker. If that doesn't work, then try adding the following line to /etc/modprobe.conf:

options snd-NAME-OF-MODULE ac97_quirk=0

The above fix has been observed to work with via82xx

options snd-NAME-OF-MODULE ac97_quirk=1

The above fix has been reported to work with snd_intel8x0

No Sound with Onboard Intel Sound Card

There may be an issue with two conflicting modules loaded, namely snd_intel8x0 and snd_intel8x0m. In this case, edit rc.conf and in the MODULES array blacklist the latter one so that it reads !snd_intel8x0m afterwards.

Muting the "External Amplifier" in alsamixer or amixer may also help. See the ALSA wiki.

With Intel Corporation 82801 I (ICH9 Family) HD Audio Controller on laptop, you may need to add this line to

/etc/modprobe.d/sound

options snd-hda-intel model=laptop

or

options snd-hda-intel model=laptop enable=1 index=0

Otherwise, the pcspkr may not work, and only the headphone have sound. See more on model in [1]

Poor Sound Quality?

If you experience poor sound quality, try setting the PCM volume (in alsamixer) to a level such that gain is 0.

Pops when Starting and Stopping Playback?

Some modules can power off your sound card when not in use. this can make an audible noise when powering down your sound card. If you find this annoying try "modinfo snd-MY-MODULE", and look for a module option that adjusts or disables this feature.

for example: to disable the power saving mode using snd-hda-intel add "options snd-hda-intel power_save=0" in /etc/modprobe.conf. or try it with "modprobe snd-hda-intel power_save=0"

Alsamixer does not run

If running alsamixer does not work and you wind up with the following error

alsamixer: function snd_ctl_open failed for default: No such device or directory

You should first check /etc/group to ensure that your current user is in the 'audio' group. Don't forget to log out and log in again for the group changes.

Then you might need to re-install your kernel. Run 'pacman -S kernel26' or whichever patchset you prefer to use.

S/PDIF output does not work

If the optical/coaxial digital output of your motherboard/sound card is not working or stopped working, and have already enabled and unmuted it in alsamixer, try running

iecset audio on

as root.

You can also put this command in rc.local as it sometimes it may stop working after a reboot.

No adjustable PCM channel

You may find that you lack adjustable PCM channel. In this case try to remove all sound-related stuff from MODULES section in /etc/rc.conf, except for snd-NAME-OF-MODULE and snd-pcm-oss.

HP TX2500

Add these 2 lines into Template:Filename:

options snd-cmipci mpu_port=0x330 fm_port=0x388
options snd-hda-intel index=0 model=toshiba position_fix=1

And don't forget to enable 'hal' in the DAEMONS section of your Template:Filename.

options snd-hda-intel model=hp (works for tx2000cto)

Skipping sound when playing MP3's

If you have sound skipping when playing MP3 files and you have more then 2 speakers attacked to your computer (i.e. > 2 speaker system), run alsamixer and disable the channels for the speakers that you DON'T have (i.e. don't enable the sound for the center speaker if you don't have a center speaker

Using a USB Headset

If you are using a USB headset with ALSA you can try using asoundconf (currently only available from the AUR) to set the headset as the primary sound output.

# asoundconf list
# asoundconf set-default-soundcard <chosen soundcard>

KDE Settings

  • Start up KDE:
# startx
  • Set up the volumes as you want them for this user (each user has their own settings):
# alsamixer

Log out and log back in as user xyz to get sound to work (I had to kill X, logout then log back in as user xyz, then start X and open Firefox and bam audio working on YouTube)

  • KDE 3.3: Go to K Menu → Multimedia → KMix
    • Choose Settings → Configure KMix...
    • Uncheck the option "Restore volumes on logon"
    • Press OK, and you should be all set. Now your volumes will be the same from the command line or within KDE.


Example asound.conf

As it can be hard to figure out the right configuration, some (2 or 3?) rather "special needs" examples with comments might be helpful.

surround51 incl. upmix stereo & dmix, swap L/R, bad speaker position in room

Bad practice but works fine for almost everything without additional per-program/file customization:

pcm.!default {
    type route
## forwards to the mixer pcm defined below
    slave.pcm dmix51
    slave.channels 6

## "Native Channels" stereo, swap left/right
    ttable.0.1 1
    ttable.1.0 1
## original normal left/right commented out
#    ttable.0.0 1
#    ttable.1.1 1

## route "native surround" so it still works but weaken signal (+ RL/RF swap) 
## because my rear speakers are more like random than really behind me
    ttable.2.3 0.7
    ttable.3.2 0.7
    ttable.4.4 0.7
    ttable.5.5 0.7

## stereo => quad speaker "upmix" for "rear" speakers + swap L/R
    ttable.0.3 1
    ttable.1.2 1

## stereo L+R => join to Center & Subwoofer 50%/50%
    ttable.0.4 0.5
    ttable.1.4 0.5
    ttable.0.5 0.5
    ttable.1.5 0.5
## to test: "$ speaker-test -c6 -twav" and: "$ speaker-test -c2 -twav"
}

pcm.dmix51 {
	type dmix
	ipc_key 1024
# let multiple users share
	ipc_key_add_uid false 
# IPC permissions (octal, default 0600)
# I think changing this fixed something - but I'm not sure what.
	ipc_perm 0660 # 
	slave {
## this is specific to my hda_intel. Often hd:0 is just allready it; To find: $ aplay -L 
		pcm surround51 
# this rate makes my soundcard crackle
#		rate 44100
# this rate stops flash in firefox from playing audio, but I don't need that
       rate 48000
       channels 6
## Any other values in the 4 lines below seem to make my soundcard crackle, too
       period_time 0
       period_size 1024
       buffer_time 0
       buffer_size 4096
	}
}

External Resources

More info can be found here: