Difference between revisions of "Advanced Linux Sound Architecture"

From ArchWiki
Jump to: navigation, search
m
(Tips and tricks: settings to let laptop's 2-in-1 headset jack detect mic properly)
 
(688 intermediate revisions by more than 100 users not shown)
Line 1: Line 1:
[[Category:Audio/Video (English)]]
+
[[Category:Sound]]
[[Category:HOWTOs (English)]]
+
[[cs:Advanced Linux Sound Architecture]]
{{i18n_links_start}}
+
[[de:Alsa]]
{{i18n_entry|English|ALSA}}
+
[[es:Advanced Linux Sound Architecture]]
{{i18n_entry|Español|ALSA (Español)}}
+
[[fa:ALSA]]
{{i18n_entry|Deutsch|ALSA Einrichten}}
+
[[fr:Alsa]]
{{i18n_entry|Italiano|ALSA (Italiano)}}
+
[[he:Advanced Linux Sound Architecture]]
{{i18n_entry|Nederlands|ALSA instellen}}
+
[[it:Advanced Linux Sound Architecture]]
{{i18n_entry|Русский|ALSA_(Russian)}}
+
[[ja:Advanced Linux Sound Architecture]]
{{i18n_entry|Slovensky|Nastavenie ALSA}}
+
[[nl:Advanced Linux Sound Architecture]]
{{i18n_entry|Česky|ALSA (Česky)}}
+
[[pt:Advanced Linux Sound Architecture]]
{{i18n_entry|简体中文|ALSA 安装设置 (简体中文)}}
+
[[ru:Advanced Linux Sound Architecture]]
{{i18n_entry|עברית|הגדרת ALSA}}
+
[[sk:Advanced Linux Sound Architecture]]
{{i18n_entry|Рolski|ALSA Setup (Polski)}}
+
[[th:Advanced Linux Sound Architecture]]
{{i18n_entry|Português do Brasil|Instalação ALSA}}
+
[[zh-hans:Advanced Linux Sound Architecture]]
{{i18n_entry|ไทย|ALSA Setup (ไทย)}}
+
{{Related articles start}}
{{i18n_entry|Türkçe|ALSA (Türkçe)}}
+
{{Related|Advanced Linux Sound Architecture/Example Configurations}}
{{i18n_entry|Français|ALSA (Français)}}
+
{{Related|Advanced Linux Sound Architecture/Troubleshooting}}
{{i18n_entry|한국어|ALSA (한국어)}}
+
{{Related|Sound system}}
{{i18n_links_end}}
+
{{Related|PC speaker}}
 +
{{Related|PulseAudio}}
 +
{{Related|Open Sound System}}
 +
{{Related articles end}}
 +
The [[Wikipedia:Advanced Linux Sound Architecture|Advanced Linux Sound Architecture]] ('''ALSA''') provides kernel driven sound card drivers. It replaces the original Open Sound System (OSS).
  
The Advanced Linux Sound Architecture (ALSA) is a Linux kernel component intended to provide device drivers for sound cards.
+
Besides the sound device drivers, ALSA also bundles a user space driven library for application developers. They can then use those ALSA drivers for high level API development. This enables direct (kernel) interaction with sound devices through ALSA libraries.
  
This document tells how to get ALSA working with 2.6 kernels. Also see how to [[Allow_multiple_programs_to_play_sound_at_once|allow multiple programs to play sound at once]]
+
== Installation ==
  
See [[OSS]] if you are looking for alternatives.
+
ALSA is a set of built-in GNU/Linux kernel modules. Therefore, manual installation is not necessary.
  
==Installation==
+
[[udev]] will automatically detect your hardware and select needed drivers at boot time, therefore, your sound should already be working. However, your sound may be initially muted. If it is, see [[#Unmuting the channels|Unmuting the channels]].
===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.
+
=== User privileges ===
  
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.
+
Usually, local users have permission to play audio and change mixer levels.
  
===Userspace utilities===
+
To allow remote users to use ALSA, you need to [[Users and groups#Group management|add]] those users to the {{ic|audio}} group.
  
* Required for native ALSA programs and administration
+
{{note|Adding users to the {{ic|audio}} group allows direct access to devices. Keep in mind, that this allows applications to exclusively reserve output devices. This may break software mixing or fast-user-switching on multi-seat systems. Therefore, adding a user to the {{ic|audio}} group is '''not''' recommended by default; unless you specifically need to [https://wiki.ubuntu.com/Audio/TheAudioGroup].}}
# 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.
+
=== ALSA Utilities ===
  
==Configuration==
+
[[Install]] the {{Pkg|alsa-utils}} package. This contains (among other utilities) the {{ic|alsamixer}} and {{ic|amixer}} utilities. ''amixer'' is a shell command to change audio settings, while ''alsamixer'' provides a more intuitive [[Wikipedia:Ncurses|ncurses]] based interface for audio device configuration.
===Set the default sound card===
 
  
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 [http://linux.die.net/man/8/lspci lspci(8)] and your ALSA driver module names with ls(1):
+
If you need [[#High quality resampling|high quality resampling]] install the {{Pkg|alsa-plugins}} package to enable [[#Upmixing/downmixing|upmixing/downmixing]] and other advanced features.
  
$ ls -l /sys/module/snd/holders
+
=== OSS compatibility ===
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 names of your sound card modules to:
+
{{Note|This is important if your application complains about missing {{ic|/dev/dsp}} or {{ic|/dev/snd/seq}}.}}
  
{{file |name=/etc/modprobe.d/modprobe.conf (prior to module-init-tools 3.8, use /etc/modprobe.conf) |content=
+
ALSA has some ability to intercept [[OSS]] calls and re-route them through ALSA instead. This emulation layer is useful e.g. for legacy applications which try to open {{ic|/dev/dsp}} and write sound data to them directly. Without OSS or the emulation library, {{ic|/dev/dsp}} will be missing, and the application will not produce any sound.
options snd-intel8x0 index=0
+
 
options snd-pcsp index=1
+
If you want [[OSS]] applications to work with [[#Dmix|dmix]], install the {{Pkg|alsa-oss}} package as well. Then load the {{ic|snd-seq-oss}}, {{ic|snd-pcm-oss}} and {{ic|snd-mixer-oss}} [[kernel modules]] to enable OSS emulation.
 +
 
 +
=== PulseAudio compatibility ===
 +
 
 +
{{AUR|apulse}} lets you use ALSA for applications that support only [[PulseAudio]] for sound. Usage is simply {{ic|$ apulse ''yourapplication''}}.
 +
 
 +
=== ALSA and Systemd ===
 +
 
 +
The {{Pkg|alsa-utils}} package comes with [[systemd]] unit configuration files {{ic|alsa-restore.service}} and {{ic|alsa-state.service}} by default.
 +
 
 +
These are automatically installed and activated during installation. Therefore, there is no further action needed. Though, you can check their status using {{ic|systemctl}}.
 +
 
 +
{{note|For reference, ALSA stores its settings in {{ic|/var/lib/alsa/asound.state}}}}
 +
 
 +
=== ALSA Firmware ===
 +
 
 +
The {{Pkg|alsa-firmware}} package contains firmware that may be required for certain sound cards (e.g. Creative SB0400 Audigy2).
 +
 
 +
== Unmuting the channels ==
 +
 
 +
By default ALSA has all channels muted. Those have to be unmuted manually.
 +
 
 +
=== Unmute with amixer ===
 +
 
 +
Unmuting the sound card's master volume can be done by using ''amixer'':
 +
 
 +
$ amixer sset Master unmute
 +
 
 +
=== Unmute with alsamixer ===
 +
 
 +
Unmuting the sound card can be done using ''alsamixer'':
 +
 
 +
$ alsamixer
 +
 
 +
The {{ic|MM}} label below a channel indicates that the channel is muted, and {{ic|00}} indicates that it is open.
 +
 
 +
Scroll to the {{ic|Master}} and {{ic|PCM}} channels with the {{ic|←}} and {{ic|→}} keys and unmute them by pressing the {{ic|m}} key.
 +
 
 +
Use the {{ic|↑}} key to increase the volume and obtain a value of {{ic|0}} dB gain. The gain can be found in the upper left next to the {{ic|Item:}} field.
 +
 
 +
{{Note|If gain is set above 0 dB audible distortion can become present.}}
 +
 
 +
=== Unmute 5.1/7.1 sound ===
 +
 
 +
To get full 5.1 or 7.1 surround sound you will likely need to unmute other channels such as {{ic|Front}}, {{ic|Surround}}, {{ic|Center}}, {{ic|LFE}} (subwoofer) and {{ic|Side}}. (Those are channel names with Intel HD Audio, they may vary with different hardware)
 +
 
 +
{{note|Please take note that this will not automatically upmix stereo sources (like most music). In order to accomplish that, see [[#Upmixing/downmixing]].}}
 +
 
 +
=== Enable the microphone ===
 +
 
 +
To enable your microphone, switch to the Capture tab with {{ic|F4}} and enable a channel with {{ic|Space}}. See [[ALSA/Troubleshooting#Microphone]] if microphone does not work.
 +
 
 +
=== Test your changes ===
 +
 
 +
Next, test to see if sound works:
 +
 
 +
$ speaker-test -c 2
 +
 
 +
Change {{ic|-c}} to fit your speaker setup. Use {{ic|-c 8}} for 7.1, for instance:
 +
 
 +
$ speaker-test -c 8
 +
 
 +
If audio is being outputted to the wrong device, try manually specifying it with the  argument {{ic|-D}}.  
 +
 
 +
$ speaker-test -D default:PCH -c 8
 +
 
 +
{{ic|-D}} accepts PCM channel names as values, which can be retrieved by running the following:
 +
 
 +
{{hc|<nowiki>$ aplay -L | grep :CARD</nowiki>|2=
 +
default:CARD=PCH  # 'default:PCH' is the PCM channel name for -D
 +
sysdefault:CARD=PCH
 +
front:CARD=PCH,DEV=0
 +
surround21:CARD=PCH,DEV=0
 +
surround40:CARD=PCH,DEV=0
 +
surround41:CARD=PCH,DEV=0
 +
surround50:CARD=PCH,DEV=0
 +
surround51:CARD=PCH,DEV=0
 +
surround71:CARD=PCH,DEV=0
 
}}
 
}}
  
These entries ensure that the Intel 82801DB-ICH4 sound card will become card 0 and the PC speaker will become card 1.
+
If that does not work, consult the [[#Configuration]] section or the [[ALSA/Troubleshooting]] page.
 +
 
 +
=== Additional notes ===
  
If you do not want snd-pcsp to load at all you can add the following to:
+
* If your system has more than one soundcard, then you can switch between them by pressing {{ic|F6}}
  
{{file |name=/etc/rc.conf |content=MODULES=(... !snd-pcsp)
+
* Some cards need to have digital output muted or disabled in order to hear analog sound. For the Soundblaster Audigy LS mute the channel labeled {{ic|IEC958}}.
}}
 
  
If you want the PC speaker completely been disabled you can additionally add the following to:
+
* Some machines, (like the Thinkpad T61), have a {{ic|Speaker}} channel which must be unmuted and adjusted as well.
  
{{file |name=/etc/rc.conf |content=MODULES=(... !pcspkr)
+
* Some machines, (like the Dell E6400) may also require the {{ic|Front}} and {{ic|Headphone}} channels to be unmuted and adjusted.
}}
 
  
 +
* If your volume adjustments seem to be lost after you reboot, try running ''alsamixer'' as root.
  
{{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. }}
+
== Configuration ==
  
===Making sure the sound modules are loaded===
+
The system configuration file is {{ic|/etc/asound.conf}}, and the per-user configuration file is {{ic|~/.asoundrc}}.
  
You can assume that udev will autodetect your sound properly, including the OSS compatibility modules. You can check this with the command
+
=== Basic syntax ===
  
$ lsmod|grep '^snd' | column -t
+
ALSA configuration files follow a simple syntax consisting of hierarchical value to parameter (key) assignments. Below are (modified) excerpts from asoundrc.txt, which is usually found in {{Pkg|alsa-lib}} package but can be also reached [http://www.alsa-project.org/alsa-doc/alsa-lib/conf.html here].
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:
+
==== Assignments and Separators ====
  
$ ls -l /dev/snd
+
Assignments define a value of a given key. There are different assignment types and styles available.
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.
+
{{hc|Simple assignment|2=
 +
# This is a comment. Everything after the '#' symbol to the end of the line will be ignored by ALSA.
 +
key = value # Equal signs are usually left out, since space can also be used as an separator.
 +
 
 +
key value # Equivalent to the example above.
 +
}}
 +
 
 +
Separators are used to indicate the start and end of an assignment, but using commas or whitespace is also possible.
 +
 
 +
{{hc|Separators|2=
 +
# The following three assignments are equivalent.
 +
key value0; key valueN;
 +
key value0, key valueN,
 +
key value0 key valueN
 +
 
 +
key
 +
value0
 +
key
 +
valueN
 +
}}
 +
 
 +
Compound assignments use braces as separators.
 +
{{hc|Compound assignment|2=
 +
key { subkey0 value0;
 +
subkeyN valueN; }
 +
 
 +
key.subkey0 value0; # Equivalent to the example above.
 +
key.subkeyN valueN;
 +
}}
 +
 
 +
For easier reading, it is recommended to use first style for definitions including more than three keys.
 +
 
 +
Array definitions use brackets as separators.
 +
 
 +
{{hc|Single array|2=
 +
key [ "value0";
 +
"valueN"; ]
 +
 
 +
key.0 "value0"; # Equivalent to the example above
 +
key.N "valueN";
 +
}}
 +
 
 +
Everything depends on user preferences when it comes to different styles of configuration, however one should avoid mixing different styles. Further information on basic configuration can be found [http://www.volkerschatz.com/noise/alsa.html#basicconf here].
 +
 
 +
==== Data types ====
 +
 
 +
ALSA uses different data types for parameter values, which must be set in the users respective configuration file. Some keys accept multiple data types, while most do not. A list of configuration options and their respective type requirements for PCM plugins can be found [http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html here]
 +
 
 +
==== Operation modes ====
 +
 
 +
There are different operation modes for parsing nodes, the default mode is merge and create. If operation mode is either merge/create or merge type checking is done. Only same type assignments can be merged, so strings cannot be merged with integers. Trying to define a simple assignment in default operation mode to a compound (and vice versa) will also not work.
 +
 
 +
Prefixes of operation modes:
 +
* "+" -- merge and create
 +
* "-" -- merge
 +
* "?" -- do not override
 +
* "!" -- override
 +
 
 +
{{hc|Operation modes|2=
 +
# Merge/create - If a node does not exist, it is created. If it does exist and types match,
 +
# subkeyN is merged into key.
 +
key.subkeyN valueN;
 +
 
 +
# Merge/create - Equivalent to above
 +
key.+subkeyN valueN;
 +
 
 +
# Merge - Node key.subkeyN must already exist and must have same data type
 +
key.-subkeyN valueN;
 +
 
 +
# No override - Ignore new assignment if key.subkeyN node already exists
 +
key.?subkeyN valueN;
 +
 
 +
# Override - Removes subkeyN and all keys below it, then creates node key.subkeyN
 +
key.!subkeyN valueN;
 +
}}
 +
 
 +
Using override operation mode, when done correctly, is usually safe, however one should bear in mind, that there might be other necessary keys in a node for proper functioning.
 +
 
 +
{{warning| Overriding pcm node itself will most definitely make alsa unusable, since every plugin definition will be deleted. Therefore <b>do not use !pcm.key</b> unless you are making a configuration from scratch.}}
 +
 
 +
===== An example of setting default device using "defaults" node =====
 +
 
 +
Assuming that "defaults" node is set in {{ic|/usr/share/alsa/alsa.conf}}, where "defaults.pcm.card" and its "ctl" counterpart have assignment values "0" (type integer), user wants to set default pcm and control device to (third) sound card "2" or "SB" for an Azalia sound card.
 +
 
 +
{{hc|Defaults node|2=
 +
defaults.ctl.card 2; # Sets default device and control to third card (counting begins with 0).
 +
defaults.pcm.card 2; # This does not change the data type.
 +
 
 +
defaults.ctl.+card 2; # Equivalent to above.
 +
defaults.pcm.+card 2;
 +
 
 +
defaults.ctl.-card 2; # Same effect on a default setup, however if defaults node was removed or
 +
defaults.pcm.-card 2; # type has been changed merge operation mode will result in no changes.
 +
 
 +
defaults.pcm.?card 2; # This does nothing, since this assignment already exists.
 +
defaults.ctl.?card 2;
 +
 
 +
defaults.pcm.!card "SB"; # The override operation mode is necessary here, because of
 +
defaults.ctl.!card "SB"; # different value types.
 +
}}
 +
 
 +
Using double quotes here automatically sets values data type to string, so in the above example setting defaults.pcm.!card "2" would result in retaining last default device, in this case card 0. Using double quotes for strings is not mandatory as long as no special characters are used, which ideally should never be the case. This may be irrelevant in other assignments.
 +
 
 +
{{note| From a configuration point of view those are not equivalent to setting a compound "default" pcm device, since most users specify addressing type in there also, which actually may be the same, but the assignment itself still differs. Also defaults.pcm.card is referred to multiple times in alsa configuration files, usually as a fallback assignment, where different environment variables take precedence.}}
 +
 
 +
==== Nesting ====
 +
 
 +
Sometimes it may be useful and even easier to read using nesting in configuration.
 +
 
 +
{{hc|Nesting PCM plugins|2=
 +
pcm.azalia { type hw; card 0 }
 +
pcm.!default { type plug; slave.pcm "azalia" }
 +
 
 +
# is equivalent to
 +
 
 +
pcm.!default { type plug; slave.pcm { type hw; card 0; } }
 +
 
 +
# which is also equivalent to
 +
 
 +
pcm.!default.type plug;
 +
pcm.default.slave.pcm.type hw;
 +
pcm.default.slave.pcm.card 0;
 +
}}
 +
 
 +
==== Including configuration files ====
 +
 
 +
{{hc|Include other configuration files|2=
 +
</path/to/configuration-file> # Include a configuration file
 +
<confdir:/path/to/configuration-file> # Reference to a global configuration directory
 +
}}
 +
 
 +
=== Set the default sound card ===
 +
 
 +
{{Expansion|Explain the difference between a "card" and a "device." {{ic|amixer --help}} suggests the two are not synonymous}}
 +
 
 +
{{Style|There is no previous instruction regarding {{ic|defaults.pcm.device}}.}}
 +
 
 +
In addition to the previous instruction regarding {{ic|defaults.pcm.card}} and {{ic|defaults.pcm.device}}, if your sound card order changes on boot, you can specify their order in any file ending with {{ic|.conf}} in {{ic|/etc/modprobe.d}} ({{ic|/etc/modprobe.d/alsa-base.conf}} is suggested).
 +
For example, if you want your mia sound card to be #0:
 +
 
 +
{{hc|/etc/modprobe.d/alsa-base.conf|2=
 +
options snd_mia index=0
 +
options snd_hda_intel index=1
 +
}}
 +
 
 +
Use {{ic|$ cat /proc/asound/modules}} to get the loaded sound modules and their order. This list is usually all that is needed for the loading order. Use {{ic|<nowiki>$ lsmod | grep snd</nowiki>}} to get a devices & modules list. This configuration assumes you have one mia sound card using {{ic|snd_mia}} and one (e.g. onboard) card using {{ic|snd_hda_intel}}.
 +
 
 +
You can also provide an index of {{ic|-2}} to instruct ALSA to never use a card as the primary one. Distributions such as Linux Mint and Ubuntu use the following settings to avoid USB and other "abnormal" drivers from getting index {{ic|0}}:
 +
 
 +
{{hc|/etc/modprobe.d/alsa-base.conf|2=
 +
options bt87x index=-2
 +
options cx88_alsa index=-2
 +
options saa7134-alsa index=-2
 +
options snd-atiixp-modem index=-2
 +
options snd-intel8x0m index=-2
 +
options snd-via82xx-modem index=-2
 +
options snd-usb-caiaq index=-2
 +
options snd-usb-ua101 index=-2
 +
options snd-usb-us122l index=-2
 +
options snd-usb-usx2y index=-2
 +
options snd-pcsp index=-2
 +
options snd-usb-audio index=-2
 +
}}
 +
 
 +
These changes require a system reboot.
 +
 
 +
See also [https://bbs.archlinux.org/viewtopic.php?pid=1446773#p1446773]
 +
 
 +
==== Select the default PCM via environment variable ====
 +
 
 +
{{Tip|An explanation of the terminology of a "card", "device", "subdevice" (a "card" is not a "device") and "PCM" can be found on [[wikipedia:Advanced Linux Sound Architecture#Concepts]].}}
 +
 
 +
Probably it is enough to set ALSA_CARD to the name of the device.  First, get the names with {{ic|aplay -l}}, then set ALSA_CARD to the name which comes after the colon and before the bracket; e.g. if you have
 +
 
 +
{{ic|card 1: HDMI [HDA ATI HDMI], device 3: HDMI 0 [HDMI 0]}}
 +
 
 +
then set ALSA_CARD=HDMI.
 +
 
 +
Other variables are also checked in the default global configuration:
 +
{{hc|/usr/share/alsa/alsa.conf|2=
 +
Variable name # Definition
 +
ALSA_CARD # pcm.default pcm.hw pcm.plughw ctl.sysdefault ctl.hw rawmidi.default rawmidi.hw hwdep.hw
 +
ALSA_CTL_CARD # ctl.sysdefault ctl.hw
 +
ALSA_HWDEP_CARD # hwdep.default hwdep.hw
 +
ALSA_HWDEP_DEVICE # hwdep.default hwdep.hw
 +
ALSA_PCM_CARD # pcm.default pcm.hw pcm.plughw
 +
ALSA_PCM_DEVICE # pcm.hw pcm.plughw
 +
ALSA_RAWMIDI_CARD # rawmidi.default rawmidi.hw
 +
ALSA_RAWMIDI_DEVICE # rawmidi.default rawmidi.hw
 +
}}
 +
 
 +
Alternatively, you can override the behavior in your own configuration file, preferably the global one (/etc/asound.conf).  Add:
 +
{{bc|1=
 +
pcm.!default {
 +
    type plug
 +
    slave.pcm {
 +
        @func getenv
 +
        vars [ ALSAPCM ]
 +
        default "hw:Audigy2"
 +
    }
 +
}
 +
}}
 +
 
 +
In this case as well, replace {{ic|Audigy2}} with the name of your device. You can get the names with {{ic|aplay -l}} or you can also use PCMs like '''surround51'''. But if you need to use the microphone it is a good idea to select full-duplex PCM as default.
 +
 
 +
Now you can select the sound card when starting programs by just changing the environment variable {{ic|ALSAPCM}}. It works fine for all program that do not allow to select the card, for the others ensure you keep the default card.
 +
For example, assuming you wrote a downmix PCM called {{ic|mix51to20}} you can use it with {{Pkg|mplayer}} using the commandline {{ic|ALSAPCM&#61;mix51to20 mplayer example_6_channel.wav}}
  
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:
+
{{note|Pay attention to default addressing type.}}
  
* Locate the module for your soundcard: [http://www.alsa-project.org/main/index.php/Matrix:Main ALSA Soundcard Matrix] The module will be prefixed with 'snd-' (for example: 'snd-via82xx').
+
==== Alternative method ====
* Load modules:
+
{{Tip|This process can be partly automated using {{AUR|asoundconf}}.}}
  # 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 {{Filename|/etc/rc.conf}} to ensure they are loaded next time (make sure '''snd-NAME-OF-MODULE''' is before '''snd-pcm-oss''').
 
  
===Unmute the channels and test===
+
First you will have to find out the card and device id that you want to set as the default:
  
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.
+
{{hc|$ aplay -l|2=
 +
**** List of PLAYBACK Hardware Devices ****
 +
card 0: Intel [HDA Intel], device 0: CONEXANT Analog [CONEXANT Analog]
 +
  Subdevices: 1/1
 +
  Subdevice #0: subdevice #0
 +
card 0: Intel [HDA Intel], device 1: Conexant Digital [Conexant Digital]
 +
  Subdevices: 1/1
 +
  Subdevice #0: subdevice #0
 +
card 1: JamLab [JamLab], device 0: USB Audio [USB Audio]
 +
  Subdevices: 1/1
 +
  Subdevice #0: subdevice #0
 +
card 2: Audio [Altec Lansing XT1 - USB Audio], device 0: USB Audio [USB Audio]
 +
  Subdevices: 1/1
 +
  Subdevice #0: subdevice #0
 +
}}
  
* Unmute Soundcard
+
{{Warning|Simply setting a {{ic|type hw}} as default card is equivalent to addressing hardware directly, which leaves the device unavailable to other applications. This method is only recommended if it is a part of a more sophisticated setup {{ic|~/.asoundrc}} or if user deliberately wants to address sound card directly (digital output through {{ic|eic958}} or dedicated music server for example).}}
  
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 {{Codeline|alsamixer}} 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.
+
For example, the last entry in this list has the card ID 2 and the device ID 0. To set this card as the default, you can either use the system-wide file {{ic|/etc/asound.conf}} or the user-specific file {{ic|~/.asoundrc}}. You may have to create the file if it does not exist. Then insert the following options with the corresponding card.
 +
{{bc|
 +
pcm.!default {
 +
    type hw
 +
    card 2
 +
}
  
{{Note | When using '''{{Codeline|amixer}}''', be sure to '''unmute''' as well as bring volumes up to a specific level in percent, i.e you need to use that % sign. '''{{Codeline|amixer}}''' understands the percent sign (%), not numbers. If you use a number (say, 90) then '''{{Codeline|amixer}}''' will take it as 100%, which can harm your speakers.}}
+
ctl.!default {
 +
    type hw
 +
    card 2
 +
}
 +
}}
  
  # amixer set Master 90% unmute
+
{{Note|For the Asus U32U series it seems that card should be set to 1 for both pcm and ctl.}}
  # amixer set PCM 85% unmute
 
  
* Try to play a WAV file
+
In most cases it is recommended to use sound card names instead of number references, which also solves boot order problem. Therefore the following would be correct for the above example.
 +
{{bc|
 +
pcm.!default {
 +
    type hw
 +
    card Audio
 +
}
  
  # aplay /usr/share/sounds/alsa/Front_Center.wav
+
ctl.!default {
 +
    type hw
 +
    card Audio
 +
}
 +
}}
  
{{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.}}
+
To get valid ALSA card names, use ''aplay'':
 +
{{hc|<nowiki>$ aplay -l | awk -F \: '/,/{print $2}' | awk '{print $1}' | uniq</nowiki>|
 +
PCH
 +
}}
  
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:
+
Alternatively use ''cat'', which might return unused devices:
# alsaconf
+
{{hc|$ cat /proc/asound/card*/id|
 +
PCH
 +
ThinkPadEC
 +
}}
 +
 
 +
{{Note|This method could be problematic if your system has several cards of the same (ALSA)name.}}
  
* [[Allow multiple programs to play sound at once]]
+
The 'pcm' options affect which card and device will be used for audio playback while the 'ctl' option affects which card is used by control utilities like alsamixer .
  
===Setup Permissions===
+
The changes should take effect as soon as you (re-)start an application (MPlayer etc.). You can also test with a command like ''aplay''.
  
To be able to use the sound card as a user, follow these steps:
+
$ aplay -D default:PCH ''your_favourite_sound.wav''
  
* Add your user to the audio group:
+
If you receive an error regarding your asound configuration, check the [http://www.alsa-project.org/main/index.php/Asoundrc#The_default_plugin upstream documentation] for possible changes to the configuration file format.
# gpasswd -a USERNAME audio
 
  
* Log your user out and back in to ensure the audio group is loaded.
+
=== Verifying correct sound modules are loaded ===
  
===Restore ALSA Mixer settings at startup===
+
You can assume that udev will autodetect your sound properly. You can check this with the command:
  
* Run {{Codeline|alsactl store}} once to create {{Filename|/etc/asound.state}}.
+
{{hc|<nowiki>$ lsmod | grep '^snd' | column -t</nowiki>|2=
 +
snd_hda_codec_hdmi    22378  4
 +
snd_hda_codec_realtek  294191  1
 +
snd_hda_intel          21738  1
 +
snd_hda_codec          73739  3  snd_hda_codec_hdmi,snd_hda_codec_realtek,snd_hda_intel
 +
snd_hwdep              6134    1  snd_hda_codec
 +
snd_pcm                71032  3  snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec
 +
snd_timer              18992  1  snd_pcm
 +
snd                    55132  9  snd_hda_codec_hdmi,snd_hda_codec_realtek,snd_hda_intel,snd_hda_codec,snd_hwdep,snd_pcm,snd_timer
 +
snd_page_alloc        7017    2  snd_hda_intel,snd_pcm
 +
}}
  
# alsactl store
+
If the output looks similar, your sound drivers have been successfully autodetected.
 +
{{Note|Since {{ic|udev>&#61;171}}, the OSS emulation modules ({{ic|snd_seq_oss, snd_pcm_oss, snd_mixer_oss}}) are not loaded by default: [[kernel modules#Manual module handling|Load them manually]], if they are needed.}}
  
* Edit {{Filename|/etc/[[rc.conf]]}} and add {{Codeline|"alsa"}} 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.
+
You might also want to check the directory {{ic|/dev/snd/}} for the right device files:
  
* If the mixer settings are not loaded on boot-up, add the following line to {{Filename|/etc/rc.local}}:
+
{{hc|$ ls -l /dev/snd|2=
 +
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
 +
}}
  
# alsactl restore
+
{{Note|If requesting help on IRC or the forums, please post the output of the above commands, if requested.}}
  
===Getting SPDIF Output===
+
If you have at least the devices '''controlC0''' and '''pcmC0D0p''' or similar, then your sound modules have been detected and loaded properly.
  
(from gralves from the Gentoo forums)
+
If this is not the case, your sound modules have not been detected properly. To solve this, you can try loading the modules manually:
* 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):
+
* Locate the module for your sound card: [http://www.alsa-project.org/main/index.php/Matrix:Main ALSA Soundcard Matrix] The module will be prefixed with 'snd-' (for example: {{ic|snd-via82xx}}).
 +
* [[Kernel modules#Manual module handling|Load the module]].
 +
* Check for the device files in {{ic|/dev/snd}} (see above) and/or try if {{ic|alsamixer}} or {{ic|amixer}} have reasonable output.
 +
* Configure {{ic|snd-NAME-OF-MODULE}} and {{ic|snd-pcm-oss}} to [[Kernel modules#Automatic module handling|load at boot]].
  
* add following lines to {{Filename|/etc/rc.local}}:
+
=== Getting S/PDIF output ===
  # Use COAX-digital output
+
[[wikipedia:S/PDIF|S/PDIF]] is a digital audio interface often used to connect a computer to a digital amplifier (such as a home theatre with 5.1/7.1 surround sound).
  amixer set 'IEC958 Optical' 100 unmute
+
{{note|With some soundcards this disables analog sound output  (eg. Sound Blaster Audigy 2).}}
  amixer set 'Audigy Analog/Digital Output Jack' on
+
Depending on what [[shell]] you use, add the following line to your shell's configuration file:
 +
amixer -c 0 cset name='IEC958 Playback Switch' on
  
 
You can see the name of your card's digital output with:
 
You can see the name of your card's digital output with:
  $ amixer scontrols
+
$ amixer scontrols
  
===System-Wide Equalizer===
+
=== 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.}}
+
==== Using ALSAEqual (provides UI) ====
  
* You will need, in addition to the aforementioned userspace utilities, alsa-plugins.
+
Install the {{AUR|alsaequal}} package. Also install {{AUR|lib32-alsaequal}} for 32-bit application support.  
# pacman -S alsa-plugins
 
* Get the ladspa and swh-plugins packages too if you don't already have them.
 
# pacman -S ladspa swh-plugins
 
* If you haven't already created either an {{Filename|~/.asoundrc}} or a {{Filename|/etc/asound.conf}} file, then create either one
 
$ vim ~/.asoundrc
 
* Insert the following into your ALSA configuration file ({{Filename|~/.asoundrc}} or {{Filename|/etc/asound.conf}}):
 
  
{{file |name=/etc/asound.conf |content=pcm.eq {
+
After installing the package, add the following to your ALSA configuration file:
  type ladspa<br>
+
 
  # The output from the EQ can either go direct to a hardware device
+
{{hc|/etc/asound.conf|2=
  # (if you have a hardware mixer, e.g. SBLive/Audigy) or it can go
+
ctl.equal {
  # to the software mixer shown here.
+
    type equal;
  #slave.pcm "plughw:0,0"
+
}
  slave.pcm "plug:dmix"<br>
+
 
  # Sometimes you may need to specify the path to the plugins,
+
pcm.plugequal {
  # especially if you've just installed them. Once you've logged
+
    type equal;
  # out/restarted this shouldn't be necessary, but if you get errors
+
    # Modify the line below if you do not
  # about being unable to find plugins, try uncommenting this.
+
    # want to use sound card 0.
  #path "/usr/lib/ladspa"<br>
+
    #slave.pcm "plughw:0,0";
  plugins [
+
    # by default we want to play from more sources at time:
     {
+
    slave.pcm "plug:dmix";
      label mbeq
+
}
      id 1197
+
 
      input {
+
# pcm.equal {
        #this setting is here by example, edit to your own taste
+
# If you do not want the equalizer to be your
        #bands: 50hz, 100hz, 156hz, 220hz, 311hz, 440hz, 622hz, 880hz, 1250hz, 1750hz, 25000hz,
+
# default soundcard comment the following
         #50000hz, 10000hz, 20000hz
+
# line and uncomment the above line. (You can
         controls [ -5 -5 -5 -5 -5 -10 -20 -15 -10 -10 -10 -10 -10 -3 -2 ]
+
# choose it as the output device by addressing
      }
+
# it with specific apps,eg mpg123 -a equal 06.Back_In_Black.mp3)
 +
pcm.!default {
 +
    type plug;
 +
     slave.pcm plugequal;
 +
}
 +
}}
 +
 
 +
If you have a x86_64-system and are using {{Pkg|lib32-flashplugin}} the sound in flash will not work with the above configuration. The configuration below enables sound in flash, but you have to specify the sound card manually in the line {{ic|pcm "hw:0,0"}} (use {{ic|aplay -l}} to list the available sound card and relative card and device number):
 +
 
 +
{{hc|/etc/asound.conf|2=
 +
pcm.dmixer {
 +
    type dmix
 +
    ipc_key 2048
 +
    slave {
 +
         pcm "hw:0,0"
 +
         buffer_size 16384
 
     }
 
     }
  ]
+
}
}<br>
+
 
# Redirect the default device to go via the EQ - you may want to do
+
ctl.equal {
# this last, once you're sure everything is working. Otherwise all
+
    type equal;
# your audio programs will break/crash if something has gone wrong.<br>
+
}
pcm.!default {
+
 
  type plug
+
pcm.equalizer {
  slave.pcm "eq"
+
    type equal
}<br>
+
    slave.pcm "plug:dmixer"
# Redirect the OSS emulation through the EQ too (when programs are running through "aoss")<br>
+
}
pcm.dsp0 {
+
 
  type plug
+
pcm.!default {
  slave.pcm "eq"
+
    type plug
}
+
    slave.pcm equalizer
 +
}
 
}}
 
}}
  
*Reload your alsa settings (as root).
+
And you are ready to change your equalizer using command
  # /etc/rc.d/alsa restart
+
$ alsamixer -D equal
 +
 
 +
Note that configuration file is different for each user (until not specified else) it is saved in {{ic|~/.alsaequal.bin}}.
 +
so if you want to use ALSAEqual with [[mpd]] or another software running under different user, you can configure it using
 +
$ su mpd -c 'alsamixer -D equal'
 +
or for example, you can make a symlink to your {{ic|.alsaequal.bin}} in his home...
 +
 
 +
===== Managing ALSAEqual states =====
 +
 
 +
Install the {{AUR|alsaequal-mgr}} package.
 +
 
 +
Configure the equalizer as usual with
 +
$ alsamixer -D equal
 +
 
 +
When you are satisfied with the state, you may give it a name ("foo" in this example) and save it:
 +
$ alsaequal-mgr save foo
 +
 
 +
The state "foo" can then be restored at a later time with
 +
  $ alsaequal-mgr load foo
 +
 
 +
You can thus create different equalizer states for games, movies, music genres, VoIP apps, etc. and reload them as necessary.
  
*You should be good to go (if not, ask in the forum).
+
See the [http://xyne.archlinux.ca/projects/alsaequal-mgr/ project page] and the help message for more options.
  
==Troubleshooting==
+
==== Using mbeq ====
===Model Settings===
 
  
Although Alsa detects your soundcard through the BIOS at times Alsa may not be able to recognize your [http://www.mjmwired.net/kernel/Documentation/sound/alsa/HD-Audio-Models.txt model type].  The soundcard chip can be found in <code>alsamixer</code> (e.g. ALC662) and the model can be set in {{Filename|/etc/modprobe.d/modprobe.conf}}.  For example:
+
{{Note|This method requires the use of a [[Wikipedia:LADSPA|LADSPA]] plugin which might be CPU intensive during playback. In addition, this was made with stereophonic sound (e.g. headphones) in mind.}}
  
options snd-hda-intel model=MODEL
+
Install the {{Pkg|alsa-plugins}}, {{Pkg|ladspa}} and {{Pkg|swh-plugins}} packages if you do not already have them.
  
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 [http://bugtrack.alsa-project.org/main/index.php/Matrix:Main Alsa Soundcard List] find your model, then Details, then look at the "Setting up modprobe..." section.  Enter these values in {{Filename|/etc/modprobe.d/modprobe.conf}}.  For example, for an Intel AC97 audio:
+
If you have not already created either an {{ic|~/.asoundrc}} or a {{ic|/etc/asound.conf}} file, then create either one and insert the following:
  
<pre># ALSA portion
+
{{hc|/etc/asound.conf|2=
alias char-major-116 snd
+
pcm.eq {
alias snd-card-0 snd-intel8x0
+
    type ladspa
# module options should go here
 
  
# OSS/Free portion
+
    # The output from the EQ can either go direct to a hardware device
alias char-major-14 soundcore
+
    # (if you have a hardware mixer, e.g. SBLive/Audigy) or it can go
alias sound-slot-0 snd-card-0
+
    # to the software mixer shown here.
 +
    #slave.pcm "plughw:0,0"
 +
    slave.pcm "plug:dmix"
  
# card #1
+
    # Sometimes you may need to specify the path to the plugins,
alias sound-service-0-0 snd-mixer-oss
+
    # especially if you have just installed them.  Once you have logged
alias sound-service-0-1 snd-seq-oss
+
    # out/restarted this should not be necessary, but if you get errors
alias sound-service-0-3 snd-pcm-oss
+
    # about being unable to find plugins, try uncommenting this.
alias sound-service-0-8 snd-seq-oss
+
    #path "/usr/lib/ladspa"
alias sound-service-0-12 snd-pcm-oss</pre>
 
  
===Conflicting PC Speaker===
+
    plugins [
 +
    {
 +
        label mbeq
 +
        id 1197
 +
        input {
 +
            # The following setting is just an example, edit to your own taste:
 +
            # bands: 50hz, 100hz, 156hz, 220hz, 311hz, 440hz, 622hz, 880hz, 1250hz, 1750hz, 25000hz,
 +
            # 50000hz, 10000hz, 20000hz
 +
            controls [ -5 -5 -5 -5 -5 -10 -20 -15 -10 -10 -10 -10 -10 -3 -2 ]
 +
            }
 +
        }
 +
    ]
 +
}
  
Remember, ALSA installs with all channels '''muted by default''' (see previous section, [[ALSA#Unmuting_the_channels_and_testing_the_sound_card|unmuting your soundcard]]).
+
# Redirect the default device to go via the EQ - you may want to do
 +
# this last, once you are sure everything is working.  Otherwise all
 +
# your audio programs will break/crash if something has gone wrong.
 +
pcm.!default {
 +
    type plug
 +
    slave.pcm "eq"
 +
}
  
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:
+
# Redirect the OSS emulation through the EQ too (when programs are running through "aoss")
 +
pcm.dsp0 {
 +
    type plug
 +
    slave.pcm "eq"
 +
}
 +
}}
  
MODULES=(!snd-pcsp ... )
+
== High quality resampling ==
  
Note that this will disable your PC's internal speaker.
+
When software mixing is enabled, ALSA is forced to resample everything to the same frequency (48 kHz by default when supported). By default, it will try to use the ''speexrate'' converter to do so, and fallback to low-quality linear interpolation if it is not available[http://git.alsa-project.org/?p=alsa-lib.git;a=blob;f=src/pcm/pcm_rate.c;h=2eb4b1b33933dec878d0f25ad118869adac95767;hb=HEAD#l1278].
If that doesn't work, then try adding the following line to <code>/etc/modprobe.d/modprobe.conf</code>:
+
Thus, if you are getting poor sound quality due to bad resampling, the problem can be solved by simply installing the {{Pkg|alsa-plugins}} package.
  
options snd-NAME-OF-MODULE ac97_quirk=0
+
For even higher quality resampling, you can change the default rate converter to {{ic|speexrate_medium}} or {{ic|speexrate_best}}. Both perform well enough that in practice it does not matter which one you choose, so using the best converter is usually not worth the extra CPU cycles it requires.
  
The above fix has been observed to work with <code>via82xx</code>
+
To change the default converter place the following contents in your {{ic|~/.asoundrc}} or {{ic|/etc/asound.conf}}:
options snd-NAME-OF-MODULE ac97_quirk=1
 
The above fix has been reported to work with <code>snd_intel8x0</code>
 
  
===No Sound with Onboard Intel Sound Card===
+
{{hc|/etc/asound.conf|
 +
defaults.pcm.rate_converter "speexrate_medium"
 +
}}
  
There may be an issue with two conflicting modules loaded, namely <code>snd_intel8x0</code> and <code>snd_intel8x0m</code>. In this case, edit <code>rc.conf</code> and in the MODULES array blacklist the latter one so that it reads <code>!snd_intel8x0m</code> afterwards.
+
{{note|It is also possible to use {{Pkg|libsamplerate}} converters, which are only about half as fast as the ''speexrate'' converters but do not achieve much higher quality. See [[Talk:Advanced_Linux_Sound_Architecture#On_high_quality_resampling|discussion]].}}
 +
{{note|It is also possible to use lavcrate resamplers that use {{Pkg|ffmpeg}} With filter sizes of lavcrate_faster:4 lavcrate_fast:8 lavcrate:16 lavcrate_high:32 lavcrate_higher:64 With the last 2 options being equal to Kodi low and medium quality resamplers respectively}}
 +
{{note|Some applications (like MPlayer and its forks) do their own resampling by default because some ALSA drivers have incorrect delay reporting when resampling is enabled (hence leading to AV desynchronization), so changing this setting will not have any effect unless you configure them to use ALSA resampling.}}
  
''Muting'' the "External Amplifier" in <code>alsamixer</code> or <code>amixer</code> may also help. See [http://alsa.opensrc.org/index.php/Intel8x0#Dell_Inspiron_8600_.28and_probably_others.29 the ALSA wiki].
+
== Upmixing/downmixing ==
  
With '''Intel Corporation 82801 I (ICH9 Family) HD Audio Controller''' on laptop, you may need to add this line to
+
=== Upmixing ===
  
/etc/modprobe.d/sound
+
In order for stereo sources like music to be able to saturate a 5.1 or 7.1 sound system, you need to use upmixing. In darker days this used to be tricky and error prone but nowadays plugins exist to easily take care of this task. We will use the {{ic|upmix}} plugin, included in the {{Pkg|alsa-plugins}} package.
options snd-hda-intel model=laptop
 
  
or
+
Then add the following to your ALSA configuration file of choice (either {{ic|/etc/asound.conf}} or {{ic|~/.asoundrc}}):
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 [http://en.opensuse.org/SDB:Intel-HDA_sound_problems]
+
{{bc|
 +
pcm.upmix71 {
 +
    type upmix
 +
    slave.pcm "surround71"
 +
    delay 15
 +
    channels 8
 +
}
 +
}}
  
===Poor Sound Quality===
+
You can easily change this example for 7.1 upmixing to 5.1 or 4.0.
  
If you experience poor sound quality, try setting the PCM volume (in alsamixer) to a level such that gain is 0.
+
The following example adds a new PCM channel that you can use for upmixing. If you want all sound sources to go through this channel, add it as a default below the previous definition like so:
  
===Pops When Starting and Stopping Playback===
+
pcm.!default "plug:upmix71"
  
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.  
+
The plugin automatically allows multiple sources to play through it without problems so setting is as a default is actually a safe choice.
 +
If this is not working, you have to setup your own dmixer for the upmixing PCM like this:
 +
{{bc|1=
 +
pcm.dmix6 {
 +
    type asym
 +
    playback.pcm {
 +
        type dmix
 +
        ipc_key 567829
 +
        slave {
 +
            pcm "hw:0,0"
 +
            channels 6
 +
        }
 +
    }
 +
}
  
for example: to disable the power saving mode using snd-hda-intel add "options snd-hda-intel power_save=0" in /etc/modprobe.d/modprobe.conf. or try it with "modprobe snd-hda-intel power_save=0"
+
}}
  
===Alsamixer Does Not Run===
+
and use "dmix6" instead of "surround71".
 +
If you experience skipping or distorted sound, consider increasing the buffer_size (to 32768, for example) or use a [[#High quality resampling|high quality resampler]].
  
If running alsamixer does not work and you wind up with the following error
+
=== Downmixing ===
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.
+
If you want to downmix sources to stereo because you, for instance, want to watch a movie with 5.1 sound on a stereo system, use the {{ic|vdownmix}} plugin, included in the {{Pkg|alsa-plugins}} package.
  
Then you might need to re-install your kernel. Run 'pacman -S kernel26' or whichever patchset you prefer to use.
+
Again, in your configuration file, add this:
  
===S/PDIF Output Does Not Work===
+
{{bc|1=
 +
pcm.!surround51 {
 +
    type vdownmix
 +
    slave.pcm "default"
 +
}
 +
pcm.!surround40 {
 +
    type vdownmix
 +
    slave.pcm "default"
 +
}
 +
}}
  
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
+
{{Note|1=This might not be enough to make downmixing working, see [http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=541786]. So, you might also need to add {{ic|pcm.!default "plug:surround51"}} or {{ic|pcm.!default "plug:surround40"}}. Only one {{ic|vdownmix}} plug can be used; if you have 7.1 channels, you will need to use {{ic|surround71}} instead the configuration above. A good example, which includes a configuration that makes both {{ic|vdownmix}} and {{ic|dmix}} working, can be found [https://bbs.archlinux.org/viewtopic.php?id=167275 here].}}
iecset audio on
 
  
as root.
+
== Dmix ==
  
You can also put this command in rc.local as it sometimes it may stop working after a reboot.
+
Mixing enables multiple applications to output sound at the same time. Most discrete sound cards support hardware mixing, which is enabled by default if available. Integrated motherboard sound cards (such as Intel HD Audio), usually do not support hardware mixing. On such cards, software mixing is done by an ALSA plugin called {{ic|dmix}}. This feature is enabled automatically if hardware mixing is unavailable.
  
===HDMI Output Does Not Work===
+
{{Note|Dmix is enabled by default for soundcards which do not support hardware mixing. Dmix is not enabled by default for digital output (S/PDIF) and will require the configuration snippet below.}}
  
If the HDMI output of your motherboard/sound card is not working or stopped working, and have already enabled and unmuted it in alsamixer, try the following.
+
To manually enable dmix, add the following to your ALSA configuration file:
  
Query for Playback Devices:
+
{{hc|/etc/asound.conf|2=
 +
pcm.dsp {
 +
    type plug
 +
    slave.pcm "dmix"
 +
}
 +
}}
  
  % aplay -l
+
== Tips and tricks ==
  **** List of PLAYBACK Hardware Devices ****
 
  card 0: NVidia [HDA NVidia], device 0: ALC1200 Analog [ALC1200 Analog]
 
    Subdevices: 1/1
 
    Subdevice #0: subdevice #0
 
  card 0: NVidia [HDA NVidia], device 1: ALC1200 Digital [ALC1200 Digital]
 
    Subdevices: 1/1
 
    Subdevice #0: subdevice #0
 
  card 0: NVidia [HDA NVidia], device 3: NVIDIA HDMI [NVIDIA HDMI]
 
    Subdevices: 0/1
 
    Subdevice #0: subdevice #0
 
  
Now that we have the info for the HDMI device, try a test,  In the example below, 0 is the card number and 3 is the device number.
+
=== Hot-plugging a USB sound card ===
  
  % aplay -D plughw:0,3 /usr/share/sounds/alsa/Front_Center.wav
+
See [http://alsa.opensrc.org/Udev Writing Udev rules for ALSA].
  
If the test is successful, edit/create asound.conf in /etc to set HDMI as the default audio device, reboot, and audio should now work.  There might be a better way to do this??
+
=== Simultaneous output ===
  
  % cat /etc/asound.conf
+
You might want to play music via external speakers connected via mini jack and internal speakers simultaneously. This can be done by unmuting '''Auto-Mute''' item using {{ic|alsamixer}} or {{ic|amixer}}:
  pcm.!default {
+
$ amixer sset "Auto-Mute" unmute
      type plug
 
      slave.pcm {
 
              type hw
 
              card 0
 
              device 3
 
      }
 
  }
 
  
===No Adjustable PCM Channel===
+
and then unmuting other required items, such as '''Headphones''', '''Speaker''', '''Bass Speaker'''...
 +
{{Note|If you have a crackling sound through headphones connector (mini-jack) after, see [[ALSA/Troubleshooting#Crackling_sound_through_mini-jack_.28headphones_connector.29|here]].}}
  
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.
+
=== Keyboard volume control ===
  
===HP TX2500===
+
Map the following commands to your volume keys: {{ic|XF86AudioRaiseVolume}}, {{ic|XF86AudioLowerVolume}}, {{ic|XF86AudioMute}}
  
Add these 2 lines into {{Filename|/etc/modprobe.d/modprobe.conf}}:
+
To raise the volume:
  options snd-cmipci mpu_port=0x330 fm_port=0x388
+
  amixer set Master 5%+
options snd-hda-intel index=0 model=toshiba position_fix=1
 
  
And don't forget to enable 'hal' in the DAEMONS section of your {{Filename|/etc/rc.conf}}.
+
To lower the volume:
 +
amixer set Master 5%-
  
  options snd-hda-intel model=hp (works for tx2000cto)
+
To toggle mute/unmute of the volume:
 +
  amixer set Master toggle
  
===Skipping Sound When Playing MP3===
+
=== Virtual sound device using snd-aloop ===
  
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
+
You might want a jack alternative to create a virtual recording or play device in order to mix different sources, using the snd-aloop module:
 +
modprobe snd-aloop
  
===Using a USB Headset and External USB Sound Cards===
+
List your new virtual devices using:
 +
aplay -l
  
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. ''note: before running please make sure you have usb audio modual enabled
+
now you can for example using ffmpeg:
  #modprobe snd-usb-audio
+
  ffmpeg -f alsa -i hw:1,1,0 -f alsa -i hw:1,1,1 -filter_complex amerge output.mp3
  
you can add this to /etc/rc.conf if you wish''
+
In the  hw:R,W,N format R is your virtual card device number, W 1 recording devices 0 for writing, N is your sub device you can use all the virtual devices available and play/stop using applications like mplayer:
 +
mplayer -ao alsa:device=hw=1,0,0 fileA
 +
mplayer -ao alsa:device=hw=1,0,1 fileB
  
# asoundconf is-active
+
Another thing you could do with this approach, is using festival to generate a voice into a recording stream using an script like this:
  # asoundconf list
+
  #!/bin/bash
  # asoundconf set-default-soundcard <chosen soundcard>
+
  echo $1|iconv -f utf-8 -t iso-8859-1| text2wave  > "_tmp_.wav"; 
 +
mplayer -ao alsa:device=hw=2,0,0 "_tmp.wav";
 +
rm "_tmp.wav";
  
===KDE Settings===
+
=== Debugging ALSA ===
  
* Start up KDE:
+
==== Retrieving the driver state ====
# startx
 
  
* Set up the volumes as you want them for this user (each user has their own settings):
+
The {{Pkg|alsa-utils}} package also contains the {{ic|alsa-info.sh}} command, which can be used to gather detailed data on the ALSA driver and user-space state.
# 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)
+
See [http://alsa-project.org/main/index.php/Bug_Tracking ALSA bug tracking] for more info.
  
* '''KDE 3.3:''' Go to ''K Menu &rarr; Multimedia &rarr; KMix''
+
==== Reconfiguring input/output ports ====
** Choose ''Settings &rarr; 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.
 
  
===Error 'Unkown hardware' Appears After a Kernel Update===
+
The {{Pkg|alsa-tools}} package contains the {{ic|hdajackretask}} tool, which can be used (on Intel HDA cards) to reconfigure the sound card input/output ports; for instance, to turn a microphone jack into a headphone jack.
  
The following messages may be displayed during the start-up ALSA after the kernel update:
+
==== Resetting codecs ====
Unknown hardware "foo" "bar" ...
 
Hardware is initialized using a guess method
 
/usr/sbin/alsactl: set_control:nnnn:failed to obtain info for control #mm (No such file or directory)
 
  
Then, try to store ALSA mixer settings again:
+
The ALSA driver can fully reconfigure attached codecs (the parts of the sound system that actually process audio streams), by doing:
# alsactl store
 
  
===HDA Analyzer===
+
# echo 1 > /sys/class/sound/''card''/reconfig
  
If the mappings to your audio pins(plugs) do not correspond but ALSA works fine, you could try HDA Analyzer -- a pyGTK2 GUI for HD-audio control found here: [http://www.alsa-project.org/main/index.php/HDA_Analyzer]
+
Before doing this, all processes using the ALSA driver (such as [[PulseAudio#Running|Pulseaudio]] or [[JACK]]) must be stopped.
Try tweaking the Widget Control section of the PIN nodes, to make microphones IN and headphone jacks OUT. Referring to the Config Defaults heading is a good idea.
 
  
==Example configurations==
+
=== Correctly detect microphone plugged in a 4-pin 3.5mm (TRRS) jack ===
The following should serve as a guide for more advanced setups. The configuration takes place in /etc/asound.conf as mentioned earlier in this article. None of the following configurations are guaranteed to be working.  
 
  
===Upmixing of stereo sources to 7.1 using dmix while saturated sources do not get upmixed===
+
On some modern laptops you may have a combined 3.5mm headset jack, instead of two separated ones, which may not be correctly detected by default.
# 2008-11-15
+
To make ALSA correctly detect plug-in status on your 3.5mm jack, you could put the following line into your {{ic|/etc/modprobe.d/alsa-base.conf}} :
#
 
# This .asoundrc will allow the following:
 
#
 
# - upmix stereo files to 7.1 speakers.
 
# - playback real 7.1 sounds, on 7.1 speakers,
 
# - allow the playback of both stereo (upmixed) and surround(7.1) sources at the same time.
 
# - use the 6th and 7th channel (side speakers) as a separate soundcard, i.e. for headphones
 
#  (This is called the "alternate" output throughout the file, device names prefixed with 'a')
 
# - play mono sources in stereo (like skype & ekiga) on the alterate output
 
#
 
# Make sure you have "8 Channels" and NOT "6 Channels" selected in alsamixer!
 
#
 
# Please try the following commands, to make sure everything is working as it should.
 
#
 
# To test stereo upmix :      speaker-test -c2 -Ddefault -twav
 
# To test surround(5.1):      speaker-test -c6 -Dplug:dmix6 -twav
 
# To test surround(7.1):      speaker-test -c6 -Dplug:dmix8 -twav
 
# To test alternative output: speaker-test -c2 -Daduplex -twav
 
# To test mono upmix:        speaker-test -c1 -Dmonoduplex -twav
 
#
 
#
 
# It may not work out of the box for all cards. If it doesnt work for you, read the comments throughout the file.
 
# The basis of this file was written by wishie of #alsa, and then modified with info from various sources by
 
# squisher. Svenstaro modified it for 7.1 output support.
 
 
#Define the soundcard to use
 
pcm.snd_card {
 
    type hw
 
    card 0
 
    device 0
 
}
 
 
# 8 channel dmix - output whatever audio, to all 8 speakers
 
pcm.dmix8 {
 
    type dmix
 
    ipc_key 1024
 
    ipc_key_add_uid false
 
    ipc_perm 0660
 
    slave {
 
        pcm "snd_card"
 
        rate 48000
 
        channels 8
 
        period_time 0
 
        period_size 1024
 
        buffer_time 0
 
        buffer_size 5120
 
    }
 
 
# Some cards, like the "nforce" variants require the following to be uncommented.
 
# It routes the audio to the correct speakers.
 
#    bindings {
 
#        0 0
 
#        1 1
 
#        2 4
 
#        3 5
 
#        4 2
 
#        5 3
 
#        6 6
 
#        7 7
 
#    }
 
}
 
 
# upmixing - duplicate stereo data to all 8 channels
 
pcm.ch71dup {
 
    type route
 
    slave.pcm dmix8
 
    slave.channels 8
 
    ttable.0.0 1
 
    ttable.1.1 1
 
    ttable.0.2 1
 
    ttable.1.3 1
 
    ttable.0.4 0.5
 
    ttable.1.4 0.5
 
    ttable.0.5 0.5
 
    ttable.1.5 0.5
 
    ttable.0.6 1
 
    ttable.1.7 1
 
}
 
 
# this creates a six channel soundcard
 
# and outputs to the eight channel one
 
# i.e. for usage in mplayer I had to define in ~/.mplayer/config:
 
#  ao=alsa:device=dmix6
 
#  channels=6
 
pcm.dmix6 {
 
    type route
 
    slave.pcm dmix8
 
    slave.channels 8
 
    ttable.0.0 1
 
    ttable.1.1 1
 
    ttable.2.2 1
 
    ttable.3.3 1
 
    ttable.4.4 1
 
    ttable.5.5 1
 
    ttable.6.6 1
 
    ttable.7.7 1
 
}
 
 
# share the microphone, i.e. because virtualbox grabs it by default
 
pcm.microphone {
 
    type dsnoop
 
    ipc_key 1027
 
    slave {
 
        pcm "snd_card"
 
    }
 
}
 
 
# rate conversion, needed i.e. for wine
 
pcm.2chplug {
 
    type plug
 
    slave.pcm "ch71dup"
 
}
 
pcm.a2chplug {
 
    type plug
 
    slave.pcm "dmix8"
 
}
 
 
# routes the channel for the alternative
 
# 2 channel output, which becomes the 7th and 8th channel
 
# on the real soundcard
 
#pcm.alt2ch {
 
#    type route
 
#    slave.pcm "a2chplug"
 
#    slave.channels 8
 
#    ttable.0.6    1
 
#    ttable.1.7    1
 
#}
 
 
# skype and ekiga are only mono, so route left channel to the right channel
 
# note: this gets routed to the alternative 2 channels
 
pcm.mono_playback {
 
    type route
 
    slave.pcm "a2chplug"
 
    slave.channels 8
 
    # Send Skype channel 0 to the L and R speakers at full volume
 
    #ttable.0.6    1
 
    #ttable.0.7    1
 
}
 
 
# 'full-duplex' device for use with aoss
 
pcm.duplex {
 
    type asym
 
    playback.pcm "2chplug"
 
    capture.pcm "microphone"
 
}
 
 
#pcm.aduplex {
 
#    type asym
 
#    playback.pcm "alt2ch"
 
#    capture.pcm "microphone"
 
#}
 
 
pcm.monoduplex {
 
    type asym
 
    playback.pcm "mono_playback"
 
    capture.pcm "microphone"
 
}
 
 
# for aoss
 
pcm.dsp0 "duplex"
 
ctl.mixer0 "duplex"
 
 
# softvol manages volume in alsa
 
# i.e. wine likes this
 
pcm.mainvol {
 
    type softvol
 
    slave.pcm "duplex"
 
    control {
 
        name "2ch-Upmix Master"
 
        card 0
 
    }
 
}
 
 
#pcm.!default "mainvol"
 
 
# set the default device according to the environment
 
# variable ALSA_DEFAULT_PCM and default to mainvol
 
pcm.!default {
 
    @func refer
 
    name { @func concat
 
            strings [ "pcm."
 
                      { @func getenv
 
                        vars [ ALSA_DEFAULT_PCM ]
 
                        default "mainvol"
 
                      }
 
            ]
 
          }
 
}
 
 
# uncomment the following if you want to be able to control
 
# the mixer device through environment variables as well
 
#ctl.!default {
 
#    @func refer
 
#    name { @func concat
 
#          strings [ "ctl."
 
#                    { @func getenv
 
#                      vars [ ALSA_DEFAULT_CTL
 
#                              ALSA_DEFAULT_PCM
 
#                      ]
 
#                      default "duplex"
 
#                    }
 
#          ]
 
#        }
 
#}
 
  
===Surround51 incl. upmix stereo & dmix, swap L/R, bad speaker position in room===
+
# options snd_hda_intel index=0 model=[YOUR_MODEL_SETTING]
  
Bad practice but works fine for almost everything without additional per-program/file customization:
+
For complete list of options put in {{ic|[YOUR_MODEL_SETTING]}}, see [http://git.alsa-project.org/?p=alsa-kernel.git;a=blob;f=Documentation/sound/alsa/HD-Audio-Models.txt;hb=HEAD HD-Audio-Models.txt].
pcm.!default {
+
Tested with Gigabyte Aero15 2017 (P65 Model), with ALC255 and set model to {{ic|dell-headset-multi}}.
    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==
+
== See also ==
  
More info can be found here:
+
* [http://www.alsa-project.org/ ALSA wiki]
 +
* [http://www.alsa-project.org/main/index.php/Asoundrc Asoundrc]
 +
* [http://alsa.opensrc.org/ Unofficial ALSA wiki]
 
* [http://www.mjmwired.net/kernel/Documentation/sound/alsa/ALSA-Configuration.txt Advanced ALSA module configuration]
 
* [http://www.mjmwired.net/kernel/Documentation/sound/alsa/ALSA-Configuration.txt Advanced ALSA module configuration]
* [http://alsa.opensrc.org/index.php/Main_Page Unofficial ALSA Wiki]
+
* [https://bbs.archlinux.org/viewtopic.php?id=36815 HOWTO: compile driver from svn]
* [http://alsa.opensrc.org/index.php/Aadebug A simple shell script to aid ALSA audio debugging]
+
* [http://www.volkerschatz.com/noise/alsa.html A close look at ALSA: ALSA concept introduction]
* [http://bbs.archlinux.org/viewtopic.php?id=36815 HOWTO: Compile driver from svn]
+
* [http://www.sabi.co.uk/Notes/linuxSoundALSA.html Linux ALSA sound notes]
* [http://gentoo-wiki.com/HOWTO_Set_up_a_system-wide_equaliser_with_ALSA_and_LADSPA HOWTO Set up a system-wide equaliser with ALSA and LADSPA]
 
 
 
* [http://archux.com/page/setting-audio Simple instructions for setting up ALSA]
 
<!-- vim: set ft=Wikipedia: -->
 

Latest revision as of 14:05, 3 June 2018

The Advanced Linux Sound Architecture (ALSA) provides kernel driven sound card drivers. It replaces the original Open Sound System (OSS).

Besides the sound device drivers, ALSA also bundles a user space driven library for application developers. They can then use those ALSA drivers for high level API development. This enables direct (kernel) interaction with sound devices through ALSA libraries.

Installation

ALSA is a set of built-in GNU/Linux kernel modules. Therefore, manual installation is not necessary.

udev will automatically detect your hardware and select needed drivers at boot time, therefore, your sound should already be working. However, your sound may be initially muted. If it is, see Unmuting the channels.

User privileges

Usually, local users have permission to play audio and change mixer levels.

To allow remote users to use ALSA, you need to add those users to the audio group.

Note: Adding users to the audio group allows direct access to devices. Keep in mind, that this allows applications to exclusively reserve output devices. This may break software mixing or fast-user-switching on multi-seat systems. Therefore, adding a user to the audio group is not recommended by default; unless you specifically need to [1].

ALSA Utilities

Install the alsa-utils package. This contains (among other utilities) the alsamixer and amixer utilities. amixer is a shell command to change audio settings, while alsamixer provides a more intuitive ncurses based interface for audio device configuration.

If you need high quality resampling install the alsa-plugins package to enable upmixing/downmixing and other advanced features.

OSS compatibility

Note: This is important if your application complains about missing /dev/dsp or /dev/snd/seq.

ALSA has some ability to intercept OSS calls and re-route them through ALSA instead. This emulation layer is useful e.g. for legacy applications which try to open /dev/dsp and write sound data to them directly. Without OSS or the emulation library, /dev/dsp will be missing, and the application will not produce any sound.

If you want OSS applications to work with dmix, install the alsa-oss package as well. Then load the snd-seq-oss, snd-pcm-oss and snd-mixer-oss kernel modules to enable OSS emulation.

PulseAudio compatibility

apulseAUR lets you use ALSA for applications that support only PulseAudio for sound. Usage is simply $ apulse yourapplication.

ALSA and Systemd

The alsa-utils package comes with systemd unit configuration files alsa-restore.service and alsa-state.service by default.

These are automatically installed and activated during installation. Therefore, there is no further action needed. Though, you can check their status using systemctl.

Note: For reference, ALSA stores its settings in /var/lib/alsa/asound.state

ALSA Firmware

The alsa-firmware package contains firmware that may be required for certain sound cards (e.g. Creative SB0400 Audigy2).

Unmuting the channels

By default ALSA has all channels muted. Those have to be unmuted manually.

Unmute with amixer

Unmuting the sound card's master volume can be done by using amixer:

$ amixer sset Master unmute

Unmute with alsamixer

Unmuting the sound card can be done using alsamixer:

$ alsamixer

The MM label below a channel indicates that the channel is muted, and 00 indicates that it is open.

Scroll to the Master and PCM channels with the and keys and unmute them by pressing the m key.

Use the key to increase the volume and obtain a value of 0 dB gain. The gain can be found in the upper left next to the Item: field.

Note: If gain is set above 0 dB audible distortion can become present.

Unmute 5.1/7.1 sound

To get full 5.1 or 7.1 surround sound you will likely need to unmute other channels such as Front, Surround, Center, LFE (subwoofer) and Side. (Those are channel names with Intel HD Audio, they may vary with different hardware)

Note: Please take note that this will not automatically upmix stereo sources (like most music). In order to accomplish that, see #Upmixing/downmixing.

Enable the microphone

To enable your microphone, switch to the Capture tab with F4 and enable a channel with Space. See ALSA/Troubleshooting#Microphone if microphone does not work.

Test your changes

Next, test to see if sound works:

$ speaker-test -c 2

Change -c to fit your speaker setup. Use -c 8 for 7.1, for instance:

$ speaker-test -c 8

If audio is being outputted to the wrong device, try manually specifying it with the argument -D.

$ speaker-test -D default:PCH -c 8

-D accepts PCM channel names as values, which can be retrieved by running the following:

$ aplay -L | grep :CARD
default:CARD=PCH  # 'default:PCH' is the PCM channel name for -D
sysdefault:CARD=PCH
front:CARD=PCH,DEV=0
surround21:CARD=PCH,DEV=0
surround40:CARD=PCH,DEV=0
surround41:CARD=PCH,DEV=0
surround50:CARD=PCH,DEV=0
surround51:CARD=PCH,DEV=0
surround71:CARD=PCH,DEV=0

If that does not work, consult the #Configuration section or the ALSA/Troubleshooting page.

Additional notes

  • If your system has more than one soundcard, then you can switch between them by pressing F6
  • Some cards need to have digital output muted or disabled in order to hear analog sound. For the Soundblaster Audigy LS mute the channel labeled IEC958.
  • Some machines, (like the Thinkpad T61), have a Speaker channel which must be unmuted and adjusted as well.
  • Some machines, (like the Dell E6400) may also require the Front and Headphone channels to be unmuted and adjusted.
  • If your volume adjustments seem to be lost after you reboot, try running alsamixer as root.

Configuration

The system configuration file is /etc/asound.conf, and the per-user configuration file is ~/.asoundrc.

Basic syntax

ALSA configuration files follow a simple syntax consisting of hierarchical value to parameter (key) assignments. Below are (modified) excerpts from asoundrc.txt, which is usually found in alsa-lib package but can be also reached here.

Assignments and Separators

Assignments define a value of a given key. There are different assignment types and styles available.

Simple assignment
# This is a comment. Everything after the '#' symbol to the end of the line will be ignored by ALSA.
key = value # Equal signs are usually left out, since space can also be used as an separator.

key value # Equivalent to the example above.

Separators are used to indicate the start and end of an assignment, but using commas or whitespace is also possible.

Separators
# The following three assignments are equivalent.
key value0; key valueN;
key value0, key valueN,
key value0 key valueN

key
value0
	key
valueN

Compound assignments use braces as separators.

Compound assignment
key {	subkey0 value0;
	subkeyN valueN;	}

key.subkey0 value0; # Equivalent to the example above.
key.subkeyN valueN;

For easier reading, it is recommended to use first style for definitions including more than three keys.

Array definitions use brackets as separators.

Single array
key [	"value0";
	"valueN";	]

key.0 "value0"; # Equivalent to the example above
key.N "valueN";

Everything depends on user preferences when it comes to different styles of configuration, however one should avoid mixing different styles. Further information on basic configuration can be found here.

Data types

ALSA uses different data types for parameter values, which must be set in the users respective configuration file. Some keys accept multiple data types, while most do not. A list of configuration options and their respective type requirements for PCM plugins can be found here

Operation modes

There are different operation modes for parsing nodes, the default mode is merge and create. If operation mode is either merge/create or merge type checking is done. Only same type assignments can be merged, so strings cannot be merged with integers. Trying to define a simple assignment in default operation mode to a compound (and vice versa) will also not work.

Prefixes of operation modes:

  • "+" -- merge and create
  • "-" -- merge
  • "?" -- do not override
  • "!" -- override
Operation modes
# Merge/create - If a node does not exist, it is created. If it does exist and types match,
# subkeyN is merged into key.
key.subkeyN valueN;

# Merge/create - Equivalent to above
key.+subkeyN valueN;

# Merge - Node key.subkeyN must already exist and must have same data type
key.-subkeyN valueN;

# No override - Ignore new assignment if key.subkeyN node already exists
key.?subkeyN valueN;

# Override - Removes subkeyN and all keys below it, then creates node key.subkeyN
key.!subkeyN valueN;

Using override operation mode, when done correctly, is usually safe, however one should bear in mind, that there might be other necessary keys in a node for proper functioning.

Warning: Overriding pcm node itself will most definitely make alsa unusable, since every plugin definition will be deleted. Therefore do not use !pcm.key unless you are making a configuration from scratch.
An example of setting default device using "defaults" node

Assuming that "defaults" node is set in /usr/share/alsa/alsa.conf, where "defaults.pcm.card" and its "ctl" counterpart have assignment values "0" (type integer), user wants to set default pcm and control device to (third) sound card "2" or "SB" for an Azalia sound card.

Defaults node
defaults.ctl.card 2; # Sets default device and control to third card (counting begins with 0).
defaults.pcm.card 2; # This does not change the data type.

defaults.ctl.+card 2; # Equivalent to above.
defaults.pcm.+card 2;

defaults.ctl.-card 2; # Same effect on a default setup, however if defaults node was removed or
defaults.pcm.-card 2; # type has been changed merge operation mode will result in no changes.

defaults.pcm.?card 2; # This does nothing, since this assignment already exists.
defaults.ctl.?card 2;

defaults.pcm.!card "SB"; # The override operation mode is necessary here, because of
defaults.ctl.!card "SB"; # different value types.

Using double quotes here automatically sets values data type to string, so in the above example setting defaults.pcm.!card "2" would result in retaining last default device, in this case card 0. Using double quotes for strings is not mandatory as long as no special characters are used, which ideally should never be the case. This may be irrelevant in other assignments.

Note: From a configuration point of view those are not equivalent to setting a compound "default" pcm device, since most users specify addressing type in there also, which actually may be the same, but the assignment itself still differs. Also defaults.pcm.card is referred to multiple times in alsa configuration files, usually as a fallback assignment, where different environment variables take precedence.

Nesting

Sometimes it may be useful and even easier to read using nesting in configuration.

Nesting PCM plugins
pcm.azalia {	type hw; card 0	}
pcm.!default {	type plug; slave.pcm "azalia"	}

# is equivalent to

pcm.!default {	type plug; slave.pcm {	type hw; card 0;	}	}

# which is also equivalent to

pcm.!default.type plug;
pcm.default.slave.pcm.type hw;
pcm.default.slave.pcm.card 0;

Including configuration files

Include other configuration files
</path/to/configuration-file> # Include a configuration file
<confdir:/path/to/configuration-file> # Reference to a global configuration directory

Set the default sound card

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: Explain the difference between a "card" and a "device." amixer --help suggests the two are not synonymous (Discuss in Talk:Advanced Linux Sound Architecture#)

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements.Tango-edit-clear.png

Reason: There is no previous instruction regarding defaults.pcm.device. (Discuss in Talk:Advanced Linux Sound Architecture#)

In addition to the previous instruction regarding defaults.pcm.card and defaults.pcm.device, if your sound card order changes on boot, you can specify their order in any file ending with .conf in /etc/modprobe.d (/etc/modprobe.d/alsa-base.conf is suggested). For example, if you want your mia sound card to be #0:

/etc/modprobe.d/alsa-base.conf
options snd_mia index=0
options snd_hda_intel index=1

Use $ cat /proc/asound/modules to get the loaded sound modules and their order. This list is usually all that is needed for the loading order. Use $ lsmod | grep snd to get a devices & modules list. This configuration assumes you have one mia sound card using snd_mia and one (e.g. onboard) card using snd_hda_intel.

You can also provide an index of -2 to instruct ALSA to never use a card as the primary one. Distributions such as Linux Mint and Ubuntu use the following settings to avoid USB and other "abnormal" drivers from getting index 0:

/etc/modprobe.d/alsa-base.conf
options bt87x index=-2
options cx88_alsa index=-2
options saa7134-alsa index=-2
options snd-atiixp-modem index=-2
options snd-intel8x0m index=-2
options snd-via82xx-modem index=-2
options snd-usb-caiaq index=-2
options snd-usb-ua101 index=-2
options snd-usb-us122l index=-2
options snd-usb-usx2y index=-2
options snd-pcsp index=-2
options snd-usb-audio index=-2

These changes require a system reboot.

See also [2]

Select the default PCM via environment variable

Tip: An explanation of the terminology of a "card", "device", "subdevice" (a "card" is not a "device") and "PCM" can be found on wikipedia:Advanced Linux Sound Architecture#Concepts.

Probably it is enough to set ALSA_CARD to the name of the device. First, get the names with aplay -l, then set ALSA_CARD to the name which comes after the colon and before the bracket; e.g. if you have

card 1: HDMI [HDA ATI HDMI], device 3: HDMI 0 [HDMI 0]

then set ALSA_CARD=HDMI.

Other variables are also checked in the default global configuration:

/usr/share/alsa/alsa.conf
Variable name # Definition
ALSA_CARD # pcm.default pcm.hw pcm.plughw ctl.sysdefault ctl.hw rawmidi.default rawmidi.hw hwdep.hw
ALSA_CTL_CARD # ctl.sysdefault ctl.hw
ALSA_HWDEP_CARD # hwdep.default hwdep.hw
ALSA_HWDEP_DEVICE # hwdep.default hwdep.hw
ALSA_PCM_CARD # pcm.default pcm.hw pcm.plughw
ALSA_PCM_DEVICE # pcm.hw pcm.plughw
ALSA_RAWMIDI_CARD # rawmidi.default rawmidi.hw
ALSA_RAWMIDI_DEVICE # rawmidi.default rawmidi.hw

Alternatively, you can override the behavior in your own configuration file, preferably the global one (/etc/asound.conf). Add:

pcm.!default {
    type plug
    slave.pcm {
        @func getenv
        vars [ ALSAPCM ]
        default "hw:Audigy2"
    }
}

In this case as well, replace Audigy2 with the name of your device. You can get the names with aplay -l or you can also use PCMs like surround51. But if you need to use the microphone it is a good idea to select full-duplex PCM as default.

Now you can select the sound card when starting programs by just changing the environment variable ALSAPCM. It works fine for all program that do not allow to select the card, for the others ensure you keep the default card. For example, assuming you wrote a downmix PCM called mix51to20 you can use it with mplayer using the commandline ALSAPCM=mix51to20 mplayer example_6_channel.wav

Note: Pay attention to default addressing type.

Alternative method

Tip: This process can be partly automated using asoundconfAUR.

First you will have to find out the card and device id that you want to set as the default:

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Intel [HDA Intel], device 0: CONEXANT Analog [CONEXANT Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 1: Conexant Digital [Conexant Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: JamLab [JamLab], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: Audio [Altec Lansing XT1 - USB Audio], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
Warning: Simply setting a type hw as default card is equivalent to addressing hardware directly, which leaves the device unavailable to other applications. This method is only recommended if it is a part of a more sophisticated setup ~/.asoundrc or if user deliberately wants to address sound card directly (digital output through eic958 or dedicated music server for example).

For example, the last entry in this list has the card ID 2 and the device ID 0. To set this card as the default, you can either use the system-wide file /etc/asound.conf or the user-specific file ~/.asoundrc. You may have to create the file if it does not exist. Then insert the following options with the corresponding card.

pcm.!default {
    type hw
    card 2
}

ctl.!default {
    type hw
    card 2
}
Note: For the Asus U32U series it seems that card should be set to 1 for both pcm and ctl.

In most cases it is recommended to use sound card names instead of number references, which also solves boot order problem. Therefore the following would be correct for the above example.

pcm.!default {
    type hw
    card Audio
}

ctl.!default {
    type hw
    card Audio
}

To get valid ALSA card names, use aplay:

$ aplay -l | awk -F \: '/,/{print $2}' | awk '{print $1}' | uniq
PCH

Alternatively use cat, which might return unused devices:

$ cat /proc/asound/card*/id
PCH
ThinkPadEC
Note: This method could be problematic if your system has several cards of the same (ALSA)name.

The 'pcm' options affect which card and device will be used for audio playback while the 'ctl' option affects which card is used by control utilities like alsamixer .

The changes should take effect as soon as you (re-)start an application (MPlayer etc.). You can also test with a command like aplay.

$ aplay -D default:PCH your_favourite_sound.wav

If you receive an error regarding your asound configuration, check the upstream documentation for possible changes to the configuration file format.

Verifying correct sound modules are loaded

You can assume that udev will autodetect your sound properly. You can check this with the command:

$ lsmod | grep '^snd' | column -t
snd_hda_codec_hdmi     22378   4
snd_hda_codec_realtek  294191  1
snd_hda_intel          21738   1
snd_hda_codec          73739   3  snd_hda_codec_hdmi,snd_hda_codec_realtek,snd_hda_intel
snd_hwdep              6134    1  snd_hda_codec
snd_pcm                71032   3  snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec
snd_timer              18992   1  snd_pcm
snd                    55132   9  snd_hda_codec_hdmi,snd_hda_codec_realtek,snd_hda_intel,snd_hda_codec,snd_hwdep,snd_pcm,snd_timer
snd_page_alloc         7017    2  snd_hda_intel,snd_pcm

If the output looks similar, your sound drivers have been successfully autodetected.

Note: Since udev>=171, the OSS emulation modules (snd_seq_oss, snd_pcm_oss, snd_mixer_oss) are not loaded by default: Load them manually, if they are needed.

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
Note: If requesting help on IRC or the forums, please post the output of the above commands, if requested.

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. To solve this, you can try loading the modules manually:

  • Locate the module for your sound card: ALSA Soundcard Matrix The module will be prefixed with 'snd-' (for example: snd-via82xx).
  • Load the module.
  • Check for the device files in /dev/snd (see above) and/or try if alsamixer or amixer have reasonable output.
  • Configure snd-NAME-OF-MODULE and snd-pcm-oss to load at boot.

Getting S/PDIF output

S/PDIF is a digital audio interface often used to connect a computer to a digital amplifier (such as a home theatre with 5.1/7.1 surround sound).

Note: With some soundcards this disables analog sound output (eg. Sound Blaster Audigy 2).

Depending on what shell you use, add the following line to your shell's configuration file:

amixer -c 0 cset name='IEC958 Playback Switch' on

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

$ amixer scontrols

System-wide equalizer

Using ALSAEqual (provides UI)

Install the alsaequalAUR package. Also install lib32-alsaequalAUR for 32-bit application support.

After installing the package, add the following to your ALSA configuration file:

/etc/asound.conf
ctl.equal {
    type equal;
}

pcm.plugequal {
    type equal;
    # Modify the line below if you do not
    # want to use sound card 0.
    #slave.pcm "plughw:0,0";
    # by default we want to play from more sources at time:
    slave.pcm "plug:dmix";
}

# pcm.equal {
# If you do not want the equalizer to be your
# default soundcard comment the following
# line and uncomment the above line. (You can
# choose it as the output device by addressing
# it with specific apps,eg mpg123 -a equal 06.Back_In_Black.mp3)
pcm.!default {
    type plug;
    slave.pcm plugequal;
}

If you have a x86_64-system and are using lib32-flashplugin the sound in flash will not work with the above configuration. The configuration below enables sound in flash, but you have to specify the sound card manually in the line pcm "hw:0,0" (use aplay -l to list the available sound card and relative card and device number):

/etc/asound.conf
pcm.dmixer {
    type dmix
    ipc_key 2048
    slave {
        pcm "hw:0,0"
        buffer_size 16384
    }
}

ctl.equal {
    type equal;
}

pcm.equalizer {
    type equal
    slave.pcm "plug:dmixer"
}

pcm.!default {
    type plug
    slave.pcm equalizer
}

And you are ready to change your equalizer using command

$ alsamixer -D equal

Note that configuration file is different for each user (until not specified else) it is saved in ~/.alsaequal.bin. so if you want to use ALSAEqual with mpd or another software running under different user, you can configure it using

$ su mpd -c 'alsamixer -D equal'

or for example, you can make a symlink to your .alsaequal.bin in his home...

Managing ALSAEqual states

Install the alsaequal-mgrAUR package.

Configure the equalizer as usual with

$ alsamixer -D equal

When you are satisfied with the state, you may give it a name ("foo" in this example) and save it:

$ alsaequal-mgr save foo

The state "foo" can then be restored at a later time with

$ alsaequal-mgr load foo

You can thus create different equalizer states for games, movies, music genres, VoIP apps, etc. and reload them as necessary.

See the project page and the help message for more options.

Using mbeq

Note: This method requires the use of a LADSPA plugin which might be CPU intensive during playback. In addition, this was made with stereophonic sound (e.g. headphones) in mind.

Install the alsa-plugins, ladspa and swh-plugins packages if you do not already have them.

If you have not already created either an ~/.asoundrc or a /etc/asound.conf file, then create either one and insert the following:

/etc/asound.conf
pcm.eq {
    type ladspa

    # The output from the EQ can either go direct to a hardware device
    # (if you have a hardware mixer, e.g. SBLive/Audigy) or it can go
    # to the software mixer shown here.
    #slave.pcm "plughw:0,0"
    slave.pcm "plug:dmix"

    # Sometimes you may need to specify the path to the plugins,
    # especially if you have just installed them.  Once you have logged
    # out/restarted this should not be necessary, but if you get errors
    # about being unable to find plugins, try uncommenting this.
    #path "/usr/lib/ladspa"

    plugins [
    {
        label mbeq
        id 1197
        input {
            # The following setting is just an example, edit to your own taste:
            # bands: 50hz, 100hz, 156hz, 220hz, 311hz, 440hz, 622hz, 880hz, 1250hz, 1750hz, 25000hz,
            # 50000hz, 10000hz, 20000hz
            controls [ -5 -5 -5 -5 -5 -10 -20 -15 -10 -10 -10 -10 -10 -3 -2 ]
            }
        }
    ]
}

# Redirect the default device to go via the EQ - you may want to do
# this last, once you are sure everything is working.  Otherwise all
# your audio programs will break/crash if something has gone wrong.
pcm.!default {
    type plug
    slave.pcm "eq"
}

# Redirect the OSS emulation through the EQ too (when programs are running through "aoss")
pcm.dsp0 {
    type plug
    slave.pcm "eq"
}

High quality resampling

When software mixing is enabled, ALSA is forced to resample everything to the same frequency (48 kHz by default when supported). By default, it will try to use the speexrate converter to do so, and fallback to low-quality linear interpolation if it is not available[3]. Thus, if you are getting poor sound quality due to bad resampling, the problem can be solved by simply installing the alsa-plugins package.

For even higher quality resampling, you can change the default rate converter to speexrate_medium or speexrate_best. Both perform well enough that in practice it does not matter which one you choose, so using the best converter is usually not worth the extra CPU cycles it requires.

To change the default converter place the following contents in your ~/.asoundrc or /etc/asound.conf:

/etc/asound.conf
defaults.pcm.rate_converter "speexrate_medium"
Note: It is also possible to use libsamplerate converters, which are only about half as fast as the speexrate converters but do not achieve much higher quality. See discussion.
Note: It is also possible to use lavcrate resamplers that use ffmpeg With filter sizes of lavcrate_faster:4 lavcrate_fast:8 lavcrate:16 lavcrate_high:32 lavcrate_higher:64 With the last 2 options being equal to Kodi low and medium quality resamplers respectively
Note: Some applications (like MPlayer and its forks) do their own resampling by default because some ALSA drivers have incorrect delay reporting when resampling is enabled (hence leading to AV desynchronization), so changing this setting will not have any effect unless you configure them to use ALSA resampling.

Upmixing/downmixing

Upmixing

In order for stereo sources like music to be able to saturate a 5.1 or 7.1 sound system, you need to use upmixing. In darker days this used to be tricky and error prone but nowadays plugins exist to easily take care of this task. We will use the upmix plugin, included in the alsa-plugins package.

Then add the following to your ALSA configuration file of choice (either /etc/asound.conf or ~/.asoundrc):

pcm.upmix71 {
    type upmix
    slave.pcm "surround71"
    delay 15
    channels 8
}

You can easily change this example for 7.1 upmixing to 5.1 or 4.0.

The following example adds a new PCM channel that you can use for upmixing. If you want all sound sources to go through this channel, add it as a default below the previous definition like so:

pcm.!default "plug:upmix71"

The plugin automatically allows multiple sources to play through it without problems so setting is as a default is actually a safe choice. If this is not working, you have to setup your own dmixer for the upmixing PCM like this:

pcm.dmix6 {
    type asym
    playback.pcm {
        type dmix
        ipc_key 567829
        slave {
            pcm "hw:0,0"
            channels 6
        }
    }
}

and use "dmix6" instead of "surround71". If you experience skipping or distorted sound, consider increasing the buffer_size (to 32768, for example) or use a high quality resampler.

Downmixing

If you want to downmix sources to stereo because you, for instance, want to watch a movie with 5.1 sound on a stereo system, use the vdownmix plugin, included in the alsa-plugins package.

Again, in your configuration file, add this:

pcm.!surround51 {
    type vdownmix
    slave.pcm "default"
}
pcm.!surround40 {
    type vdownmix
    slave.pcm "default"
}
Note: This might not be enough to make downmixing working, see [4]. So, you might also need to add pcm.!default "plug:surround51" or pcm.!default "plug:surround40". Only one vdownmix plug can be used; if you have 7.1 channels, you will need to use surround71 instead the configuration above. A good example, which includes a configuration that makes both vdownmix and dmix working, can be found here.

Dmix

Mixing enables multiple applications to output sound at the same time. Most discrete sound cards support hardware mixing, which is enabled by default if available. Integrated motherboard sound cards (such as Intel HD Audio), usually do not support hardware mixing. On such cards, software mixing is done by an ALSA plugin called dmix. This feature is enabled automatically if hardware mixing is unavailable.

Note: Dmix is enabled by default for soundcards which do not support hardware mixing. Dmix is not enabled by default for digital output (S/PDIF) and will require the configuration snippet below.

To manually enable dmix, add the following to your ALSA configuration file:

/etc/asound.conf
pcm.dsp {
    type plug
    slave.pcm "dmix"
}

Tips and tricks

Hot-plugging a USB sound card

See Writing Udev rules for ALSA.

Simultaneous output

You might want to play music via external speakers connected via mini jack and internal speakers simultaneously. This can be done by unmuting Auto-Mute item using alsamixer or amixer:

$ amixer sset "Auto-Mute" unmute

and then unmuting other required items, such as Headphones, Speaker, Bass Speaker...

Note: If you have a crackling sound through headphones connector (mini-jack) after, see here.

Keyboard volume control

Map the following commands to your volume keys: XF86AudioRaiseVolume, XF86AudioLowerVolume, XF86AudioMute

To raise the volume:

amixer set Master 5%+

To lower the volume:

amixer set Master 5%-

To toggle mute/unmute of the volume:

amixer set Master toggle

Virtual sound device using snd-aloop

You might want a jack alternative to create a virtual recording or play device in order to mix different sources, using the snd-aloop module:

modprobe snd-aloop

List your new virtual devices using:

aplay -l

now you can for example using ffmpeg:

ffmpeg -f alsa -i hw:1,1,0 -f alsa -i hw:1,1,1 -filter_complex amerge output.mp3

In the hw:R,W,N format R is your virtual card device number, W 1 recording devices 0 for writing, N is your sub device you can use all the virtual devices available and play/stop using applications like mplayer:

mplayer -ao alsa:device=hw=1,0,0 fileA
mplayer -ao alsa:device=hw=1,0,1 fileB 

Another thing you could do with this approach, is using festival to generate a voice into a recording stream using an script like this:

#!/bin/bash
echo $1|iconv -f utf-8 -t iso-8859-1| text2wave  > "_tmp_.wav";   
mplayer -ao alsa:device=hw=2,0,0 "_tmp.wav";
rm "_tmp.wav";

Debugging ALSA

Retrieving the driver state

The alsa-utils package also contains the alsa-info.sh command, which can be used to gather detailed data on the ALSA driver and user-space state.

See ALSA bug tracking for more info.

Reconfiguring input/output ports

The alsa-tools package contains the hdajackretask tool, which can be used (on Intel HDA cards) to reconfigure the sound card input/output ports; for instance, to turn a microphone jack into a headphone jack.

Resetting codecs

The ALSA driver can fully reconfigure attached codecs (the parts of the sound system that actually process audio streams), by doing:

# echo 1 > /sys/class/sound/card/reconfig

Before doing this, all processes using the ALSA driver (such as Pulseaudio or JACK) must be stopped.

Correctly detect microphone plugged in a 4-pin 3.5mm (TRRS) jack

On some modern laptops you may have a combined 3.5mm headset jack, instead of two separated ones, which may not be correctly detected by default. To make ALSA correctly detect plug-in status on your 3.5mm jack, you could put the following line into your /etc/modprobe.d/alsa-base.conf :

# options snd_hda_intel index=0 model=[YOUR_MODEL_SETTING]

For complete list of options put in [YOUR_MODEL_SETTING], see HD-Audio-Models.txt. Tested with Gigabyte Aero15 2017 (P65 Model), with ALC255 and set model to dell-headset-multi.

See also