Advanced Linux Sound Architecture: Difference between revisions

From ArchWiki
(update interlanguage links)
(update interlanguage links)
 
(77 intermediate revisions by 15 users not shown)
Line 1: Line 1:
[[Category:Sound]]
[[Category:Sound]]
[[cs:Advanced Linux Sound Architecture]]
[[de:Advanced Linux Sound Architecture]]
[[de:Advanced Linux Sound Architecture]]
[[es:Advanced Linux Sound Architecture]]
[[es:Advanced Linux Sound Architecture]]
[[fa:ALSA]]
[[fr:Advanced Linux Sound Architecture]]
[[fr:Advanced Linux Sound Architecture]]
[[it:Advanced Linux Sound Architecture]]
[[ja:Advanced Linux Sound Architecture]]
[[ja:Advanced Linux Sound Architecture]]
[[pt:Advanced Linux Sound Architecture]]
[[zh-hans:Advanced Linux Sound Architecture]]
[[zh-hans:Advanced Linux Sound Architecture]]
{{Related articles start}}
{{Related articles start}}
Line 19: Line 15:
{{Related articles end}}
{{Related articles end}}


The [[Wikipedia:Advanced Linux Sound Architecture|Advanced Linux Sound Architecture]] ('''ALSA''') provides kernel driven sound card drivers. It replaces the original Open Sound System (OSS).
The [[Wikipedia:Advanced Linux Sound Architecture|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.
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.
Line 27: Line 23:
ALSA is a set of built-in Linux kernel modules. Therefore, manual installation is not necessary.
ALSA is a set of built-in 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|Unmuting the channels]].
[[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 ===
=== User privileges ===
Line 33: Line 29:
Usually, local users have permission to play audio and change mixer levels.
Usually, local users have permission to play audio and change mixer levels.


To allow remote users to use ALSA, you need to [[Users and groups#Group management|add]] those users to the {{ic|audio}} group, however this is not recommended by default (see note below).
To allow remote users to use ALSA, you need to [[Users and groups#Group management|add]] those users to the {{ic|audio}} group; however, this is not recommended by default (see note below).


{{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].}}
{{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].}}


=== ALSA utilities ===
=== ALSA utilities ===


[[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.
[[Install]] the {{Pkg|alsa-utils}} package. This contains (among other utilities) the {{man|1|alsamixer}} and {{man|1|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.


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.
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.


=== OSS compatibility ===
=== OSS compatibility ===
Line 53: Line 49:
=== PulseAudio compatibility ===
=== PulseAudio compatibility ===


{{AUR|apulse}} lets you use ALSA for applications that support only [[PulseAudio]] for sound. Usage is simply {{ic|$ apulse ''yourapplication''}}.
{{AUR|apulse}} lets you use ALSA for applications that support only [[PulseAudio]] for sound. Usage is simply
 
$ apulse ''application''


=== ALSA and systemd ===
=== ALSA and systemd ===
Line 59: Line 57:
The {{Pkg|alsa-utils}} package comes with [[systemd]] unit configuration files {{ic|alsa-restore.service}} and {{ic|alsa-state.service}} by default.
The {{Pkg|alsa-utils}} package comes with [[systemd]] unit configuration files {{ic|alsa-restore.service}} and {{ic|alsa-state.service}} by default.


These are automatically installed and activated during installation (via package provided symlink to [[systemd#Targets|sound.target]]). Neither will run by default, as they rely on some conscious decisions by the user to know which method should be preferred. The options are as follows:
These are automatically installed and activated during installation (via package provided symlink to [[systemd#Targets|sound.target]]). The options are as follows:


* {{ic|alsa-restore.service}} Reads {{ic|/var/lib/alsa/asound.state}} on boot and writes updated values on shutdown, granted it is already present by having ran {{ic|alsactl store}} at some point
* {{ic|alsa-restore.service}} reads {{ic|/var/lib/alsa/asound.state}} on boot and writes updated values on shutdown, provided {{ic|/etc/alsa/state-daemon.conf}} does not exist. As {{ic|/etc/alsa/state-daemon.conf}} is not created without a conscious action of the user, it is the default method.
* {{ic|alsa-state.service}} (Re-)Starts alsactl in daemon mode to continouously keep track of, and persist, volume changes, again under the condition that the user has consciously started {{ic|alsactl daemon}} at least once
* {{ic|alsa-state.service}} (Re-)Starts alsactl in daemon mode to continuously keep track of, and persist, volume changes, under the condition that the user has consciously created {{ic|/etc/alsa/state-daemon.conf}}.


Both methods are mutually exclusive and you can decide for one of the two approaches depending on your requirements, for further information see {{man|1|alsactl}}
Evidently, both methods are mutually exclusive. You can decide for one of the two approaches depending on your requirements. To edit these units, see [[systemd#Editing provided units]]. You can check their status using [[systemctl]].


You can check their status using {{ic|systemctl}}.
For further information, see {{man|1|alsactl}}.


=== ALSA firmware ===
=== ALSA firmware ===
{{Pkg|sof-firmware}} is required for some newer laptop models (mainly since 2019) because they implement their drivers with firmware provided by the [https://www.sofproject.org/ Sound Open Firmware] project. Checking the [[journal]] will provide messages about the missing firmware (see [https://bbs.archlinux.org/viewtopic.php?id=275577 BBS#275577]).


The {{Pkg|alsa-firmware}} package contains firmware that may be required for certain sound cards (e.g. Creative SB0400 Audigy2).
The {{Pkg|alsa-firmware}} package contains firmware that may be required for certain sound cards (e.g. Creative SB0400 Audigy2).
{{Pkg|sof-firmware}} and {{Pkg|alsa-ucm-conf}} are required for few newer laptop models (end of 2019/2020) which implement their drivers with firmware provided by the [https://www.sofproject.org/ Sound Open Firmware] project.


== Unmuting the channels ==
== Unmuting the channels ==


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


=== Unmute with amixer ===
=== Unmute with amixer ===
Line 94: Line 92:
The {{ic|MM}} label below a channel indicates that the channel is muted, and {{ic|OO}} indicates that it is open.
The {{ic|MM}} label below a channel indicates that the channel is muted, and {{ic|OO}} indicates that it is open.


Scroll to the {{ic|Master}} and {{ic|PCM}} channels with the {{ic|}} and {{ic|}} keys and unmute them by pressing the {{ic|m}} key.
Scroll to the {{ic|Master}} and {{ic|PCM}} channels with the {{ic|Left}} and {{ic|Right}} keys and unmute them by pressing the {{ic|m}} key.


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


{{Note|If gain is set above 0 dB audible distortion can become present.}}
{{Note|If gain is set above 0 dB, audible distortion can become present.}}


=== Unmute 5.1/7.1 sound ===
=== Unmute 5.1/7.1 sound ===


To get full 5.1 or 7.1 surround sound you will likely need to unmute other channels such as {{ic|Front}}, {{ic|Surround}}, {{ic|Center}}, {{ic|LFE}} (subwoofer) and {{ic|Side}}. (Those are channel names with Intel HD Audio, they may vary with different hardware)
To get full [[wikipedia:5.1 surround sound|5.1]] or [[wikipedia:7.1 surround sound|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 [[wikipedia:Intel High Definition Audio|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]].}}
{{note|Please take note that this will not automatically upmix stereo sources (like most music). In order to accomplish that, see [[#Upmixing/downmixing]].}}
Line 120: Line 118:
  $ speaker-test -c 8
  $ speaker-test -c 8


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


  $ speaker-test -D default:PCH -c 8
  $ speaker-test -D default:PCH -c 8
Line 144: Line 142:
* If your system has more than one soundcard, then you can switch between them by pressing {{ic|F6}}
* If your system has more than one soundcard, then you can switch between them by pressing {{ic|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 {{ic|IEC958}}.
* 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}}.


* Some machines, (like the Thinkpad T61), have a {{ic|Speaker}} channel which must be unmuted and adjusted as well.
* Some machines, like the Thinkpad T61, have a {{ic|Speaker}} channel which must be unmuted and adjusted as well.


* Some machines, (like the Dell E6400) may also require the {{ic|Front}} and {{ic|Headphone}} channels to be unmuted and adjusted.
* Some machines, like the Dell E6400, may also require the {{ic|Front}} and {{ic|Headphone}} channels to be unmuted and adjusted.


* If your volume adjustments seem to be lost after you reboot, try running ''alsamixer'' as root.
* If your volume adjustments seem to be lost after you reboot, try running ''alsamixer'' as root.
Line 186: Line 184:


Compound assignments use braces as separators.
Compound assignments use braces as separators.
{{hc|Compound assignment|2=
{{hc|Compound assignment|2=
key { subkey0 value0;
key { subkey0 value0;
Line 196: Line 195:
For easier reading, it is recommended to use first style for definitions including more than three keys.
For easier reading, it is recommended to use first style for definitions including more than three keys.


Array definitions use brackets as separators.
Array definition is an alternative syntax to define compound statements. It uses brackets as separators. The keys are automatically generated as numbers, starting with zero.


{{hc|Single array|2=
{{hc|Single array|2=
key [ "value0";
key [ "value0";
"valueN"; ]
"value1";
"value''N''"; ]


key.0 "value0"; # Equivalent to the example above
key.0 "value0"; # Equivalent to the example above.
key.N "valueN";
key.1 "value1";
key.''N'' "value''N''";
}}
}}


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 in [https://www.volkerschatz.com/noise/alsa.html#basicconf].
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 in [https://www.volkerschatz.com/noise/alsa.html#basicconf].


==== Data types ====
==== Data types ====
Line 214: Line 215:
==== Operation modes ====
==== 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.
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:
Prefixes of operation modes:
Line 240: Line 241:
}}
}}


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.
Using override operation mode, when done correctly, is usually safe; however, one should bear in mind that there might be other necessary keys in a node for proper functioning.


{{warning| Overriding pcm node itself will most definitely make alsa unusable, since every plugin definition will be deleted. Therefore <b>do not use !pcm.key</b> unless you are making a configuration from scratch.}}
{{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 =====
===== An example of setting default device using "defaults" node =====
Line 256: Line 257:


defaults.ctl.-card 2; # Same effect on a default setup, however if defaults node was removed or
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; # type has been changed, merge operation mode will result in error.


defaults.pcm.?card 2; # This does nothing, since this assignment already exists.
defaults.pcm.?card 2; # This does nothing, since this assignment already exists.
Line 265: Line 266:
}}
}}


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.
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.}}
{{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 ====
==== Nesting ====


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


{{hc|Nesting PCM plugins|2=
{{hc|Nesting PCM plugins|2=
Line 300: Line 301:
==== Setting the default sound card via defaults node ====
==== Setting the default sound card via defaults node ====


To put the [[#An_example_of_setting_default_device_using_"defaults"_node|previous example]] regarding {{ic|defaults.pcm.card}} and {{ic|defaults.pcm.device}} into practice assuming we have 2 cards with index 0 and 1 respectively and wish to simply change the default card to index 1, would lead to the following configuration in {{ic|/etc/asound.conf}} or the user-specific {{ic|~/.asoundrc}} to change both the playback and the mixer control card.
Putting the [[#An example of setting default device using "defaults" node|previous example]] regarding {{ic|defaults.pcm.card}} and {{ic|defaults.pcm.device}} into practice, assuming we have 2 cards with index 0 and 1 respectively and wish to simply change the default card to index 1, would lead to the following configuration in {{ic|/etc/asound.conf}} or the user-specific {{ic|~/.asoundrc}} to change both the playback and the mixer control card.


{{bc|1=
{{bc|1=
Line 341: Line 342:


==== Select the default PCM via environment variable ====
==== Select the default PCM via environment variable ====
Probably it is enough to set ALSA_CARD to the name of the device.  First, get the names with {{ic|aplay -l}}, then set ALSA_CARD to the name which comes after the colon and before the bracket; e.g. if you have


{{ic|card 1: HDMI [HDA ATI HDMI], device 3: HDMI 0 [HDMI 0]}}
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
 
card 1: HDMI [HDA ATI HDMI], device 3: HDMI 0 [HDMI 0]
 
then set {{ic|1=ALSA_CARD=HDMI}}.


then set ALSA_CARD=HDMI.
Other variables are also checked in the default global configuration {{ic|/usr/share/alsa/alsa.conf}}. By looking there for constructs of the form {{ic|vars [ ... ]}}, the following table emerges:


Other variables are also checked in the default global configuration:
{| class="wikitable"
{{hc|/usr/share/alsa/alsa.conf|2=
|-
Variable name # Definition
! style="width: 7.5%;"| !! Variable name !! Used by
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
| {{C|1}} || ALSA_CARD || pcm.default , pcm.hw , pcm.plughw , ctl.sysdefault , ctl.hw rawmidi.default , rawmidi.hw , hwdep.hw
ALSA_HWDEP_CARD # hwdep.default hwdep.hw
|-
ALSA_HWDEP_DEVICE # hwdep.default hwdep.hw
| {{C|2}} || ALSA_CTL_CARD || ctl.sysdefault , ctl.hw
ALSA_PCM_CARD # pcm.default pcm.hw pcm.plughw
|-
ALSA_PCM_DEVICE # pcm.hw pcm.plughw
| {{C|3}} || ALSA_HWDEP_CARD || hwdep.default , hwdep.hw
ALSA_RAWMIDI_CARD # rawmidi.default rawmidi.hw
|-
ALSA_RAWMIDI_DEVICE # rawmidi.default rawmidi.hw
| {{C|4}} || ALSA_HWDEP_DEVICE || hwdep.default , hwdep.hw
}}
|-
| {{C|5}} || ALSA_PCM_CARD || pcm.default , pcm.hw , pcm.plughw
|-
| {{C|6}} || ALSA_PCM_DEVICE || pcm.hw , pcm.plughw
|-
| {{C|7}} || ALSA_RAWMIDI_CARD || rawmidi.default , rawmidi.hw
|-
| {{C|8}} || ALSA_RAWMIDI_DEVICE || rawmidi.default , rawmidi.hw
|}
 
Alternatively, you can override the behavior in your own configuration file, preferably the global one ({{ic|/etc/asound.conf}}).  Add:


Alternatively, you can override the behavior in your own configuration file, preferably the global one (/etc/asound.conf). Add:
  pcm.!default {
{{bc|1=
pcm.!default {
     type plug
     type plug
     slave.pcm {
     slave.pcm {
Line 369: Line 381:
         default "hw:Audigy2"
         default "hw:Audigy2"
     }
     }
}
}
}}


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


Now you can select the sound card when starting programs by just changing the environment variable {{ic|ALSAPCM}}. It works fine for all program that do not allow to select the card, for the others ensure you keep the default card.
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}}
For example, assuming you wrote a downmix PCM called {{ic|mix51to20}}, you can use it with {{Pkg|mplayer}} using the commandline {{ic|1=ALSAPCM=mix51to20 mplayer example_6_channel.wav}}


{{note|Pay attention to default addressing type.}}
{{note|Pay attention to default addressing type.}}


==== Alternative method ====
==== Alternative method ====
{{Tip|This process can be partly automated using {{Pkg|asoundconf}}.}}


First you will have to find out the card and device id that you want to set as the default:
{{Tip|This process can be partly automated using {{AUR|asoundconf}}.}}
 
First, you will have to find out the card and device id that you want to set as the default:


{{hc|$ aplay -l|2=
{{hc|$ aplay -l|2=
Line 403: Line 415:


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.
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 {
pcm.!default {
     type hw
     type hw
     card 2
     card 2
}
}
 
ctl.!default {
ctl.!default {
     type hw
     type hw
     card 2
     card 2
}
}
}}


{{Note|For the Asus U32U series it seems that card should be set to 1 for both pcm and ctl.}}
{{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. Card names are easier to grasp, and also overcomes the boot order problem. Therefore the following would be correct for the above example.
In most cases, it is recommended to use sound card names instead of number references. Card names are easier to grasp, and also overcomes the boot order problem. Therefore, the following would be correct for the above example.
{{bc|
 
pcm.!default {
pcm.!default {
     type hw
     type hw
     card Audio
     card Audio
}
}
 
ctl.!default {
ctl.!default {
     type hw
     type hw
     card Audio
     card Audio
}
}
}}


To get valid ALSA card names, use ''aplay'':
To get valid ALSA card names, use ''aplay'':
Line 435: Line 445:
}}
}}


Alternatively use ''cat'', which might return unused devices:
Alternatively, use ''cat'', which might return unused devices:
{{hc|$ cat /proc/asound/card*/id|
{{hc|$ cat /proc/asound/card*/id|
PCH
PCH
Line 468: Line 478:


If the output looks similar, your sound drivers have been successfully autodetected.
If the output looks similar, your sound drivers have been successfully autodetected.
{{Note|Since {{ic|udev>&#61;171}}, the OSS emulation modules ({{ic|snd_seq_oss, snd_pcm_oss, snd_mixer_oss}}) are not loaded by default: [[kernel modules#Manual module handling|Load them manually]], if they are needed.}}
{{Note|Since [[udev]] ≥ 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.}}


You might also want to check the directory {{ic|/dev/snd/}} for the right device files:
You might also want to check the directory {{ic|/dev/snd/}} for the right device files:
Line 494: Line 504:
* [[Kernel modules#Manual module handling|Load the module]].
* [[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.
* 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 loading with systemd|load at boot]].
* Configure {{ic|snd-''name-of-module''}} and {{ic|snd-pcm-oss}} to [[Kernel module#systemd|load at boot]].


=== Getting S/PDIF output ===
=== Getting S/PDIF output ===
[[wikipedia:S/PDIF|S/PDIF]] is a digital audio interface often used to connect a computer to a digital amplifier (such as a home theatre with 5.1/7.1 surround sound).
[[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).}}
 
{{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:
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
 
  $ amixer -c 0 cset name='IEC958 Playback Switch' on


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


=== System-wide equalizer ===
=== Equalizer ===


==== Using ALSAEqual (provides UI) ====
==== ALSAEqual system-wide ====


Install the {{AUR|alsaequal}} package. Also install {{AUR|lib32-alsaequal}} for 32-bit application support.
Install the {{AUR|alsaequal}} package.


After installing the package, add the following to your ALSA configuration file:
After installing the package, add the following to your ALSA configuration file:
Line 520: Line 534:
pcm.plugequal {
pcm.plugequal {
     type equal;
     type equal;
     # Modify the line below if you do not
     # Normally, the equalizer feeds into dmix so that audio
     # want to use sound card 0.
    # from multiple applications can be played simultaneously:
    slave.pcm "plug:dmix";
     # If you want to feed directly into a device, specify it instead of dmix:
     #slave.pcm "plughw:0,0";
     #slave.pcm "plughw:0,0";
    # by default we want to play from more sources at time:
    slave.pcm "plug:dmix";
}
}


# Configuring pcm.!default will make the equalizer your default sink
pcm.!default {
# If you do not want the equalizer to be your default,
# give it a different name, like pcm.equal commented below
# Then you can choose it as the output device by addressing
# it in individual apps, for example mpg123 -a equal 06.Back_In_Black.mp3
# pcm.equal {
# 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;
     type plug;
     slave.pcm plugequal;
     slave.pcm plugequal;
Line 539: Line 553:
}}
}}


And you are ready to change your equalizer using command
To change your equalizer settings, run
  $ alsamixer -D equal
  $ alsamixer -D equal


Note that configuration file is different for each user (until not specified else) it is saved in {{ic|~/.alsaequal.bin}}.
Note that the equalizer configuration 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
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'
  $ su mpd -c 'alsamixer -D equal'
or for example, you can make a symlink to your {{ic|.alsaequal.bin}} in his home directory.
or for example, you can make a symlink to your {{ic|.alsaequal.bin}} in their home directory.


===== Managing ALSAEqual states =====
==== ALSAEqual for specific outputs only ====
 
If you wish to apply an equalizer to a specific output device only (for example your speakers connected to the S/PDIF output, but not your headphones connected to the headphone jack), but also want be able to output from multiple applications and to both output devices simultaneously, you need to create two {{ic|dmix}} devices that feed into their respective devices ({{ic|slave.pcm}}) directly. The following works for stereo output and maintains a regular stereo input, applying the equalizer to the S/PDIF output only.
 
{{hc|/etc/asound.conf|2=
#
#  (capture.pcm)  <-- dnsoop
#        {{!}}
# !default                              --> dmixa
#        {{!}}                              {{!}}
#  (playback.pcm) --> stereo2quad ==> quad
#                                        {{!}}
#                                        --> softvol --> plugequal --> dmixd
#
 
# dmix for analog output
pcm.dmixa {
  type dmix
  ipc_key 1024
  ipc_perm 0666
  slave.pcm "hw:PCH,0"
  slave {
    period_time 0
    period_size 1024
    buffer_size 4096
    channels 2
  }
  bindings {
    0 0
    1 1
  }
}
 
# dmix for digital output
pcm.dmixd {
  type dmix
  ipc_key 2048
  ipc_perm 0666
  slave.pcm "hw:PCH,1"
  slave {
    period_time 0
    period_size 1024
    buffer_size 4096
    channels 2
  }
  bindings {
    0 0
    1 1
  }
}
 
# equalizer with controls
pcm.plugequal {
  type equal
  slave {
    pcm "plug:dmixd"
  }
}
ctl.equal {
type equal
}
 
# Volume control for S/PDIF
pcm.softvol {
    type softvol
    slave.pcm "plug:plugequal"
    control {
        name "S/PDIF"
    }
}
 
# multi:
# "a" (analog)  -> dmix,
# "d" (digital) -> softvol -> plugequal -> dmix
pcm.quad {
    type multi
    slaves {
      a.pcm "dmixa"
      a.channels 2
      d.pcm "plug:softvol" # detour via softvol and equalizer
      d.channels 2
    }
    bindings {
      0 { slave a; channel 0; }
      1 { slave a; channel 1; }
      2 { slave d; channel 0; }
      3 { slave d; channel 1; }
    }
}
 
# stereo to quad
pcm.stereo2quad {
  type route
  slave.pcm "quad"
  ttable [
    [ 1 0 1 0 ]
    [ 0 1 0 1 ]
  ]
}
 
# playback to stereo to quad, capture as usual
pcm.!default {
  type asym
  playback.pcm "plug:stereo2quad"
  capture.pcm "plug:dnsoop"
}
}}
 
==== Managing ALSAEqual states ====


Install the {{AUR|alsaequal-mgr}} package.
Install the {{AUR|alsaequal-mgr}} package.
Line 554: Line 676:
  $ alsamixer -D equal
  $ alsamixer -D equal


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


The state "foo" can then be restored at a later time with
The state "foo" can then be restored at a later time with
  $ alsaequal-mgr load foo
  $ alsaequal-mgr load ''foo''


This however only restores {{ic|~/.alsaequal.bin}}. You then have to update the equalizer by {{ic|alsamixer -D equal}}.
This, however, only restores {{ic|~/.alsaequal.bin}}. You then have to update the equalizer by {{ic|alsamixer -D equal}}.


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


See the [https://xyne.archlinux.ca/projects/alsaequal-mgr/ project page] and the help message for more options.
See the [https://xyne.dev/projects/alsaequal-mgr/ project page] and the help message for more options.


==== Using mbeq ====
==== Using mbeq ====
mbeq is a fairly typical multi band graphical equalizer. [https://github.com/swh/ladspa/blob/b0c0b9261819bc9bc9d9f392b49ff177285cc0f9/mbeq_1197.xml#L45-L48]


{{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.}}
{{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.}}
Line 584: Line 708:
     slave.pcm "plug:dmix"
     slave.pcm "plug:dmix"


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


# Redirect the default device to go via the EQ - you may want to do
# 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
# this last, once you are sure everything is working.  Otherwise, all
# your audio programs will break/crash if something has gone wrong.
# your audio programs will break/crash if something has gone wrong.
pcm.!default {
pcm.!default {
Line 626: Line 750:
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.
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.


To change the default converter place the following contents in your {{ic|~/.asoundrc}} or {{ic|/etc/asound.conf}}:
To change the default converter, place the following contents in your {{ic|~/.asoundrc}} or {{ic|/etc/asound.conf}}:


{{hc|/etc/asound.conf|
{{hc|/etc/asound.conf|
Line 632: Line 756:
}}
}}


{{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|<nowiki/>
{{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}}
* 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|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.}}
* It is also possible to use lavcrate[https://github.com/alsa-project/alsa-plugins/blob/86d695c5d6ba028a3c01758a3b398312408ee0cf/doc/lavrate.txt] 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.
* 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/downmixing ==
Line 640: Line 765:
=== Upmixing ===
=== 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 {{ic|upmix}} plugin, included in the {{Pkg|alsa-plugins}} package.
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 [https://github.com/alsa-project/alsa-plugins/blob/master/doc/upmix.txt upmix] plugin, included in the {{Pkg|alsa-plugins}} package.


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


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


You can easily change this example for 7.1 upmixing to 5.1 or 4.0.
You can easily change this example for 7.1 upmixing to 5.1 or 4.0.
Line 661: Line 784:
The plugin automatically allows multiple sources to play through it without problems so setting is as a default is actually a safe choice.
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:
If this is not working, you have to setup your own dmixer for the upmixing PCM like this:
{{bc|1=
 
pcm.dmix6 {
pcm.dmix6 {
     type asym
     type asym
     playback.pcm {
     playback.pcm {
Line 672: Line 795:
         }
         }
     }
     }
}
}
 
}}


and use "dmix6" instead of "surround71".
and use "dmix6" instead of "surround71".
Line 685: Line 806:
Again, in your configuration file, add this:
Again, in your configuration file, add this:


{{bc|1=
pcm.!surround51 {
pcm.!surround51 {
     type vdownmix
     type vdownmix
     slave.pcm "default"
     slave.pcm "default"
}
}
pcm.!surround40 {
pcm.!surround40 {
     type vdownmix
     type vdownmix
     slave.pcm "default"
     slave.pcm "default"
}
}
}}


{{Note|1=This might not be enough to make downmixing working, see [https://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 in [https://bbs.archlinux.org/viewtopic.php?id=167275].}}
{{Note|1=This might not be enough to make downmixing working; see [https://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 in [https://bbs.archlinux.org/viewtopic.php?id=167275].}}


== Dmix ==
== Dmix ==
Line 740: Line 859:
=== Keyboard volume control ===
=== Keyboard volume control ===


Map the following commands to your volume keys: {{ic|XF86AudioRaiseVolume}}, {{ic|XF86AudioLowerVolume}}, {{ic|XF86AudioMute}}
[[keyboard input|Map]] the following commands to your volume keys: {{ic|XF86AudioRaiseVolume}}, {{ic|XF86AudioLowerVolume}}, {{ic|XF86AudioMute}}.


To raise the volume:
To raise the volume:
Line 762: Line 881:
  ffmpeg -f alsa -i hw:1,1,0 -f alsa -i hw:1,1,1 -filter_complex amerge output.mp3
  ffmpeg -f alsa -i hw:1,1,0 -f alsa -i hw:1,1,1 -filter_complex amerge output.mp3


In the hw:R,W,N format R is your virtual card device number, W 1 recording devices 0 for writing, N is your sub device you can use all the virtual devices available and play/stop using applications like mplayer:
In the hw:R,W,N phrase, R is your virtual card device number. W should be set to 1 for recording devices, or 0 for playing. N is your sub device. You can use all the virtual devices available and play/stop using applications like mplayer:
  mplayer -ao alsa:device=hw=1,0,0 fileA
  mplayer -ao alsa:device=hw=1,0,0 fileA
  mplayer -ao alsa:device=hw=1,0,1 fileB
  mplayer -ao alsa:device=hw=1,0,1 fileB


Another thing you could do with this approach, is using festival to generate a voice into a recording stream using an script like this:
Another thing you could do with this approach is using [[festival]] to generate a voice into a recording stream using a script like this:
  #!/bin/bash
 
  echo $1|iconv -f utf-8 -t iso-8859-1| text2wave  > "_tmp_.wav";
  #!/bin/sh
  mplayer -ao alsa:device=hw=2,0,0 "_tmp.wav";
  echo "$1" | iconv -f utf-8 -t iso-8859-1 | text2wave  > "_tmp_.wav"
  rm "_tmp.wav";
  mplayer -ao alsa:device=hw=2,0,0 "_tmp.wav"
  rm "_tmp.wav"


=== Debugging ALSA ===
=== Debugging ALSA ===
Line 794: Line 914:
=== Correctly detect microphone plugged in a 4-pin 3.5mm (TRRS) jack ===
=== Correctly detect microphone plugged in a 4-pin 3.5mm (TRRS) jack ===


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


  options snd_hda_intel index=0 model=''your_model_setting''
  options snd_hda_intel index=0 model=''your_model_setting''


For complete list of options to put in {{ic|''your_model_setting''}}, see [https://www.kernel.org/doc/html/latest/sound/hd-audio/models.html HD-Audio Codec-Specific Models] or its source located at {{ic|/usr/lib/modules/$(uname -r)/build/Documentation/sound/hd-audio/models.rst}} (provided by the {{Pkg|linux-docs}} package).
For a complete list of options to put in {{ic|''your_model_setting''}}, see [https://docs.kernel.org/sound/hd-audio/models.html HD-Audio Codec-Specific Models] or its source located at {{ic|/usr/lib/modules/$(uname -r)/build/Documentation/sound/hd-audio/models.rst}} (provided by the {{Pkg|linux-docs}} package). A common model is {{ic|dell-headset-multi}}, even if the hardware is not from Dell.
 
Tested with Gigabyte Aero15 2017 (P65 Model), with ALC255 and set model to {{ic|dell-headset-multi}}.


== See also ==
== See also ==
Line 809: Line 927:
* [https://alsa.opensrc.org/ Unofficial ALSA wiki]
* [https://alsa.opensrc.org/ Unofficial ALSA wiki]
* [https://www.mjmwired.net/kernel/Documentation/sound/alsa/ALSA-Configuration.txt Advanced ALSA module configuration]
* [https://www.mjmwired.net/kernel/Documentation/sound/alsa/ALSA-Configuration.txt Advanced ALSA module configuration]
* [https://bbs.archlinux.org/viewtopic.php?id=36815 HOWTO: compile driver from svn]
* [https://www.volkerschatz.com/noise/alsa.html A close look at ALSA: ALSA concept introduction]
* [https://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]
* [http://www.sabi.co.uk/Notes/linuxSoundALSA.html Linux ALSA sound notes]

Latest revision as of 17:58, 1 February 2024

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 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; however, this is not recommended by default (see note below).

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(1) and amixer(1) utilities. amixer is a shell command to change audio settings, while alsamixer provides a more intuitive ncurses based interface for audio device configuration.

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

OSS compatibility

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

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

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

PulseAudio compatibility

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

$ apulse application

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 (via package provided symlink to sound.target). The options are as follows:

  • alsa-restore.service reads /var/lib/alsa/asound.state on boot and writes updated values on shutdown, provided /etc/alsa/state-daemon.conf does not exist. As /etc/alsa/state-daemon.conf is not created without a conscious action of the user, it is the default method.
  • alsa-state.service (Re-)Starts alsactl in daemon mode to continuously keep track of, and persist, volume changes, under the condition that the user has consciously created /etc/alsa/state-daemon.conf.

Evidently, both methods are mutually exclusive. You can decide for one of the two approaches depending on your requirements. To edit these units, see systemd#Editing provided units. You can check their status using systemctl.

For further information, see alsactl(1).

ALSA firmware

sof-firmware is required for some newer laptop models (mainly since 2019) because they implement their drivers with firmware provided by the Sound Open Firmware project. Checking the journal will provide messages about the missing firmware (see BBS#275577).

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
$ amixer sset Speaker unmute
$ amixer sset Headphone 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 OO indicates that it is open.

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

Use the Up 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 /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 /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. The syntax is also shown in [2].

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 a 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 definition is an alternative syntax to define compound statements. It uses brackets as separators. The keys are automatically generated as numbers, starting with zero.

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

key.0 "value0"; # Equivalent to the example above.
key.1 "value1";
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 in [3].

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 in [4].

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 error.

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

Tip: An explanation of ALSA related terminology "card", "device" (a "card" is not a "device"), "subdevice", and more, can be found on Wikipedia:Advanced Linux Sound Architecture#Concepts. Wikipedia also has many articles on related terms, such as PCM, and S/PDIF.

Setting the default sound card via defaults node

Putting the previous example regarding defaults.pcm.card and defaults.pcm.device into practice, assuming we have 2 cards with index 0 and 1 respectively and wish to simply change the default card to index 1, would lead to the following configuration in /etc/asound.conf or the user-specific ~/.asoundrc to change both the playback and the mixer control card.

defaults.pcm.card 1
defaults.ctl.card 1

Configuring the index order via kernel module options

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 [5]

Select the default PCM via environment variable

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. By looking there for constructs of the form vars [ ... ], the following table emerges:

Variable name Used by
1 ALSA_CARD pcm.default , pcm.hw , pcm.plughw , ctl.sysdefault , ctl.hw , rawmidi.default , rawmidi.hw , hwdep.hw
2 ALSA_CTL_CARD ctl.sysdefault , ctl.hw
3 ALSA_HWDEP_CARD hwdep.default , hwdep.hw
4 ALSA_HWDEP_DEVICE hwdep.default , hwdep.hw
5 ALSA_PCM_CARD pcm.default , pcm.hw , pcm.plughw
6 ALSA_PCM_DEVICE pcm.hw , pcm.plughw
7 ALSA_RAWMIDI_CARD rawmidi.default , rawmidi.hw
8 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. Card names are easier to grasp, and also overcomes the 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

Equalizer

ALSAEqual system-wide

Install the alsaequalAUR package.

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

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

pcm.plugequal {
    type equal;
    # Normally, the equalizer feeds into dmix so that audio
    # from multiple applications can be played simultaneously:
    slave.pcm "plug:dmix";
    # If you want to feed directly into a device, specify it instead of dmix:
    #slave.pcm "plughw:0,0";
}

# Configuring pcm.!default will make the equalizer your default sink
pcm.!default {
# If you do not want the equalizer to be your default,
# give it a different name, like pcm.equal commented below
# Then you can choose it as the output device by addressing
# it in individual apps, for example mpg123 -a equal 06.Back_In_Black.mp3
# pcm.equal {
    type plug;
    slave.pcm plugequal;
}

To change your equalizer settings, run

$ alsamixer -D equal

Note that the equalizer configuration 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 their home directory.

ALSAEqual for specific outputs only

If you wish to apply an equalizer to a specific output device only (for example your speakers connected to the S/PDIF output, but not your headphones connected to the headphone jack), but also want be able to output from multiple applications and to both output devices simultaneously, you need to create two dmix devices that feed into their respective devices (slave.pcm) directly. The following works for stereo output and maintains a regular stereo input, applying the equalizer to the S/PDIF output only.

/etc/asound.conf
#
#  (capture.pcm)  <-- dnsoop
#        |
# !default                               --> dmixa
#        |                               |
#  (playback.pcm) --> stereo2quad ==> quad
#                                        |
#                                        --> softvol --> plugequal --> dmixd 
#

# dmix for analog output
pcm.dmixa {
  type dmix
  ipc_key 1024
  ipc_perm 0666
  slave.pcm "hw:PCH,0"
  slave {
    period_time 0
    period_size 1024
    buffer_size 4096
    channels 2
  }
  bindings {
    0 0
    1 1
  }
}

# dmix for digital output
pcm.dmixd {
  type dmix
  ipc_key 2048
  ipc_perm 0666
  slave.pcm "hw:PCH,1"
  slave {
    period_time 0
    period_size 1024
    buffer_size 4096
    channels 2
  }
  bindings {
    0 0
    1 1
  }
}

# equalizer with controls
pcm.plugequal {
  type equal
  slave {
    pcm "plug:dmixd"
  }
}
ctl.equal {
 type equal
}

# Volume control for S/PDIF
pcm.softvol {
    type softvol
    slave.pcm "plug:plugequal"
    control {
        name "S/PDIF"
    }
}

# multi:
# "a" (analog)  -> dmix,
# "d" (digital) -> softvol -> plugequal -> dmix
pcm.quad {
    type multi
    slaves {
      a.pcm "dmixa"
      a.channels 2
      d.pcm "plug:softvol" # detour via softvol and equalizer
      d.channels 2
    }
    bindings {
      0 { slave a; channel 0; }
      1 { slave a; channel 1; }
      2 { slave d; channel 0; }
      3 { slave d; channel 1; }
    }
}

# stereo to quad
pcm.stereo2quad {
  type route
  slave.pcm "quad"
  ttable [
    [ 1 0 1 0 ]
    [ 0 1 0 1 ]
  ]
}

# playback to stereo to quad, capture as usual
pcm.!default {
  type asym
  playback.pcm "plug:stereo2quad"
  capture.pcm "plug:dnsoop"
}

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

This, however, only restores ~/.alsaequal.bin. You then have to update the equalizer by alsamixer -D equal.

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

mbeq is a fairly typical multi band graphical equalizer. [6]

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[7]. 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.
  • It is also possible to use lavcrate[8] 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.
  • 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 [9]. 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 in [10].

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

Disabling auto mute on startup

Auto-Mute Mode can be configured on startup with amixer. For example, to disable it:

# amixer -c 0 sset "Auto-Mute Mode" Disabled

Alternatively, the graphical interface can be utilized through alsamixer. In order to save any modifications, use:

# alsactl store

or

# alsactl daemon

See ALSA and Systemd

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 /Troubleshooting#Crackling sound through mini-jack (headphones connector).

Keyboard volume control

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

To raise the volume:

amixer set Master 5%+

To lower the volume:

amixer set Master 5%-

To toggle mute/unmute of the volume:

amixer set Master toggle

Virtual sound device using snd-aloop

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

modprobe snd-aloop

List your new virtual devices using:

aplay -l

now you can for example using ffmpeg:

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

In the hw:R,W,N phrase, R is your virtual card device number. W should be set to 1 for recording devices, or 0 for playing. N is your sub device. You can use all the virtual devices available and play/stop using applications like mplayer:

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

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

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

Debugging ALSA

Retrieving the driver state

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

See ALSA bug tracking for more info.

Reconfiguring input/output ports

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

Resetting codecs

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

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

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

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

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

options snd_hda_intel index=0 model=your_model_setting

For a complete list of options to put in your_model_setting, see HD-Audio Codec-Specific Models or its source located at /usr/lib/modules/$(uname -r)/build/Documentation/sound/hd-audio/models.rst (provided by the linux-docs package). A common model is dell-headset-multi, even if the hardware is not from Dell.

See also