Difference between revisions of "Advanced Linux Sound Architecture"

From ArchWiki
Jump to: navigation, search
m (Previous fix would go away every time pm-utils was updated. Added a more permanent solution.)
m ("config file" -> "configuration file")
 
(297 intermediate revisions by 81 users not shown)
Line 1: Line 1:
 
[[Category:Sound]]
 
[[Category:Sound]]
[[Category:Audio/Video]]
 
 
[[cs:Advanced Linux Sound Architecture]]
 
[[cs:Advanced Linux Sound Architecture]]
 
[[de:Alsa]]
 
[[de:Alsa]]
Line 8: Line 7:
 
[[he:Advanced Linux Sound Architecture]]
 
[[he:Advanced Linux Sound Architecture]]
 
[[it:Advanced Linux Sound Architecture]]
 
[[it:Advanced Linux Sound Architecture]]
 +
[[ja:Advanced Linux Sound Architecture]]
 
[[nl:Advanced Linux Sound Architecture]]
 
[[nl:Advanced Linux Sound Architecture]]
 
[[pt:Advanced Linux Sound Architecture]]
 
[[pt:Advanced Linux Sound Architecture]]
Line 13: Line 13:
 
[[sk:Advanced Linux Sound Architecture]]
 
[[sk:Advanced Linux Sound Architecture]]
 
[[th:Advanced Linux Sound Architecture]]
 
[[th:Advanced Linux Sound Architecture]]
[[tr:Gelişmiş_ses_mimarisi_(ALSA)]]
+
[[tr:Gelişmiş ses mimarisi (ALSA)]]
 
[[zh-CN:Advanced Linux Sound Architecture]]
 
[[zh-CN:Advanced Linux Sound Architecture]]
The [[Wikipedia:Advanced Linux Sound Architecture|Advanced Linux Sound Architecture]] ('''ALSA''') is a Linux kernel component which replaced the original Open Sound System (OSSv3) for providing device drivers for sound cards. Besides the sound device drivers, '''ALSA''' also bundles a user space library for application developers who want to use driver features with a higher level API than direct interaction with the kernel drivers.
+
{{Related articles start}}
 +
{{Related|Advanced Linux Sound Architecture/Example Configurations}}
 +
{{Related|Advanced Linux Sound Architecture/Troubleshooting}}
 +
{{Related|Sound system}}
 +
{{Related|Disable PC Speaker Beep}}
 +
{{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).
  
{{Note|For an alternative sound environment, see the [[Open Sound System]] page.}}
+
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.
  
{{Article summary start}}
+
== Installation ==
{{Article summary text|Using, configuring and troubleshooting ALSA.}}
+
{{Article summary heading|Related}}
+
{{Article summary wiki|Sound}}
+
{{Article summary wiki|Disable PC Speaker Beep}}
+
{{Article summary end}}
+
  
==Installation==
+
ALSA is a set of built-in GNU/Linux kernel modules. Therefore, manual installation is not necessary.
ALSA is included in the default Arch kernel as a set of modules, so installing it is not necessary.
+
  
[[udev]] will automatically probe your hardware at boot, loading the corresponding kernel module for your audio card. Therefore, your sound should already be working, but upstream sources mute all channels by default.
+
[[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]].
  
Users with a local login (at a virtual terminal or a display manager) have permission to play audio and change mixer levels. To allow this for a remote login, the user has to be [[Users and Groups#Group management|added]] to the {{ic|audio}} group. Membership in the {{ic|audio}} group also allows direct access to devices, which can lead to applications grabbing exclusive output (breaking software mixing) and breaks fast-user-switching, and multiseat.
+
=== User privileges ===
  
===User-space utilities===
+
Usually, local users have permission to play audio and change mixer levels.
From [[Official Repositories|official repositories]]:
+
* [[pacman|Install]] the {{Pkg|alsa-utils}} package which contains the {{ic|alsamixer}} user-space tool, which allows for configuration of the sound device from the console or terminal.
+
* Install the {{Pkg|alsa-oss}} package if you want OSS applications to work with dmix (software mixing).
+
{{Note|1=Since [[udev]] >= 171, the OSS emulation modules ({{ic|snd_seq_oss}}, {{ic|snd_pcm_oss}}, {{ic|snd_mixer_oss}}) are not automatically loaded by default.}}
+
*Install the {{Pkg|alsa-plugins}} package if you want [[#High quality resampling|high quality resampling]], [[#Upmixing/Downmixing|upmixing/downmixing]] and other advanced features.
+
  
==Unmuting the channels==
+
To allow remote users to use ALSA, you need to [[Users and groups#Group management|add]] those users to the {{ic|audio}} group.  
The current version of ALSA installs with all channels '''muted by default'''. You will need to unmute the channels manually.
+
  
It is easiest to use {{ic|alsamixer}} ncurses UI to accomplish this:
+
{{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].}}
  
$ alsamixer
+
=== ALSA Utilities ===
  
Alternatively, use {{ic|amixer}} from the command-line:
+
[[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.
  
$ amixer sset Master unmute
+
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.
  
The label {{ic|MM}} below a channel indicates that the channel is muted, and {{ic|00}} indicates that it is open.
+
=== OSS compatibility ===
  
Scroll to the {{ic|Master}} and {{ic|PCM}} channels with the {{keypress|←}} and {{keypress|→}} keys and unmute them by pressing the {{keypress|m}} key. Use the {{keypress|↑}} 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. Higher values of gain will produce distorted sound.
+
{{Note|This is important if your application complains about missing {{ic|/dev/dsp}} or {{ic|/dev/snd/seq}}.}}
  
To get full 5.1 or 7.1 surround sound you likely need to unmute other channels such as Front, Surround, Center, LFE (subwoofer) and Side (these are the names of the channels with Intel HD Audio, they may vary with different hardware). Please take note that this will not automatically upmix stereo sources (like most music). In order to accomplish that, see [[#Upmixing/Downmixing]].
+
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.
  
Leave alsamixer by pressing {{Keypress|Esc}}.
+
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.
  
{{Note|
+
=== ALSA and Systemd ===
* 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.
+
* Some machines, (like the Thinkpad T61), have a Speaker channel which must be unmuted and adjusted as well.
+
* Some machines, (like Dell E6400) may also require the {{ic|Front}} and {{ic|Headphone}} channels to be unmuted and adjusted.}}
+
  
Next, test to see if sound works:
+
The {{Pkg|alsa-utils}} package comes with [[systemd]] unit configuration files {{ic|alsa-restore.service}} and {{ic|alsa-state.service}} by default.
  
$ speaker-test -c 2
+
These are automatically installed and activated during installation. Therefore, there is no further action needed. Though, you can check their status using {{ic|systemctl}}.
  
Change -c to fit your speaker setup. Use -c 8 for 7.1, for instance:
+
{{note|For reference, ALSA stores its settings in {{ic|/var/lib/alsa/asound.state}}}}
  
$ speaker-test -c 8
+
=== ALSA Firmware ===
  
If it does not work, proceed to [[#Configuration]] and then [[#Troubleshooting]] to solve your issues.
+
The {{Pkg|alsa-firmware}} package contains firmware that may be required for certain sound cards (e.g. Creative SB0400 Audigy2).
  
The {{pkg|alsa-utils}} package includes {{ic|alsa-restore.service}} and {{ic|alsa-store.service}}, which are preconfigured to run at boot and shutdown respectively.
+
== Unmuting the channels ==
  
==Configuration==
+
By default ALSA has all channels muted. Those have to be unmuted manually.
===No sound in virtualbox===
+
If you experience problems with virtualbox, the following command might be helpful:
+
  
{{hc|$ alsactl init|2=<nowiki>
+
=== Unmute with amixer ===
  
Found hardware: "ICH" "SigmaTel STAC9700,83,84" "AC97a:83847600" "0x8086" "0x0000"
+
Unmuting the sound card's master volume can be done by using ''amixer'':
Hardware is initialized using a generic method
+
</nowiki>
+
}}
+
  
You might need to activate the ALSA output in your audio software as well.
+
$ amixer sset Master unmute
  
===Set the default sound card===
+
=== Unmute with alsamixer ===
  
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).
+
Unmuting the sound card can be done using ''alsamixer'':
For example, if you want your mia sound card to be #0:
+
  
{{hc|/etc/modprobe.d/alsa-base.conf|2=<nowiki>
+
$ alsamixer
options snd slots=snd_mia,snd_hda_intel
+
options snd_mia index=0
+
options snd_hda_intel index=1
+
</nowiki>}}
+
  
snd_mia and snd_hda_intel are the modules used by the respective cards.  This configuration assumes you have one mia sound card and one card using snd_hda_intel (e.g. onboard).
+
The {{ic|MM}} label below a channel indicates that the channel is muted, and {{ic|00}} indicates that it is open.
  
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:
+
Scroll to the {{ic|Master}} and {{ic|PCM}} channels with the {{ic|←}} and {{ic|→}} keys and unmute them by pressing the {{ic|m}} key.
  
{{hc|/etc/modprobe.d/alsa-base.conf|2=<nowiki>
+
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.
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-audio 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
+
# Keep snd-pcsp from being loaded as first soundcard
+
options snd-pcsp index=-2
+
# Keep snd-usb-audio from beeing loaded as first soundcard
+
options snd-usb-audio index=-2
+
</nowiki>}}
+
  
These changes require a system reboot.
+
{{Note|If gain is set above 0 dB audible distortion can become present.}}
  
{{Out of date|{{ic|/etc/asound.conf}} does not exist on a default setup, and these instructions may not work.}}
+
=== Unmute 5.1/7.1 sound ===
  
First you will have to find out the card and device id that you want to set as the default by running {{ic|aplay -l}}:
+
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)
  
{{hc|$ aplay -l|2=<nowiki>
+
{{note|Please take note that this will not automatically upmix stereo sources (like most music). In order to accomplish that, see [[#Upmixing/downmixing]].}}
**** 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
+
</nowiki>}}
+
  
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 and device id.
+
=== Enable the microphone ===
{{hc|~/.asoundrc|2=<nowiki>
+
defaults.pcm.card 2
+
defaults.pcm.device 0
+
defaults.ctl.card 2
+
</nowiki>}}
+
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.).
+
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.
  
===Making sure the sound modules are loaded===
+
=== Test your changes ===
You can assume that udev will autodetect your sound properly. You can check this with the command
+
  
{{hc|<nowiki>$ lsmod | grep '^snd' | column -t</nowiki>|<nowiki>
+
Next, test to see if sound works:
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
+
</nowiki>}}
+
  
If the output looks similar, your sound drivers have been successfully autodetected.
+
$ speaker-test -c 2
{{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#Loading|Load them manually]] if they are needed.}}
+
  
You might also want to check the directory {{ic|/dev/snd/}} for the right device files:
+
Change {{ic|-c}} to fit your speaker setup. Use {{ic|-c 8}} for 7.1, for instance:
  
{{hc|$ ls -l /dev/snd|2=<nowiki>
+
$ speaker-test -c 8
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
+
</nowiki>}}
+
  
{{Note|If requesting help on IRC or the forums, please post the output of the above commands.}}
+
If audio is being outputted to the wrong device, try manually specifying it with the argument {{ic|-D}}.
  
If you have at least the devices '''controlC0''' and '''pcmC0D0p''' or similar, then your sound modules have been detected and loaded properly.
+
$ speaker-test -D default:PCH -c 8
  
If this is not the case, your sound modules have not been detected properly. To solve this, you can try loading the modules manually:
+
{{ic|-D}} accepts PCM channel names as values, which can be retrieved by running the following:
  
* 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}}).
+
{{hc|<nowiki>$ aplay -L | grep :CARD</nowiki>|2=
* [[Kernel modules#Loading|Load the module]].
+
default:CARD=PCH  # 'default:PCH' is the PCM channel name for -D
* Check for the device files in {{ic|/dev/snd}} (see above) and/or try if {{ic|alsamixer}} or {{ic|amixer}} have reasonable output.
+
sysdefault:CARD=PCH
* Configure {{ic|snd-NAME-OF-MODULE}} and {{ic|snd-pcm-oss}} to [[Kernel modules#Loading|load at boot]].
+
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
 +
}}
  
===Getting SPDIF Output===
+
If that does not work, consult the [[#Configuration]] section or the [[ALSA/Troubleshooting]] page.
(from gralves from the Gentoo forums)
+
* In GNOME Volume Control, under the Options tab, change the IEC958 to PCM.  This option can be enabled in the preferences.
+
* If you do not have GNOME Volume Control installed,
+
** Edit {{ic|/var/lib/alsa/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 {{ic|value:false}}. Change it to {{ic|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):
+
=== Additional notes ===
  
* add following lines to {{ic|/etc/rc.local}}:
+
* If your system has more than one soundcard, then you can switch between them by pressing {{ic|F6}}
  # Use COAX-digital output
+
  amixer set 'IEC958 Optical' 100 unmute
+
  amixer set 'Audigy Analog/Digital Output Jack' on
+
  
You can see the name of your card's digital output with:
+
* 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}}.
  $ amixer scontrols
+
  
===System-Wide Equalizer===
+
* Some machines, (like the Thinkpad T61), have a {{ic|Speaker}} channel which must be unmuted and adjusted as well.
====Using AlsaEqual (provides UI)====
+
Install {{AUR|alsaequal}} from the [[AUR]].
+
  
{{Note | If you have a x86_64-system and are using a 32bit-flashplugin the sound in flash will not work. Either you have to disable alsaequal or build alsaequal for 32bit.}}
+
* Some machines, (like the Dell E6400) may also require the {{ic|Front}} and {{ic|Headphone}} channels to be unmuted and adjusted.
  
After installing the package, insert the following into your ALSA configuration file ({{ic|~/.asoundrc}} or {{ic|/etc/asound.conf}}):
+
* If your volume adjustments seem to be lost after you reboot, try running alsamixer as root.
  
ctl.equal {
+
== Configuration ==
  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 don't 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;
+
}
+
+
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 {{ic|~/.alsaequal.bin}}.
+
The system configuration file is {{ic|/etc/asound.conf}}, and the per-user configuration file is {{ic|~/.asoundrc}}.
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=====
+
=== Basic syntax ===
Install [http://xyne.archlinux.ca/projects/alsaequal-mgr/ alsaequal-mgr] from [http://xyne.archlinux.ca/repos/ Xyne's repos] or the [https://aur.archlinux.org/packages.php?ID=62420 AUR].
+
  
Configure the equalizer as usual with
+
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].
$alsamixer -D equal
+
  
When you are satisfied with the state, you may give it a name ("foo" in this example) and save it:
+
==== Assignments and Separators ====
$alsaequal-mgr save foo
+
  
The state "foo" can then be restored at a later time with
+
Assignments define a value of a given key. There are different assignment types and styles available.
$alsaequal-mgr load foo
+
  
You can thus create different equalizer states for games, movies, music genres, VoIP apps, etc. and reload them as necessary.
+
{{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.
  
See the [http://xyne.archlinux.ca/projects/alsaequal-mgr/ project page] and the help message for more options.
+
key value # Equivalent to the example above.
 +
}}
  
====Using mbeq====
+
Separators are used to indicate the start and end of an assignment, but using commas or whitespace is also possible.
{{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.}}
+
  
Install the {{Pkg|alsa-plugins}}, {{Pkg|ladspa}} and {{Pkg|swh-plugins}} packages if you do not already have them.
+
{{hc|Separators|2=
 +
# The following three assignments are equivalent.
 +
key value0; key valueN;
 +
key value0, key valueN,
 +
key value0 key valueN
  
* 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:
+
key
 +
value0
 +
key
 +
valueN
 +
}}
  
{{hc|/etc/asound.conf|2=<nowiki>pcm.eq {
+
Compound assignments use braces as separators.
  type ladspa
+
{{hc|Compound assignment|2=
 +
key { subkey0 value0;
 +
subkeyN valueN; }
  
  # The output from the EQ can either go direct to a hardware device
+
key.subkey0 value0; # Equivalent to the example above.
  # (if you have a hardware mixer, e.g. SBLive/Audigy) or it can go
+
key.subkeyN valueN;
  # 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,
+
For easier reading, it is recommended to use first style for definitions including more than three keys.
  # 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 [
+
Array definitions use brackets as separators.
    {
+
      label mbeq
+
      id 1197
+
      input {
+
        #this setting is here by 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
+
{{hc|Single array|2=
# this last, once you're sure everything is working.  Otherwise all
+
key [ "value0";
# your audio programs will break/crash if something has gone wrong.
+
"valueN"; ]
  
pcm.!default {
+
key.0 "value0"; # Equivalent to the example above
  type plug
+
key.N "valueN";
  slave.pcm "eq"
+
}}
}
+
  
# Redirect the OSS emulation through the EQ too (when programs are running through "aoss")
+
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].
  
pcm.dsp0 {
+
==== Data types ====
  type plug
+
  slave.pcm "eq"
+
}
+
</nowiki>}}
+
  
* You should be good to go (if not, ask in the forum).
+
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]
  
==High quality resampling==
+
==== Operation modes ====
When software mixing is enabled, ALSA is forced to resample everything to the same frequency (48000 by default when supported). dmix uses a poor resampling algorithm which produces noticeable sound quality loss.
+
  
Install {{pkg|alsa-plugins}} and {{pkg|libsamplerate}}.
+
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.
  
Change the default rate converter to libsamplerate:
+
Prefixes of operation modes:
 +
* "+" -- merge and create
 +
* "-" -- merge
 +
* "?" -- do not override
 +
* "!" -- override
  
{{hc|/etc/asound.conf|defaults.pcm.rate_converter "samplerate_best"}}
+
{{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;
  
or
+
# Merge/create - Equivalent to above
 +
key.+subkeyN valueN;
  
{{hc|~/.asoundrc|defaults.pcm.rate_converter "samplerate_best"}}
+
# Merge - Node key.subkeyN must already exist and must have same data type
 +
key.-subkeyN valueN;
  
'''samplerate_best''' offers the best sound quality, but you need a decent CPU to be able to use it as it requires a lot of CPU cycles for real-time resampling. There are other algorithms available ('''samplerate''', etc.) but they may not provide much of an improvement over the default resampler.
+
# No override - Ignore new assignment if key.subkeyN node already exists
 +
key.?subkeyN valueN;
  
{{Warning|On some systems, enabling samplerate_best may cause an issue where you get no sound from flashplayer.}}
+
# Override - Removes subkeyN and all keys below it, then creates node key.subkeyN
 +
key.!subkeyN valueN;
 +
}}
  
==Upmixing/Downmixing==
+
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.
===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. Thus, install {{Pkg|alsa-plugins}}.
+
  
Then add the following to your ALSA configuration file of choice (either {{ic|/etc/asound.conf}} or {{ic|~/.asoundrc}}):
+
{{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.}}
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.
+
===== An example of setting default device using "defaults" node =====
  
This adds a new pcm that you can use for upmixing. If you want all sound sources to go through this pcm, add it as a default below the previous definition like so:
+
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.
  
pcm.!default "plug:upmix71"
+
{{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.
  
The plugin automatically allows multiple sources to play through it without problems so setting is as a default is actually a safe choice.  
+
defaults.ctl.+card 2; # Equivalent to above.
If this is not working, you have to setup your own dmixer for the upmixing PCM like this:
+
defaults.pcm.+card 2;
pcm.dmix6 {
+
    type asym
+
    playback.pcm {
+
        type dmix
+
        ipc_key 567829
+
        slave {
+
            pcm "hw:0,0"
+
            channels 6
+
        }
+
    }
+
}
+
  
and use "dmix6" instead of "surround71".  
+
defaults.ctl.-card 2; # Same effect on a default setup, however if defaults node was removed or
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]].
+
defaults.pcm.-card 2; # type has been changed merge operation mode will result in no changes.
  
===Downmixing===
+
defaults.pcm.?card 2; # This does nothing, since this assignment already exists.
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, you need to use the vdownmix plugin that alsa provides in the same package.
+
defaults.ctl.?card 2;
  
Again, in your configuration file, add this:
+
defaults.pcm.!card "SB"; # The override operation mode is necessary here, because of
 +
defaults.ctl.!card "SB"; # different value types.
 +
}}
  
pcm.!surround51 {
+
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.
    type vdownmix
+
    slave.pcm "default"
+
}
+
pcm.!surround40 {
+
    type vdownmix
+
    slave.pcm "default"
+
}
+
  
==Mixing==
+
{{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.}}
===Software mixing (dmix)===
+
  
{{Note|For ALSA 1.0.9rc2 and higher on analog sound outputs you do not need to setup dmix. Dmix is enabled as default for soundcards which do not support hardware mixing.}}
+
==== Nesting ====
  
If that does not work however, it is a matter of simply creating a .asoundrc file in your home folder with the following contents.
+
Sometimes it may be useful and even easier to read using nesting in configuration.
  
pcm.dsp {
+
{{hc|Nesting PCM plugins|2=
    type plug
+
pcm.azalia { type hw; card 0 }
    slave.pcm "dmix"
+
pcm.!default { type plug; slave.pcm "azalia" }
}
+
  
This should enable software mixing and allows more than one application to make use of the soundcard.
+
# is equivalent to
  
For a digital sound output such as S/PDIF, the ALSA package still does not enable dmix by default. Thus, the dmix configuration above can be used to enable dmix for S/PDIF devices.
+
pcm.!default { type plug; slave.pcm { type hw; card 0; } }
  
See [[#Troubleshooting]] for common problems and solutions.
+
# which is also equivalent to
  
===Hardware mixing===
+
pcm.!default.type plug;
====Support====
+
pcm.default.slave.pcm.type hw;
If you have an audio chipset that supports mixing in hardware, then no configuration is necessary. Almost every onboard audio chipset does not support hardware mixing, and requires mixing to be done in software (see above). Many sound cards do support hardware mixing, and the ones best supported on Linux are listed below:
+
pcm.default.slave.pcm.card 0;
 +
}}
  
* Creative SoundBlaster Live! (5.1 model)
+
==== Including configuration files ====
* Creative SoundBlaster Audigy (some models)
+
* Creative SoundBlaster Audidy 2 (ZS models)
+
* Creative SoundBlaster Audigy 4 (Pro models)
+
  
{{Note|The low end variants of above cards, (Audigy SE, Audigy 2 NX, SoundBlaster Live! 24bit and SoundBlaster Live! 7.1) '''do not''' support hardware mixing as they use other chips.}}
+
{{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
 +
}}
  
{{Note|The onboard VIA8237 chip supports 4-stream hardware mixing, however, it does only 3 for some motherboards (the 4th makes no sound) or is just broken. Even if it works, the quality is not good compared to other solutions.}}
+
=== Set the default sound card ===
  
====Fixes====
+
{{Expansion|Explain the difference between a "card" and a "device." {{ic|amixer --help}} suggests the two are not synonymous}}
If you are using 64-bit Arch and the Intel Corporation 82801I (ICH9 Family) HD Audio Controller (rev 02), you can get sound working for Enemy Territory with the following:
+
echo "et.x86 0 0 direct" > /proc/asound/card0/pcm0p/oss
+
echo "et.x86 0 0 disable" > /proc/asound/card0/pcm0c/oss
+
  
==Troubleshooting==
+
{{Style|There is no previous instruction regarding {{ic|defaults.pcm.device}}.}}
===Sound Skipping While Using Dynamic Frequency Scaling===
+
Some combinations of ALSA drivers and chipsets may cause audio from all sources to skip when used in combination with a dynamic frequency scaling governor such as {{ic|ondemand}} or {{ic|conservative}}. Currently, the solution is to switch back to the {{ic|performance}} governor.
+
  
Refer to the [[CPU Frequency Scaling]] for more information.
+
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:
  
===Problems with Availability to Only One User at a Time===
+
{{hc|/etc/modprobe.d/alsa-base.conf|2=
You might find that only one user can use the dmixer at a time.  This is probably ok for most, but for those who run [[mpd]] as a separate user this poses a problem.  When mpd is playing a normal user cannot play sounds though the dmixer.  While it's quite possible to just run mpd under a user's login account, another solution has been found.  Adding the line {{ic|ipc_key_add_uid 0}} to the {{ic|pcm.dmixer}} block disables this locking. The following is a snippet of the {{ic|asound.conf}}, the rest is the same as above.
+
options snd_mia index=0
...
+
options snd_hda_intel index=1
pcm.dmixer {
+
}}
  type dmix
+
  ipc_key 1024
+
  ipc_key_add_uid 0
+
  ipc_perm 0660
+
slave {
+
...
+
  
 +
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}}.
  
===Simultaneous Playback Issues===
+
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=
If you are having simultaneous playback issues, and if [[PulseAudio]] is installed (i.e. by [[GNOME]]), its default configuration is set to "hijack" the soundcard. Some users of ALSA may not want to use [[PulseAudio]] and are quite content with their current ALSA settings. One fix is to edit {{ic|/etc/asound.conf}} and comment out the following lines:
+
options bt87x index=-2
# Use PulseAudio by default
+
options cx88_alsa index=-2
#pcm.!default {
+
options saa7134-alsa index=-2
#  type pulse
+
options snd-atiixp-modem index=-2
#  fallback "sysdefault"
+
options snd-intel8x0m index=-2
#  hint {
+
options snd-via82xx-modem index=-2
#    show on
+
options snd-usb-caiaq index=-2
#    description "Default ALSA Output (currently PulseAudio Sound Server)"
+
options snd-usb-ua101 index=-2
#  }
+
options snd-usb-us122l index=-2
#}
+
options snd-usb-usx2y index=-2
 
+
options snd-pcsp index=-2
Commenting the following out also may help:
+
options snd-usb-audio index=-2
#ctl.!default {
+
#  type pulse
+
#  fallback "sysdefault"
+
#}
+
 
+
This may be a much simpler solution than completely uninstalling [[PulseAudio]].
+
 
+
Effectively, here is an example of a working {{ic|/etc/asound.conf}}:
+
{{bc|<nowiki>pcm.dmixer {
+
        type dmix
+
        ipc_key 1024
+
        ipc_key_add_uid 0
+
        ipc_perm 0660
+
}
+
pcm.dsp {
+
        type plug
+
        slave.pcm "dmix"
+
}</nowiki>
+
 
}}
 
}}
  
{{note|This {{ic|/etc/asound.conf}} file was intended for and used successfully with a global [[MPD]] configuration. See [[Alsa#Problems_with_Availability_to_Only_One_User_at_a_Time|this section]] on multiple users}}
+
These changes require a system reboot.
  
===Random Lack of Sound on Startup===
+
See also [https://bbs.archlinux.org/viewtopic.php?pid=1446773#p1446773]
If you randomly have no sound on startup, it may be because your system has multiple sound cards, and their order may sometimes change on startup.  If this is the case, try [[#Set the default sound card|setting the default sound card]].
+
  
If you use mpd and the configuration tips above do not work for you, try [http://mpd.wikia.com/wiki/Configuration#ALSA_MPD_software_volume_control reading this] instead.
+
==== Select the default PCM via environment variable ====
  
===Specific Program Problems===
+
{{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]].}}
For other programs who insist on their own audio setup, eg, XMMS or Mplayer, you would need to set their specific options.
+
  
For mplayer, open up {{ic|~/.mplayer/config}} (or {{ic|/etc/mplayer/mplayer.conf}} for global setting) and add the following line:
+
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
ao=alsa
+
  
For XMMS/Beep Media Player, go into their options and make sure the sound driver is set to Alsa, not oss.
+
{{ic|card 1: HDMI [HDA ATI HDMI], device 3: HDMI 0 [HDMI 0]}}
  
To do this in XMMS:
+
then set ALSA_CARD=HDMI.
* Open XMMS
+
** Options -> preferences.
+
** Choose the Alsa output plugin.
+
  
For applications which do not provide a ALSA output, you can use aoss from the alsa-oss package. To use aoss, when you run the program, prefix it with {{ic|aoss}}, eg:
+
Other variables are also checked in the default global configuration:
aoss realplay
+
{{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
 +
}}
  
pcm.!default{ ... } doesnt work for me anymore. but this does:
+
Alternatively, you can override the behavior in your own configuration file, preferably the global one (/etc/asound.conf)Add:
  pcm.default pcm.dmixer
+
{{bc|1=
 +
pcm.!default {
 +
    type plug
 +
    slave.pcm {
 +
        @func getenv
 +
        vars [ ALSAPCM ]
 +
        default "hw:Audigy2"
 +
    }
 +
}
 +
}}
  
===Model Settings===
+
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.
Although Alsa detects your soundcard through the BIOS at times Alsa may not be able to recognize your [http://www.kernel.org/doc/Documentation/sound/alsa/HD-Audio-Models.txt model type].  The soundcard chip can be found in {{ic|alsamixer}} (e.g. ALC662) and the model can be set in {{ic|/etc/modprobe.d/modprobe.conf}} or {{ic|/etc/modprobe.d/sound.conf}}. For example:
+
  
options snd-hda-intel model=MODEL
+
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}}
  
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 {{ic|/etc/modprobe.d/modprobe.conf}}.  For example, for an Intel AC97 audio:
+
{{note|Pay attention to default addressing type.}}
  
{{bc|# ALSA portion
+
==== Alternative method ====
alias char-major-116 snd
+
{{Tip|This process can be partly automated using {{AUR|asoundconf}}.}}
alias snd-card-0 snd-intel8x0
+
# module options should go here
+
  
# OSS/Free portion
+
First you will have to find out the card and device id that you want to set as the default:
alias char-major-14 soundcore
+
alias sound-slot-0 snd-card-0
+
  
# card #1
+
{{hc|$ aplay -l|2=
alias sound-service-0-0 snd-mixer-oss
+
**** List of PLAYBACK Hardware Devices ****
alias sound-service-0-1 snd-seq-oss
+
card 0: Intel [HDA Intel], device 0: CONEXANT Analog [CONEXANT Analog]
alias sound-service-0-3 snd-pcm-oss
+
  Subdevices: 1/1
alias sound-service-0-8 snd-seq-oss
+
  Subdevice #0: subdevice #0
alias sound-service-0-12 snd-pcm-oss}}
+
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
 +
}}
  
===Conflicting PC Speaker===
+
{{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).}}
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 adding the following line to {{ic|/etc/modprobe.d/modprobe.conf}}:
+
  
options snd-NAME-OF-MODULE ac97_quirk=0
+
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
 +
}
  
The above fix has been observed to work with {{ic|via82xx}}
+
ctl.!default {
options snd-NAME-OF-MODULE ac97_quirk=1
+
    type hw
The above fix has been reported to work with {{ic|snd_intel8x0}}
+
    card 2
 +
}
 +
}}
  
===No Microphone Input===
+
{{Note|For the Asus U32U series it seems that card should be set to 1 for both pcm and ctl.}}
In alsamixer, make sure that all the volume levels are up under recording, and that CAPTURE is toggled active on the microphone (e.g. Mic, Internal Mic) and/or on Capture (in alsamixer, select these items and press space). Try making positive Mic Boost and raising Capture and Digital levels higher; this make make static or distortion, but then you can adjust them back down once you're hearing ''something'' when you record
+
  
As the pulseaudio wrapper is shown as "default" in alsamixer, you may have to press F6 to select your actual soundcard first. You may also need to enable and increase the volume of Line-in in the Playback section.
+
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
 +
}
  
To test the microphone, run these commands (see arecord's man page for further information):
+
ctl.!default {
  arecord -d 5 test-mic.wav
+
    type hw
  aplay test-mic.wav
+
    card Audio
 +
}
 +
}}
  
If all fails, you may want to eliminate hardware failure by testing the microphone with a different device.
+
To get valid ALSA card names, use ''aplay'':
 +
{{hc|<nowiki>$ aplay -l | awk -F \: '/,/{print $2}' | awk '{print $1}' | uniq</nowiki>|
 +
PCH
 +
}}
  
For at least some computers, muting a microphone (MM) simply means its input doesn't go immediately to the speakers. It still receives input.
+
Alternatively use ''cat'', which might return unused devices:
 +
{{hc|$ cat /proc/asound/card*/id|
 +
PCH
 +
ThinkPadEC
 +
}}
  
Many Dell laptops need "-dmic" to be appended to the model name in {{ic|/etc/modprobe.d/modprobe.conf}}:
+
{{Note|This method could be problematic if your system has several cards of the same (ALSA)name.}}
  options snd-hda-intel model=dell-m6-dmic
+
  
Some programs use try to use OSS as the main input software. Add the following lines to {{ic|/etc/modprobe.d/modprobe.conf}} to prevent OSS modules from being loaded:
+
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 .
  
{{Note|The OSS modules are no longer autoloaded anyway.}}
+
The changes should take effect as soon as you (re-)start an application (MPlayer etc.). You can also test with a command like ''aplay''.
  
  blacklist snd_pcm_oss
+
  $ aplay -D default:PCH ''your_favourite_sound.wav''
blacklist snd_mixer_oss
+
blacklist snd_seq_oss
+
  
See also:
+
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.
* http://www.alsa-project.org/main/index.php/SoundcardTesting
+
* http://alsa.opensrc.org/Record_from_mic
+
  
===Setting the default Microphone/Capture Device===
+
=== Verifying correct sound modules are loaded ===
Some applications (Pidgin, Adobe Flash) do not provide an option to change the capture device. It becomes an issue if your microphone is on a separate device (e.g. USB webcam or microphone) than your internal sound card. To change only the default capture device, leaving the default playback device as is, you can modify your {{ic|~/.asoundrc}} file to include the following:
+
  
pcm.usb
+
You can assume that udev will autodetect your sound properly. You can check this with the command:
{
+
    type hw
+
    card U0x46d0x81d
+
}
+
+
pcm.!default
+
{
+
    type asym
+
    playback.pcm
+
    {
+
        type plug
+
        slave.pcm "dmix"
+
    }
+
    capture.pcm
+
    {
+
        type plug
+
        slave.pcm "usb"
+
    }
+
}
+
  
Replace "U0x46d0x81d" with your capture device's card name in ALSA. You can use {{ic|arecord -L}} to list all the capture devices detected by ALSA.
+
{{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
 +
}}
  
===Internal Microphone not working===
+
If the output looks similar, your sound drivers have been successfully autodetected.
First make sure all the volume levels are up under recording in alsamixer. In my case adding the following option to /etc/sound.conf and reloading the snd-* module produced a new volume setting called Capture which was capturing for the internal mic. For eg, for snd-hda-intel add
+
{{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.}}
  
  options snd-hda-intel enable_msi=1
+
You might also want to check the directory {{ic|/dev/snd/}} for the right device files:
  
Then reload the module (as below), up the recording volume of Capture and then test.
+
{{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
 +
}}
  
{{bc|# rmmod snd-hda-intel && modprobe snd-hda-intel}}
+
{{Note|If requesting help on IRC or the forums, please post the output of the above commands, if requested.}}
  
===No Sound with Onboard Intel Sound Card===
+
If you have at least the devices '''controlC0''' and '''pcmC0D0p''' or similar, then your sound modules have been detected and loaded properly.
There may be an issue with two conflicting modules loaded, namely {{ic|snd_intel8x0}} and {{ic|snd_intel8x0m}}. In this case, blacklist snd_intel8x0m:
+
  
{{hc|/etc/modprobe.d/modprobe.conf|blacklist snd_intel8x0m}}
+
If this is not the case, your sound modules have not been detected properly. To solve this, you can try loading the modules manually:
  
''Muting'' the "External Amplifier" in {{ic|alsamixer}} or {{ic|amixer}} may also help. See [http://alsa.opensrc.org/Intel8x0#Dell_Inspiron_8600_.28and_probably_others.29 the ALSA wiki].
+
* 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]].
  
===No Headphone Sound with Onboard Intel Sound Card===
+
=== Getting S/PDIF output ===
With '''Intel Corporation 82801 I (ICH9 Family) HD Audio Controller''' on laptop, you may need to add this line to modprobe or sound.conf:
+
[[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).
 +
{{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
  
  options snd-hda-intel model=$model
+
You can see the name of your card's digital output with:
 +
  $ amixer scontrols
  
Where $model is any one of the following (in order of possibility to work, but not merit):
+
=== System-wide equalizer ===
  
* dell-vostro
+
==== Using ALSAEqual (provides UI) ====
* olpc-xo-1_5
+
* laptop
+
* dell-m6
+
* laptop-hpsense
+
  
Note: It may be necessary to put this "options" line below (after) any "alias" lines about your card.
+
Install the {{AUR|alsaequal}} package.
  
You can see all the available models in the kernel documentation. For example [http://git.kernel.org/?p=linux/kernel/git/stable/linux-2.6.35.y.git;a=blob;f=Documentation/sound/alsa/HD-Audio-Models.txt;h=dc25bb84b83b49665a7ed850e7bf5423d50cd3ba;hb=HEAD here], but check that it is the correct version of that document for your kernel version.
+
{{Note|If you have a x86_64-system and are using a 32bit-flashplugin the sound in flash will not work. You have to disable alsaequal or build alsaequal for 32bit.}}
  
A list of available models is also available [http://www.mjmwired.net/kernel/Documentation/sound/alsa/HD-Audio-Models.txt here]. To know your chip name type the following command (with * being corrected to match your files). Note that some chips could have been renamed and don't directly match the available ones in the file.
+
After installing the package, add the following to your ALSA configuration file:
  
cat /proc/asound/card*/codec* | grep Codec
+
{{hc|/etc/asound.conf|2=
 +
ctl.equal {
 +
    type equal;
 +
}
  
Note that there is a high chance none of the input devices (all internal and external mics) will work if you choose to do this, so it is either your headphones or your mic. Please report to ALSA if you are affected by this bug.
+
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";
 +
}
  
And also, if you have problems getting beeps to work (pcspkr):
+
# pcm.equal {
 
+
# If you do not want the equalizer to be your
options snd-hda-intel model=$model enable=1 index=0
+
# default soundcard comment the following
 
+
# line and uncomment the above line. (You can
===No sound when S/PDIF video card is installed===
+
# choose it as the output device by addressing
Discover available modules and their order:
+
# it with specific apps,eg mpg123 -a equal 06.Back_In_Black.mp3)
$ cat /proc/asound/modules
+
0 snd_hda_intel
+
1 snd_ca0106
+
 
+
Disable the undesired video card audio codec in {{ic|/etc/modprobe.d/modprobe.conf}}:
+
# /etc/modprobe.d/modprobe.conf
+
#
+
install snd_hda_intel /bin/false
+
 
+
If both devices use the same module, it might be possible to disable one of them in the BIOS.
+
 
+
===Poor sound quality or clipping===
+
If you experience poor sound quality, try setting the PCM volume (in alsamixer) to a level such that gain is 0.
+
 
+
If snd-usb-audio driver has been loaded, you could try to enable {{ic|softvol}} in '''/etc/asound.conf''' file. Example configuration for the first audio device:
+
  pcm.!default {
+
    type plug
+
    slave.pcm "softvol"
+
  }
+
  pcm.dmixer {
+
      type dmix
+
      ipc_key 1024
+
      slave {
+
          pcm "hw:0"
+
          period_time 0
+
          period_size 4096
+
          buffer_size 131072
+
          rate 50000
+
      }
+
      bindings {
+
          0 0
+
          1 1
+
      }
+
  }
+
  pcm.dsnooper {
+
      type dsnoop
+
      ipc_key 1024
+
      slave {
+
          pcm "hw:0"
+
          channels 2
+
          period_time 0
+
          period_size 4096
+
          buffer_size 131072
+
          rate 50000
+
      }
+
      bindings {
+
          0 0
+
          1 1
+
      }
+
  }
+
  pcm.softvol {
+
      type softvol
+
      slave { pcm "dmixer" }
+
      control {
+
          name "Master"
+
          card 0
+
      }
+
  }
+
  ctl.!default {
+
    type hw
+
    card 0
+
  }
+
  ctl.softvol {
+
    type hw
+
    card 0
+
  }
+
  ctl.dmixer {
+
    type hw
+
    card 0
+
  }
+
 
+
===Pops When Starting and Stopping Playback===
+
Some modules (e.g. snd_ac97_codec and snd_hda_intel) can power off your sound card when not in use. This can make an audible noise (like a crack/pop/scratch) when turning on/off your sound card. Sometimes even when move the slider volume, or open and close windows (KDE4). If you find this annoying try {{ic|modinfo snd_MY_MODULE}}, and look for a module option that adjusts or disables this feature.
+
 
+
Example: to disable the power saving mode and solve cracking sound trough speakers issue, using snd_hda_intel add in {{ic|/etc/modprobe.d/modprobe.conf}}
+
options snd_hda_intel power_save=0
+
or
+
options snd_hda_intel power_save=0 power_save_controller=N
+
 
+
You can also try it with {{ic|1=modprobe snd_hda_intel power_save=0}} before.
+
 
+
You may also have to unmute the 'Line' ALSA channel for this to work. Any value will do (other than '0' or something too high).
+
 
+
''Example:'' on an onboard VIA VT1708S (using the snd_hda_intel module) these cracks occured even though 'power_save' was set to 0. Unmuting the 'Line' channel and setting a value of '1' solved the issue.
+
 
+
Source: https://www.kernel.org/doc/Documentation/sound/alsa/powersave.txt
+
 
+
If you use a laptop, pm-utils will change {{ic|power_save}} back to 1 when you go onto battery power even if you disable power saving in {{ic|/etc/modprobe.d}}. Disable this for pm-utils by disabling the script that makes the change (see [https://wiki.archlinux.org/index.php/Pm-utils#Disabling_a_hook Disabling a hook] for more information):
+
# touch /etc/pm/power.d/intel-audio-powersave
+
 
+
===S/PDIF Output Does Not Work===
+
 
+
If the optical/coaxial digital output of your motherboard/sound card is not working or stopped working, and have already enabled and unmuted it in alsamixer, try running
+
# iecset audio on
+
 
+
as root.
+
 
+
You can also put this command in {{Ic|rc.local}} as it sometimes it may stop working after a reboot.
+
 
+
===HDMI Output Does Not Work===
+
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.
+
 
+
Query for Playback Devices:
+
 
+
  $ aplay -l
+
  **** 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.
+
 
+
  $ aplay -D plughw:0,3 /usr/share/sounds/alsa/Front_Center.wav
+
 
+
If aplay does not output any errors, but still no sound is heared, "reboot" the receiver, monitor or tv set. Since the HDMI interface executes a handshake on connection, it might have noticed before that there was no audio stream embedded, and disabled audio decoding. In particular, if you are using a standalone window manager (don’t know about Gnome or KDE), you may need to have some sound playing ''while'' plugging in the HDMI cable.
+
 
+
{{Note|If you're using an ATI card and linux 3.0, check your kernel/grub settings, you most likely need to use the ''''radeon.audio'''<nowiki>=</nowiki>'''1'''' boot parameter, or alternatively set up the option in your modprobe configuration files.}}
+
 
+
If the test is successful, create or edit your ~/.asoundrc file to set HDMI as the default audio device.
+
 
+
{{hc|~/.asoundrc|
+
 
pcm.!default {
 
pcm.!default {
  type hw
+
    type plug;
  card 0
+
    slave.pcm plugequal;
  device 3
+
 
}
 
}
 
}}
 
}}
  
Or you above config does not work try:
+
And you are ready to change your equalizer using command
{{hc|~/.asoundrc|
+
$ alsamixer -D equal
defaults.pcm.card 0
+
defaults.pcm.device 3
+
defaults.ctl.card 0
+
}}
+
  
 +
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 =====
  
====Using udev to automatically turn HDMI audio on or off====
+
Install the {{AUR|alsaequal-mgr}} package.
  
{{Out of date| /var/run/ConsoleKit/database doesn't exist anymore and the hdmi-switch script doesn't seem to work }}
+
Configure the equalizer as usual with
 +
$ alsamixer -D equal
  
{{Note|This will only work if the driver supports udev; NVIDIA's proprietary one, for instance, does not.}}
+
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 previous steps in this section are good for testing, or if you don't need to hotplug your HDMI cable often. We now consider the situation where you have a laptop and want HDMI audio only when you have the HDMI cable plugged in.
+
The state "foo" can then be restored at a later time with
 +
$ alsaequal-mgr load foo
  
The code in this section comes from [https://bbs.archlinux.org/viewtopic.php?id=132641 The Arch Linux Forums].
+
You can thus create different equalizer states for games, movies, music genres, VoIP apps, etc. and reload them as necessary.
  
We create a udev rule (for processing the cable connect/disconnect events), two different ALSA configuration files, and a script that switches between these configurations.
+
See the [http://xyne.archlinux.ca/projects/alsaequal-mgr/ project page] and the help message for more options.
  
First create {{ic|/etc/alsa/}} if it doesn't exist yet; it will house the configuration files and the switcher script:
+
==== Using mbeq ====
  
{{bc|<nowiki>[[ -d /etc/alsa/ ]] || sudo mkdir -v /etc/alsa</nowiki>}}
+
{{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.}}
  
Place inside this directory the following files (which you may wish to tweak as you see fit):
+
Install the {{Pkg|alsa-plugins}}, {{Pkg|ladspa}} and {{Pkg|swh-plugins}} packages if you do not already have them.
  
{{hc|/etc/alsa/hdmi-switch|2=
+
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:
<nowiki>
+
#! /bin/bash
+
set -x
+
export DISPLAY=:0
+
hdmi_status="$(cat /sys/class/drm/card0-HDMI-A-1/status)"
+
USERID="$(cat /var/run/ConsoleKit/database | grep -B 6 is_active=true | grep uid= | cut -f 2 -d '=')"
+
USER="$(grep $USERID /etc/passwd | cut -f 1 -d ':')"
+
  
if [[ $hdmi_status == "disconnected" ]]; then
+
{{hc|/etc/asound.conf|2=
[[ $(pgrep X) > 0 ]] && su $USER -c "xrandr --output HDMI-1 --off"
+
pcm.eq {
else
+
    type ladspa
[[ $(pgrep X) > 0 ]] && su $USER -c "xrandr --output LVDS-1 --mode 1920x1080 --auto --output HDMI-1 --auto --right-of LVDS-1"
+
fi
+
  
ln -sf "/etc/alsa/asound.hdmi-$hdmi_status" /etc/asound.conf
+
    # The output from the EQ can either go direct to a hardware device
systemctl restart alsa-restore
+
    # (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"
  
exit 0
+
    # Sometimes you may need to specify the path to the plugins,
</nowiki>
+
    # 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 ]
 +
            }
 +
        }
 +
    ]
 +
}
  
{{hc|/etc/alsa/asound.hdmi-connected|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 {
 
pcm.!default {
 
     type plug
 
     type plug
     slave.pcm "dmixer"
+
     slave.pcm "eq"
 
}
 
}
  
 +
# Redirect the OSS emulation through the EQ too (when programs are running through "aoss")
 
pcm.dsp0 {
 
pcm.dsp0 {
 
     type plug
 
     type plug
     slave.pcm "dmixer"
+
     slave.pcm "eq"
 
}
 
}
 +
}}
  
pcm.dmixer {
+
== High quality resampling ==
    type dmix
+
    ipc_key 1024           
+
    ipc_key_add_uid 0
+
    ipc_perm 0666               
+
    slave {
+
        pcm "hw:0,3"    # HDMI CARD AND DEVICE
+
        period_time 0
+
        period_size 1024
+
        buffer_size 8192
+
        rate 48000 #or 44100
+
    } 
+
}
+
  
ctl.dmixer {
+
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].
    type hw
+
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.
    card 0
+
}
+
}}
+
  
{{hc|/etc/alsa/asound.hdmi-disconnected|2=
+
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.
pcm.!default {
+
 
  type plug
+
To change the default converter place the following contents in your {{ic|~/.asoundrc}} or {{ic|/etc/asound.conf}}:
  slave.pcm "dmixer"
+
}
+
 
+
pcm.dsp0 {
+
  type plug
+
  slave.pcm "dmixer"
+
}
+
 
+
pcm.dmixer {
+
  type dmix
+
  ipc_key 1024               
+
  ipc_key_add_uid 0
+
  ipc_perm 0666         
+
  slave {
+
      pcm "hw:0,0"      # LOCAL CARD AND DEVICE
+
      period_time 0
+
      period_size 1024
+
      buffer_size 8192
+
      rate 48000 #or 44100
+
  }
+
}
+
 
+
ctl.dmixer {
+
  type hw
+
  card 0
+
}
+
  
 +
{{hc|/etc/asound.conf|
 +
defaults.pcm.rate_converter "speexrate_medium"
 
}}
 
}}
  
The two asound.conf versions include dmix settings and allow merging of user permissions so that, for example, the mpd user and your regular user can access it at the same time.
+
{{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.}}
  
You may now test that the switcher script works by running,
+
== Upmixing/downmixing ==
  
# chmod +x /etc/alsa/hdmi-switch
+
=== Upmixing ===
# /etc/alsa/hdmi-switch
+
  
You should find that you can successfully obtain HDMI audio output when you run the script while the cable is plugged in. You should be able to restore your default audio output by unplugging the cable and manually running the script again.
+
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.
  
Once you have that working, we automate the process by adding the udev rule:
+
Then add the following to your ALSA configuration file of choice (either {{ic|/etc/asound.conf}} or {{ic|~/.asoundrc}}):
  
{{hc|/etc/udev/rules.d/hdmi.rules|2=
+
{{bc|
SUBSYSTEM=="drm", ACTION=="change", RUN+="/bin/bash /etc/alsa/hdmi-switch"
+
pcm.upmix71 {
 +
    type upmix
 +
    slave.pcm "surround71"
 +
    delay 15
 +
    channels 8
 +
}
 
}}
 
}}
  
To make udev incorporate the new rule immediately, reload all rules:
+
You can easily change this example for 7.1 upmixing to 5.1 or 4.0.
  
# udevadm control --reload-rules
+
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:
  
===HDMI Multi-channel PCM output does not work (Intel) ===
+
pcm.!default "plug:upmix71"
As of Linux 3.1 multi-channel PCM output through HDMI with a Intel card (Intel Eaglelake, IbexPeak/Ironlake,SandyBridge/CougarPoint and IvyBridge/PantherPoint) is not yet supported. Support for it has been recently added and expected to be available in Linux 3.2. To make it work in Linux 3.1 you need to apply the following patches:
+
  
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=patch;h=76adaa34db407f174dd06370cb60f6029c33b465 drm: support routines for HDMI/DP ELD]
+
The plugin automatically allows multiple sources to play through it without problems so setting is as a default is actually a safe choice.
* [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=patch;h=e0dac65ed45e72fe34cc7ccc76de0ba220bd38bb drm/i915: pass ELD to HDMI/DP audio driver]
+
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
 +
        }
 +
    }
 +
}
  
===HP TX2500===
+
}}
Add these 2 lines into {{ic|/etc/modprobe.d/modprobe.conf}}:
+
options snd-cmipci mpu_port=0x330 fm_port=0x388
+
options snd-hda-intel index=0 model=toshiba position_fix=1
+
  
options snd-hda-intel model=hp (works for tx2000cto)
+
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]].
  
===Skipping Sound When Playing MP3===
+
=== Downmixing ===
If you have sound skipping when playing MP3 files and you have more then 2 speakers attached to your computer (i.e. > 2 speaker system), run alsamixer and disable the channels for the speakers that you '''DO NOT''' have (i.e. do not enable the sound for the center speaker if you do not have a center speaker.
+
  
===Using a USB Headset and External USB Sound Cards===
+
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.
If you are using a USB headset with ALSA you can try using {{AUR|asoundconf}} (currently only available from the [[AUR]]) to set the headset as the primary sound output. Before running make sure you have usb audio module enabled ({{ic|modprobe snd-usb-audio}}).
+
  
# asoundconf is-active
+
Again, in your configuration file, add this:
# asoundconf list
+
# asoundconf set-default-card <chosen soundcard>
+
  
==== Crackling sound with USB devices ====
+
{{bc|1=
If you experience crackling sound on USB devices, you can try tuning the snd-usb-audio for minimal latency.
+
pcm.!surround51 {
 +
    type vdownmix
 +
    slave.pcm "default"
 +
}
 +
pcm.!surround40 {
 +
    type vdownmix
 +
    slave.pcm "default"
 +
}
 +
}}
  
Add this to your {{ic|/etc/modprobe.d/modprobe.conf}}:
+
{{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].}}
  
options snd-usb-audio nrpacks=1
+
== Dmix ==
  
source: http://alsa.opensrc.org/Usb-audio#Tuning_USB_devices_for_minimal_latencies
+
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.
  
==== Hot-plugging a USB Sound Card ====
+
{{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.}}
In order to automatically make a USB Sound Card the primary output device, when the card is plugged in, you can use the following udev rules (e.g. add the following two lines to {{ic|/etc/udev/rules.d/00-local.rules}} and reboot).
+
  
{{bc|1=KERNEL=="pcmC[D0-9cp]*", ACTION=="add", PROGRAM="/bin/sh -c 'K=%k; K=$${K#pcmC}; K=$${K%%D*}; echo defaults.ctl.card $$K > /etc/asound.conf; echo defaults.pcm.card $$K >>/etc/asound.conf'"
+
To manually enable dmix, add the following to your ALSA configuration file:
KERNEL=="pcmC[D0-9cp]*", ACTION=="remove", PROGRAM="/bin/sh -c 'echo defaults.ctl.card 0 > /etc/asound.conf; echo defaults.pcm.card 0 >>/etc/asound.conf'"}}
+
  
===Error 'Unknown hardware' Appears After a Kernel Update===
+
{{hc|/etc/asound.conf|2=
The following messages may be displayed during the start-up ALSA after the kernel update:
+
pcm.dsp {
Unknown hardware "foo" "bar" ...
+
    type plug
Hardware is initialized using a guess method
+
    slave.pcm "dmix"
/usr/sbin/alsactl: set_control:nnnn:failed to obtain info for control #mm (No such file or directory)
+
}
 +
}}
  
or
+
== Tips and tricks ==
Found hardware: "HDA-Intel" "VIA VT1705" "HDA:11064397,18490397,00100000" "0x1849" "0x0397"
+
Hardware is initialized using a generic method
+
/usr/sbin/alsactl: set_control:1328: failed to obtain info for control #1 (No such file or directory)
+
/usr/sbin/alsactl: set_control:1328: failed to obtain info for control #2 (No such file or directory)
+
/usr/sbin/alsactl: set_control:1328: failed to obtain info for control #25 (No such file or directory)
+
/usr/sbin/alsactl: set_control:1328: failed to obtain info for control #26 (No such file or directory)
+
  
Simply store ALSA mixer settings again (as root):
+
=== Hot-plugging a USB sound card ===
# alsactl -f /var/lib/alsa/asound.state store
+
  
It may be necessary configure ALSA again with alsamixer
+
See [http://alsa.opensrc.org/Udev Writing Udev rules for ALSA].
  
===HDA Analyzer===
+
=== Simultaneous output ===
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 can be found [http://www.alsa-project.org/main/index.php/HDA_Analyzer at the ALSA wiki].
+
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.
+
  
NOTE: the script is done by such way that it is incompatible with python3 (which is now shipped with ArchLinux) but tries to use it.
+
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}}:
The workaround is: open "run.py", find all occurences of "python" (2 occurences - one on the first line, and the second on the last line) and replace them all by "python2".
+
$ amixer sset "Auto-Mute" unmute
  
NOTE2: the script requires root acces, but running it via su/sudo is bogus. Run it via {{ic|kdesu}} or {{ic|gksu}}.
+
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]].}}
  
===ALSA with SDL===
+
=== Keyboard volume control ===
If you get no sound via SDL and ALSA cannot be chosen from the application. Try setting the environmental variable SDL_AUDIODRIVER to alsa.
+
# export SDL_AUDIODRIVER=alsa
+
  
===Low Sound Workaround===
+
Map the following commands to your volume keys: {{ic|XF86AudioRaiseVolume}}, {{ic|XF86AudioLowerVolume}}, {{ic|XF86AudioMute}}
  
If you are facing low sound even after maxing out your speakers/headphones, you can give the softvol plugin a try. Add the following to {{ic|/etc/asound.conf}}.
+
To raise the volume:
{{bc|<nowiki>
+
amixer set Master 5%+
pcm.!default {
+
      type plug
+
      slave.pcm "softvol"
+
  }
+
 
+
pcm.softvol {
+
    type softvol
+
    slave {
+
        pcm "dmix"
+
    }
+
    control {
+
        name "Pre-Amp"
+
        card 0
+
    }
+
    min_dB -5.0
+
    max_dB 20.0
+
    resolution 6
+
}
+
</nowiki>}}
+
{{note| You'll probably have to restart the computer, as restarting the alsa daemon didn't load the new configuration for me. Also, if the configuration doesn't work even after restarting, try changing {{ic|plug}} with {{ic|hw}} in the above configuration.}}
+
  
After the changes are loaded successfully, you will see a {{ic|Pre-Amp}} section in alsamixer. You can adjust the levels there.
+
To lower the volume:
{{note|Setting a high value for {{ic|Pre-Amp}} can cause sound distortion, so adjust it according to the level that suits you.}}
+
amixer set Master 5%-
  
===Popping sound after resuming from suspension===
+
To toggle mute/unmute of the volume:
You might hear a popping sound after resuming the computer from suspension. This can be fixed by editing {{ic|/etc/pm/sleep.d/90alsa}} and removing the line that says {{ic|aplay -d 1 /dev/zero}}
+
amixer set Master toggle
  
==Example configurations==
+
== See also ==
See [[Advanced Linux Sound Architecture/Example Configurations]].
+
  
==See also==
+
* [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/Main_Page Unofficial ALSA Wiki]
+
* [https://bbs.archlinux.org/viewtopic.php?id=36815 HOWTO: compile driver from svn]
* [https://bbs.archlinux.org/viewtopic.php?id=36815 HOWTO: Compile driver from svn]
+
* [http://www.volkerschatz.com/noise/alsa.html A close look at ALSA: ALSA concept introduction]
 +
* [http://www.sabi.co.uk/Notes/linuxSoundALSA.html Linux ALSA sound notes]

Latest revision as of 18:47, 22 April 2016

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.

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.

Note: If you have a x86_64-system and are using a 32bit-flashplugin the sound in flash will not work. You have to disable alsaequal or build alsaequal for 32bit.

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;
}

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

See also