Differences between revisions 132 and 133
Revision 132 as of 2019-09-20 17:56:34
Size: 8727
Editor: nodiscc
Comment: rm dead link, all project homepage
Revision 133 as of 2021-01-31 11:38:29
Size: 7477
Comment: Attempt to modernize article. It's 2021 and a history lesson on OSS, as well as any information regarding it, is long-past obsolete. Rewrite a lot of everything.
Deletions are marked like this. Additions are marked like this.
Line 6: Line 6:
 . '''[[WikiPedia:Advanced_Linux_Sound_Architecture|Advanced Linux Sound Architecture (ALSA)]]''' is a part of the Linux kernel that provides an interface (API) for [[Sound|sound]] card device drivers. ALSA handles automatic configuration of sound-card hardware and multiple sound devices.  . '''[[WikiPedia:Advanced_Linux_Sound_Architecture|Advanced Linux Sound Architecture (ALSA)]]''' is a software framework and part of the Linux kernel that provides an application programming interface (API) for [[Sound|sound]] card device drivers.
Line 8: Line 8:
Put simply, ALSA can be divided into two components: The kernel API that
provides access to your sound card for higher-level sound servers and applications,
and a userspace library that provides more general functions (like effects, mixing, routing, etc.)
Line 9: Line 12:
There is no way to "replace" ALSA, with regards to the kernel API. Previously,
there was also OSS (Open Sound System), but that's been deprecated for nearly 20 years.
The same is not true of ALSA's userspace library, which can be replaced.
Line 10: Line 16:
The sound servers [[PulseAudio]] and [[JACK]] work on top of ALSA and implemented sound card device drivers. On Linux systems, ALSA succeeded the older Open Sound System (OSS). A sound server will sit between ALSA and your applications. These will traditionally
be [[PulseAudio]] (for easy and automatic audio), [[JACK]] (for professional-grade
low-latency audio), or [[PipeWire]] (for any use-case, but is still experimental). A
sound server is not ''necessary'' as applications can output sound to ALSA directly,
but some applications will make use of a sound server's API and require it to be
available in order to produce sound. Most infamously, [[Firefox]] does not support
ALSA directly and instead uses the !PulseAudio API, forcing usage of !PulseAudio (or
a compatibility layer) as well.
Line 12: Line 25:
!PulseAudio will, by default, take control of all ALSA devices and redirect all
audio streams to itself. PipeWire, if configured to do so, will use a small subset
of the core ALSA functionality in the kernel API to access your soundcard, and
handle all other features itself (replacing the ALSA userspace library entirely).
Line 13: Line 30:
The rest of this article will assume that you are ''not'' using an intermediary
sound server and that you're using ALSA exclusively. This is very uncommon these
days, though it still may be of interest to some. If you're a typical end-user,
you're probably more interested in the page for the sound server you're
using (likely [[PulseAudio]])
Line 14: Line 36:
{{{#!wiki warning
This page is outdated. 2017-09-30
<<TableOfContents(3)>>

= Packages =
 * DebianPkg:libasound2 - This package contains the ALSA userspace library and its standard plugins, as well as the required configuration files.
 * DebianPkg:libasound2-plugins - This package contains additional plugins for the ALSA userspace library, including rate converters, and upmixing/downmixing plugins. You almost definitely want to install this in a pure-ALSA environment.
 * DebianPkg:libasound2-doc - This package contains the HTML documentation for the ALSA library, which describes the development API for user-space applications that want to use ALSA.
 * DebianPkg:alsa-utils - A handful of CLI tools for configuring and using ALSA in userspace. See the package description for specifics.
 * DebianPkg:alsa-oss - ALSA wrapper for legacy OSS applications.
 * DebianPkg:alsamixergui - A GUI frontend for the alsamixer application.
 * DebianPkg:apulse - !PulseAudio API emulation for ALSA. Necessary for running [[Firefox]] and other applications that make use of PulseAudio directly, if running a pure-ALSA configuration.
 * DebianPkg:alsa-firmware-loaders - Requires the contrib component of Debian to be enabled. May assist in making some specific audio hardware functional.

== Loading modules ==
ALSA should "just work", with udev identifying your hardware and loading the
appropriate driver whenever you boot or whenever the audio device is connected,
making sound immediately functionable and configurable through utilities such as
alsamixer.

Users have sometimes needed to manually initialize ALSA before their sound
would work. You would accomplish this by running:
{{{
# alsactl init
Line 18: Line 60:
<<TableOfContents(3)>>
= ALSA 2015-11-01 =
ALSA, the Advanced Linux Sound Architecture, is both a project and a body of software. The project was started because the [[OSS]] architecture is technically weak in some respects, and the free variant of OSS lacks some drivers available only in the commercial variant. For several years the ALSA software was developed separately from Linux. The drivers were added to the Linux codebase during the 2.5 development series and became the standard sound driver system in Linux '''2.6.'''
== Test ==
You can test sound output using any player and any audio file. Something
traditional would be {{{aplay}}} which is helpfully available in the
DebianPkg:alsa-utils package, however it only supports uncompressed WAV files.
You probably want to use something like DebianPkg:mpv instead, which should
handle anything, and can still run headless.
Line 22: Line 67:
ALSA is not just a set of [[sound]] drivers; it is also a library with an extensible API that gives applications access to the latest features of sound cards (e.g., multiple sound channels, Dolby AC3, etc.). ALSA provides efficient support for many applications, is fully modularized, is SMP and thread-safe. There is also a generic white noise file
included with ALSA if you don't care about testing fidelity or accuracy
using audio (such as music) that you're familiar with, and just want to ensure
output works. You can play it with:
{{{
$ aplay /usr/share/sounds/alsa/Noise.wav}}}
Line 24: Line 74:
Applications written for OSS can be made to work with ALSA by means of either userspace emulation (using the [[http://alsa.opensrc.org/index.php?page=alsa-oss|aoss]] program loader) or kernelspace emulation (the snd-*-oss drivers). However, you cannot use both ALSA and OSS ''drivers'' at the same time. ALSA has a MIDI implementation in the case that you have any hardware MIDI ports.
You can use {{{aplaymidi}}} to play input from one of those ports.
Line 26: Line 77:
N.B. ALSA driver names always start with '''snd-''' . == Configuration ==
You can find ALSA configuration files in the {{{/etc/alsa/conf.d/}}} directory. A
lot of files are already included here by default. Advanced features such as mixing
should already be configured with sane defaults. If you want to make changes, add a
new file in here.
Line 28: Line 83:
== Packages ==
 * DebPkg:Libasound2
 * DebPkg:Libasound2-doc
 * DebPkg:Alsa-base
 * DebPkg:Alsa-utils
 * DebPkg:Alsa-oss
 * DebPkg:Alsamixergui
== Troubleshooting ==
=== No sound output ===
If you can't get any output at all, make sure your user is in the "audio" group,
then relog. You can add your user to the group by running:
{{{
# adduser yourusername audio
}}}
Replacing "yourusername" with your actual username.
Line 36: Line 92:
== Loading modules ==
alsa-base packages are designed to "just" work. The alsa-base package does not load modules; instead, [[udev]] detects the sound hardware and loads the right ALSA modules and then alsa-base takes care of setting usable mixer levels.

Configure alsa by running the command '{{{alsactl init}}}' as root. Then reboot and try to test your sound. For more details please see [[http://forums.debian.net/viewtopic.php?f=6&t=39116|this thread]].

You can also try to detect and configure your sound card manually.

 * If you have a PCI soundcard, do a '[[HowToIdentifyADevice/PCI#lspci|lspci]] -v' to list all available pci devices. The list will most probably include a reference to a multimedia audio device: that is your SoundCard.
 * For a USB card, use [[lsusb]].

You could now have a look at the [[http://www.alsa-project.org/main/index.php/Matrix:Main|ALSA's soundcard-matrix]] to find out which driver name can be used for the chipset you found.

== ALSA and OSS ==
If your system is already configured to load OSS drivers for your sound card then look at your current module loader configuration files. There will be entries for the OSS modules which will give you clues about which chipsets your sound cards have. Don't forget to disable these entries before reconfiguring things to load ALSA modules.

If you don't unload all OSS modules then ALSA modules will not be able to initialise (or work properly) because the OSS driver will be futzing with the sound hardware that the ALSA driver needs to control. If you see a message about "sound card not detected" and you are sure you have the right ALSA driver, the presence of an OSS module could be the reason.

== Test ==
Test the driver, using aplay or xmms for example.

To test midi, you can use aplaymidi.

== Sharing a card among multiple processes ==
It is often desirable to be able to share a sound card among several processes running at the same time. This requires the ability to mix the sound outputs of those processes into a single stream.

If your cheap sound card doesn't support hardware mixing try the dmix plugin. This has been set up automatically since libasound2 version 1.0.10-2; in prior versions, look at {{{/usr/share/doc/libasound2/examples/asound.conf_dmix}}} to see how to enable DMIX in {{{/etc/asound.conf}}} (for all users) or {{{~.asoundrc}}} (for your user).

An example .asoundrc for modern laptops that have one HDMI and a simple soundcard in the wrong order would be (use aplay -l first to get proper names for your cards):
=== Wrong card used by default ===
To see what indexes have been assigned to cards, run:
Line 66: Line 95:
defaults.pcm.!card Generic_1
defaults.ctl.!card Generic_1
defaults.pcm.!device 0
defaults.ctl.!device 0
$ cat /proc/asound/cards
Line 72: Line 98:
== Alternative Method ==
If your sound card has a Realtek chipset, and you cannot get sound to work, try the following method:

1. Download the Realtek HD Audio Codec Driver. Follow the link on http://www.realtek.com.tw homepage under "Quick Links", accept the notice, and then download the appropriate driver for Linux.

2. Open the downloaded file, extract it to a location (for example, your home directory), open a root terminal, and compile it as usual.

{{{
./configure
make
make install
}}}


Note:

1. Make sure you already have the necessary build environment (gcc, make, build-essential, linux-headers for your kernel, etc.) set up before running the install script above.

2. If you encounter errors, read the INSTALL file and edit the appropriate configuration files accordingly.

== Troubleshooting ==
To see what indexes have been assigned to cards, run:
{{{
  cat /proc/asound/cards
}}}

The first card that ALSA finds is usually given index 0 and thus is usually the 'default' sound card. If you are unlucky then the first sound card found is one that it not suitable for playing system sounds. (However an error such as "Unknown PCM default" when playing a sound occurs if the user is not a member of the 'audio' group - run "{{{sudo adduser <username> audio}}}", and then "{{{newgrp}}}" as the user)
The first card that ALSA finds is usually given index 0 and thus is usually
the 'default' sound card. If you are unlucky then the first sound card found
is one that is not suitable for playing system sounds.
Line 112: Line 114:
Does rebooting bypass BIOS and GRUB menu? This could be caused by kexec-tools.  It allows the bypass of BIOS during rebooting and prevent proper initialization of various devices. As root, edit file {{{/etc/default/kexec}}} and update {{{LOAD_KEXEC}}} to: Does rebooting bypass BIOS and GRUB menu? This could be caused by kexec-tools.
It allows the bypass of BIOS during rebooting and prevent proper initialization of
various devices. As root, edit file {{{/etc/default/kexec}}} and update {{{LOAD_KEXEC}}} to:
Line 117: Line 121:
This will allow your BIOS to properly initialize sound and other devices during every reboot. This will allow your BIOS to properly initialize sound and other
devices during every reboot.
Line 121: Line 126:
 * add yourself to the 'audio' group (log out and log in again)
 * use alsamixer and unmute channels and raise levels (also try *muting* some channels like s/pdif & toggle jack sense)
 * arts or esound stopped?
 * OSS modules unloaded?
 * speakers on? and connected??
 * modprobe snd-pcm-oss
 * d
oes "aplay /usr/share/sounds/alsa/Noise.wav" work for root? Test your sound with aplay and a wav so codec issues don't confuse the situation.
 * Disable kexec-tools if working sound is disabled after rebooting/restarting  the OS.



== Version ==
Look at {{{/proc/asound/version}}}.

== Tools ==

 * Alsactl : !AlsaControl
 * Alsamixer : To adjust levels of sound, it uses a Ncurses interface.
 * Aplay : To play a .wav file.
 * Arecord : To record a .wav file.
 * Aconnect : For connections on ALSA sequencer.
 * Is your user in the "audio" group? (See the first troubleshooting section)
 * Use alsamixer and unmute channels and raise levels (also try *muting* some channels like s/pdif & toggle jack sense)
 * Arts or esound stopped?
 * Speakers on? And connected?
 * Does "aplay /usr/share/sounds/alsa/Noise.wav" work for root? Test your sound with aplay and a wav so codec issues don't confuse the situation.
 * Disable kexec-tools if working sound is disabled after rebooting/restarting the OS.
Line 144: Line 134:
For more information, read the {{{README.Debian}}} files in the alsa-base and
alsa-source packages or check out http://www.alsa-project.org and http://alsa.opensrc.org.

##Please note with Debian Sarge my sound card is working right now but I still have NOTHING at {{{/proc/asound}}} though {{{lsmod}}} shows {{{snd_intel8x0}}} and a whole bunch of other sound stuff.
For more information, check out https://www.alsa-project.org and https://alsa.opensrc.org.
Line 154: Line 141:
 * [[http://alsa.opensrc.org/DisableOss|Disable Oss kernel modules]].
Line 156: Line 142:
 * [[http://www.alsa-project.org/~valentyn/#toc5|Alsa-sound-mini-HOWTO]] (obsolete)

Translation(s): English - Français - Italiano - Русский


Put simply, ALSA can be divided into two components: The kernel API that provides access to your sound card for higher-level sound servers and applications, and a userspace library that provides more general functions (like effects, mixing, routing, etc.)

There is no way to "replace" ALSA, with regards to the kernel API. Previously, there was also OSS (Open Sound System), but that's been deprecated for nearly 20 years. The same is not true of ALSA's userspace library, which can be replaced.

A sound server will sit between ALSA and your applications. These will traditionally be PulseAudio (for easy and automatic audio), JACK (for professional-grade low-latency audio), or PipeWire (for any use-case, but is still experimental). A sound server is not necessary as applications can output sound to ALSA directly, but some applications will make use of a sound server's API and require it to be available in order to produce sound. Most infamously, Firefox does not support ALSA directly and instead uses the PulseAudio API, forcing usage of PulseAudio (or a compatibility layer) as well.

PulseAudio will, by default, take control of all ALSA devices and redirect all audio streams to itself. PipeWire, if configured to do so, will use a small subset of the core ALSA functionality in the kernel API to access your soundcard, and handle all other features itself (replacing the ALSA userspace library entirely).

The rest of this article will assume that you are not using an intermediary sound server and that you're using ALSA exclusively. This is very uncommon these days, though it still may be of interest to some. If you're a typical end-user, you're probably more interested in the page for the sound server you're using (likely PulseAudio)

Packages

  • libasound2 - This package contains the ALSA userspace library and its standard plugins, as well as the required configuration files.

  • libasound2-plugins - This package contains additional plugins for the ALSA userspace library, including rate converters, and upmixing/downmixing plugins. You almost definitely want to install this in a pure-ALSA environment.

  • libasound2-doc - This package contains the HTML documentation for the ALSA library, which describes the development API for user-space applications that want to use ALSA.

  • alsa-utils - A handful of CLI tools for configuring and using ALSA in userspace. See the package description for specifics.

  • alsa-oss - ALSA wrapper for legacy OSS applications.

  • alsamixergui - A GUI frontend for the alsamixer application.

  • apulse - PulseAudio API emulation for ALSA. Necessary for running Firefox and other applications that make use of PulseAudio directly, if running a pure-ALSA configuration.

  • alsa-firmware-loaders - Requires the contrib component of Debian to be enabled. May assist in making some specific audio hardware functional.

Loading modules

ALSA should "just work", with udev identifying your hardware and loading the appropriate driver whenever you boot or whenever the audio device is connected, making sound immediately functionable and configurable through utilities such as alsamixer.

Users have sometimes needed to manually initialize ALSA before their sound would work. You would accomplish this by running:

# alsactl init

Test

You can test sound output using any player and any audio file. Something traditional would be aplay which is helpfully available in the alsa-utils package, however it only supports uncompressed WAV files. You probably want to use something like mpv instead, which should handle anything, and can still run headless.

There is also a generic white noise file included with ALSA if you don't care about testing fidelity or accuracy using audio (such as music) that you're familiar with, and just want to ensure output works. You can play it with:

$ aplay /usr/share/sounds/alsa/Noise.wav

ALSA has a MIDI implementation in the case that you have any hardware MIDI ports. You can use aplaymidi to play input from one of those ports.

Configuration

You can find ALSA configuration files in the /etc/alsa/conf.d/ directory. A lot of files are already included here by default. Advanced features such as mixing should already be configured with sane defaults. If you want to make changes, add a new file in here.

Troubleshooting

No sound output

If you can't get any output at all, make sure your user is in the "audio" group, then relog. You can add your user to the group by running:

# adduser yourusername audio

Replacing "yourusername" with your actual username.

Wrong card used by default

To see what indexes have been assigned to cards, run:

$ cat /proc/asound/cards

The first card that ALSA finds is usually given index 0 and thus is usually the 'default' sound card. If you are unlucky then the first sound card found is one that is not suitable for playing system sounds.

There are two ways to fix this problem.

1. Force the cards to load in a different order. I chose this route, and added the following to my /etc/modprobe.d/sound:

  options snd-trident index=0
  options snd-usb-audio index=1

This forces my Trident card to be the default (card 0) and my USB microphone to be card 1.

2. Change the default card by editing /etc/asound.conf or ~/.asoundrc . More info on this Alsa Multiple Cards

Does rebooting bypass BIOS and GRUB menu? This could be caused by kexec-tools. It allows the bypass of BIOS during rebooting and prevent proper initialization of various devices. As root, edit file /etc/default/kexec and update LOAD_KEXEC to:

LOAD_KEXEC=false

This will allow your BIOS to properly initialize sound and other devices during every reboot.

Checklist

  • Is your user in the "audio" group? (See the first troubleshooting section)
  • Use alsamixer and unmute channels and raise levels (also try *muting* some channels like s/pdif & toggle jack sense)

  • Arts or esound stopped?
  • Speakers on? And connected?
  • Does "aplay /usr/share/sounds/alsa/Noise.wav" work for root? Test your sound with aplay and a wav so codec issues don't confuse the situation.
  • Disable kexec-tools if working sound is disabled after rebooting/restarting the OS.

More information

For more information, check out https://www.alsa-project.org and https://alsa.opensrc.org.

See also: AlsaMidi.


CategoryHardware CategorySound