ALSA/de

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page ALSA and the translation is 8% complete.
Outdated translations are marked like this.
Some of the information in this article may have drifted out of sync with current practices. Please help out by checking over the content (how to get started).


Dieser Artikel beschreibt die Einrichtung von einer Soundkarte mit ALSA (Advanced Linux Sound Architecture).

As of 2026年01月14日, desktop profiles enable the PipeWire sound server. This includes support for packages which make use of the PulseAudio interface (e.g. via the pulseaudio USE flag), by using media-sound/libpulse and pipewire-pulse(1) .

Those using PipeWire as a sound server - whether via a profile or otherwise - should typically not need to manually configure ALSA. However, those with more complex hardware and software setups might need to do so.

This page assumes that no sound server is being used.

Hardwareerkennung

Wichtig
To check if a system has working soundcard driver modules, run lsmod(8) . If that lists no modules with the prefix snd_, be sure that the kernel driver module for the system's specific soundcard is installed. Refer to the Kernel Modules page for details.

Um den richtigen Treiber zu wählen, muss zuerst der verwendete Audiocontroller ermittelt werden. Benutzen Sie hierfür lspci :

user $lspci | grep -i audio

Sobald der Name des Controllers ermittelt wurde, kann der benötigte Treiber in der ALSA Soundkarten-Matrix gefunden werden.

Kernel

Aktivieren Sie die folgenden Kerneloptionen:

KERNEL
Device Drivers --->
 <*> Sound card support
 <*> Advanced Linux Sound Architecture --->
 [*] PCI sound devices --->
 Select the driver for your audio controller.
 HD-Audio --->
 Select a codec or enable all and let the generic parse choose the right one:
 [*] Build Realtek HD-audio codec support
 [*] ...
 [*] Build Silicon Labs 3054 HD-modem codec support
 [*] Enable generic HD-audio codec parser
 [*] USB sound devices --->
 Must have as some cards are presented as USB devices.
 [*] USB Audio/MIDI driver
General setup --->
 [*] System V IPC

Wenn das System mehr als 8 Audioausgänge hat (jeder HDMI-Anschluss an einer GPU gilt als solches), muss die maximale Anzahl an Soundkarten erhöht werden:

KERNEL
Device Drivers --->
 <*> Sound card support
 <*> Advanced Linux Sound Architecture --->
 [*] Dynamic device file minor numbers
 (32) Max number of sound cards

Kernel modules

For advanced configurations (e.g. involving multiple sound cards), it can be better to select all the ALSA-related kernel options as modules. Then, their use can be configured via two files:

  • /etc/modules-load.d/alsa.conf - one line per module, normally only needed for virtual sound cards.
  • /etc/modprobe.d/alsa.conf - for the modules' options.

For example, assume a laptop with two hda-intel sound cards and an external USB card. If the aloop and VirMIDI virtual sound cards are also required, together with a card order that persists across reboots:

  1. the aloop virtual card
  2. the hda-intel PCM device
  3. the hda-intel HDMI device
  4. the VirMIDI virtual device
  5. the USB card

then the relevant modules should be loaded in that order:

DATEI /etc/modprobe.d/alsa.conf
options snd slots=snd-aloop,snd-hda-intel,snd-hda-intel,snd-virmidi,snd-usb-audio
options snd-hda-intel index=1,2 model=1002:1637,1022:15e3

Card indexes start from 0.

To get the model strings, use lspci(1) (or lsusb(1) for USB cards):

root #lspci -nn
04:00.1 Audio device: Advanced Micro Devices, Inc. [AMD/ATI] Renoir Radeon High Definition Audio Controller [1002:1637]
04:00.6 Audio device: Advanced Micro Devices, Inc. [AMD] Family 17h/19h HD Audio Controller [1022:15e3]

Instruct the kernel to load the virtual sound cards:

DATEI /etc/modules-load.d/alsa.conf
snd-aloop
snd-virmidi

Software

Portage kennt die globale USE flag alsa, welche die Unterstützung für ALSA in anderen Paketen aktiviert. Durch das aktivieren dieser USE flag wird automatisch media-libs/alsa-lib hinzugezogen (Standardeinstellung in den x86 und amd64 Desktop-Profilen):

Nachdem dies eingestellt wurde, muss sichergestellt werden dass das System aktualisiert wird, sodass die Änderungen übernommen werden:

root #emerge --ask --changed-use --deep @world

Das Paket media-sound/alsa-utils stellt einige Werkzeuge zur Fehlerbehebung und zum Testen des Soundsystems bereit. Es ist zu empfehlen das Paket zu mergen, falls dies noch nicht installiert wurde:

root #emerge --ask media-sound/alsa-utils

Commands provided by media-sound/alsa-utils include:

Name Description
aconnect(1) ALSA sequencer connection manager
alsactl(1) Advanced controls for ALSA soundcard driver
alsamixer(1) Soundcard mixer for ALSA soundcard driver, with ncurses interface
amixer(1) Command-line mixer for ALSA soundcard driver
aplay(1) Command-line player for ALSA soundcard driver
aplaymidi(1) Play Standard MIDI Files
arecord(1) Command-line sound recorder for ALSA soundcard driver
aseqdump(1) Show the events received at an ALSA sequencer port
speaker-test(1) Command-line speaker test tone generator for ALSA

Konfiguration

Dateien

  • /etc/asound.conf - Globale (systemweite) Konfigurationsdatei.
  • ~/.asoundrc - Lokale (userspezifische) Konfigurationsdatei.
  • /var/lib/alsa/conf.d/
  • /usr/etc/alsa/conf.d/
  • /etc/alsa/conf.d/
  • /etc/asound.conf or /usr/etc/asound.conf
  • ~/.asoundrc
  • ${XDG_CONFIG_HOME}/alsa/asoundrc

Configuration locations later in the list override earlier ones. If the XDG_CONFIG_HOME environment variable is not set, it's given a default value of ~/.config/.

/etc/asound.conf is typically used as the global (system-wide) configuration file, while ~/.asoundrc is typically used as a local (per-user) configuration file, overriding ALSA configuration for a specific user. Neither file exists by default; each must be created manually as necessary.

This page refers to both /etc/asound.conf and ~/.asoundrc when describing configuration snippets, but the snippets can typically be added to either file (or to another location), depending on the specific configuration being sought. For example, one particular snippet might be most appropriately applied system-wide, or might be most appropriately applied per-user.

A description of the syntax for ALSA configuration files is available in /usr/share/doc/alsa-lib-<version>/asoundrc.txt.gz.

Various configuration snippets are available in the /usr/share/alsa/, the global configuration directory. For example, snippets available in the /usr/share/alsa/pcm/ directory include dmix.conf, hdmi.conf, and surround51.conf.

Creating a configuration

In general, ALSA should work "out of the box", and not require any manual configuration. To list the current ALSA configuration, including any configuration files being applied, use the command alsactl dump-cfg. Additionally, ALSA's current state can be listed by using the command alsactl dump-state; ALSA state is stored in, and restored from, /var/lib/alsa/asound.state.

Diese Datei kann optional dazu verwendet werden, um userspezifisch ALSA-Standardeinstellungen zu überschreiben. Wenn das System spezielle Hardware hat, ist es wahrscheinlich, dass Karte 0 und Gerät 0 (die Standardwerte) nicht funktionieren werden.

Falls Sie keine Kartennummer finden können, die das Gerät identifiziert welches Sie verwenden möchten, keine Panik - Die Kartennummer ist intern ein Name, den Sie verwenden können. Wenn Ihre Karte wie folgend aufgelistet ist...

user $aplay -L
front:CARD=Generic,DEV=0
HD-Audio Generic, ALC282 Analog
Front speakers

... dann bedeutet es, dass die Datei ~/.asoundrc so aussehen sollte:

DATEI ~/.asoundrc
defaults.pcm.!card Generic
defaults.pcm.!device 0
defaults.ctl.!card Generic

This snippet demonstrates the use of .! to specify 'override' operation mode[1] .

The default operation mode, 'merge+create', is indicated by either a bare . character before the final component of the node, or by .+ in that position. In this mode, if a configuration node is not present, a new one is created; otherwise, if it passes type checking, the assignment is merged.

For example, in the node defaults.pcm.card, the final component is card, and there is a bare . preceding it, thus indicating that 'merge+create' mode is used for the node.

However, if .! is used instead, as in the snippet above, 'override' mode is used for the node: the old node value will be overwritten with the new value. Thus, the above snippet will overwrite the old value of each of the specified nodes with the value specified (e.g. PCH)

Wenn der korrekte Name nicht zu erkennen ist, kann einfach eine Liste mit folgendem Kommando ausgegeben werden:

user $cat /sys/class/sound/card*/id
Q1U
HDMI
PCH
C930e

Hier haben wir das Q1U-Mikrofon als Q1U, das eingebaute HDMI als HDMI, den analogen Klinkenstecker als PCH und das eingebaute Mikrofon der Webcam als C930e. Alle dieser Namen sind verwendbar für die Karte.

PulseAudio emulation

Some software (e.g. Firefox) makes use of the Pulse API. For PulseAudio support on a pure-ALSA system (i.e. one not using a sound server such as PipeWire or Pulse), install apulse.

S/PDIF oder HDMI .asoundrc

With a default ALSA installation, an S/PDIF or HDMI connection might work "out of the box", without requiring any manual configuration of ALSA. If this is not the case, use aplay -L to find the appropriate card name and device number, as described in the the "Files" section above, then use that information in the following snippet for the appropriate ALSA configuration file:

DATEI ~/.asoundrc
pcm.!spdif {
 type hw
 card 0
 device 1
}
pcm.!default {
 type plug
 slave {
 pcm "spdif"
 }
}
# Gemeinsame Nutzung einer einzigen Karte mit mehreren Anwendungen
#pcm.!default {
# type plug
# slave.pcm "dmix:CARD=0,DEVICE=1,RATE=48000"
#}
Hinweis
When playing sound files using aplay, the beginning of the playback will be clipped because the digital S/PDIF or HDMI connection is not held open and needs to be started each time a sound file is played.

The above configuration will not allow sound to be played from more than one sound application, or two sounds to be played simultaneously through the same sound card. In order to allow this, use the following configuration snippet for mixing (noting that doing so might result in interrupted output and/or a slight degradation in sound quality):

DATEI /etc/asound.conf
# Share a single card with multiple applications 
pcm.!default {
 type plug
 slave.pcm "dmix:CARD=PCH,DEVICE=1,RATE=48000"
}

Cloning audio for two or more devices

Sometimes there's a need to clone audio: for example, using two cloned screens with different inputs, where the first screen is HDMI, and the second screen is DVI and analog audio.

The following snippet provides such a configuration. Adjust it as necessary for the system to which it's being applied.

Refer to this forum discussion for more information.

DATEI /etc/asound.conf
ctl.!default {
 type hw
 # Setzen Sie Ihre Standardkarte
 card 0
}
pcm.!default both
pcm.both {
 type softvol
 slave {
 pcm {
 type plug
 slave {
 pcm {
 type route
 slave {
 pcm {
 type multi
 slaves.a.pcm {
 type dmix
 ipc_key 2589455
 ipc_perm 0666
 slave {
 pcm {
 # Fügen Sie die Standardkarte hinzu - ändern Sie sie entsprechend Ihrer Soundkarte #1
 type hw
 card 0
 device 0
 }
 buffer_size 4096
 channels 2
 }
 }
 slaves.b.pcm {
 type dmix
 ipc_key 4855689
 ipc_perm 0666
 slave {
 pcm {
 # Fügen Sie die Slave-Soundkarte hinzu - passen Sie sie an Ihre Soundkarte an #2
 type hw
 card 1
 device 7
 }
 buffer_size 4096
 channels 2
 }
 }
 slaves.a.channels 2
 slaves.b.channels 2
 bindings.0.slave a
 bindings.0.channel 0
 bindings.1.slave a
 bindings.1.channel 1
 bindings.2.slave b
 bindings.2.channel 0
 bindings.3.slave b
 bindings.3.channel 1
 }
 }
 ttable.0.0 1
 ttable.1.1 1
 ttable.0.2 1
 ttable.1.3 1
 }
 }
 }
}
control {
 # Name der Lautstärkeregelung festlegen
 name PCM
 # Setzen Sie Ihre Standardkarte
 card 0
}

A/52, AC3, Dolby, DTS

Sound cards providing S/PDIF output can do lossy compressed multichannel audio passthrough. An S/PDIF or HDMI connection is required for passthrough of advanced encoding; analog connections (RCA and minijacks) don't support any advanced encoding.

If a sound card states it has S/PDIF, it will also likely pass A/52 (also known as Dolby AC-3 and Dolby Digital) and/or DTS, even if neither is specifically listed as a feature. When a card lists one or both, it's because the vendor provides software for upmixing, or provides the decoded signal through analog output.

Hinweis
Decoding from, or encoding to, A/52 or DTS requires a license; having a sound card with multichannel support often provides such a license. Refer to this article for more information.

For A/52 support, install the media-plugins/alsa-plugins package with the ffmpeg USE Flag enabled.

Audio/multimedia players might need multichannel codecs specified in their configuration, to allow the provision of hardware passthrough rather than downmixing.

Encoding to A/52

To simulate A/52-encoded audio from standard one- or two-channel audio streams or files:

DATEI ~/.asoundrc
pcm.!default {
 type plug:surroundaudio
}
ctl.!default {
 type plug:surroundaudio
}
pcm.a52encode {
 type a52
 format S16_LE
 channels 6
 rate 48000
 bitrate 448
}
pcm.surroundaudio a52encode
ctl.surroundaudio {
 type hw
 card 0
 device 1
}

Test the configuration with speaker-test(1) :

user $speaker-test -Dsurroundaudio -c 6

The preceding snippet might not work with PCM 5.1 streams. Additionally, such streams might also require downmixing from S24_LE to S16_LE format: 24-bit is a common format for most media, but receivers can sometimes only decode 16- or 32-bit audio.

The following configuration snippet will encode a PCM 5.1 24-bit stream into a 16-bit A/52 stream, for streaming over S/PDIF. Note that this is not required when using HDMI, as HDMI can handle the bandwidth of a PCM 5.1 audio stream.

DATEI ~/.asoundrc
# Make it possible to use A/52 with PulseAudio out of 
# the box. May also be useful for other use-cases.
 
pcm.a52 {
 @args [ CARD ]
 @args.CARD {
 type string
 default 0
 }
 type plug
 slave {
 pcm {
 type a52
 card $CARD
 bitrate 640 # Default 448
 }
 # Convert to S16 bit format, per S/PDIF spec
 format S16_LE
 }
}
user $aplay -D pcm.a52 /home/me/Music/Led_Zeppelin/Celegration_Day/PCM51-24bit/*.wav
user $aplay -D pcm.a52 /home/me/Music/Led_Zeppelin/Celegration_Day/PCM51-24bit/*.wav

JACK Audio Connection Kit

It is possible to interconnect JACK and ALSA. For more information, refer to this section of the "JACK" page.

Rechte

If the acl USE flag is enabled globally, and a login daemon (e.g. systemd-logind(8) or elogind) is being used, such as on systems using a desktop profile, sound card permissions will be handled automatically. Permissions can be checked using getfacl(1) :

user $getfacl /dev/snd/controlC0 | grep larry
user:larry:rw-

A broader solution is to add the user accessing the sound card to the audio group.

root #gpasswd -a larry audio
user $grep audio /etc/group
audio::18:larry
Warnung
Unless use of the dmix plugin has been configured, a user being in the audio group might result in a single application taking control of the sound card in a way that prevents other applications from using it. Note also that adding a user to the audio group is not needed when using PipeWire.

To confirm that the user has been added to the audio group, check the contents of /etc/group:

user $grep audio /etc/group
audio::18:larry

To apply this change generally, log out and back in again. To immediately apply this change within a current shell session, use newgrp(1) :

user $newgrp audio

Dienste

OpenRC

The alsasound service saves and restores mixer levels. To start it manually:

root #rc-service alsasound start

To have the service start at boot, add it the boot runlevel using rc-update:

root #rc-update add alsasound boot

systemd

On systemd systems, ALSA state is preserved and restored automatically across system restarts.

The current ALSA state can be checked using the systemctl command:

root #systemctl status alsa-restore

Bedienung

This section assumes that the media-sound/alsa-utils package has been installed, as recommended in the "Software" section.

Test speakers

Use speaker-test(1) to test speakers:

user $speaker-test -t wav

Press Ctrl+C to interrupt the test.

Various options are available to specify the test output, e.g. the number of channels and the test type; refer to the man page for details.

For systems using 5.1 surround sound:

user $speaker-test -t wav -c 6 -D surround51

Falls Sie versuchen die Testprozedur durchzuführen und der Lautsprechertest einen Fehler bezüglich "function IPC semaphore not implemented" zurückgibt, ist folgendes die Option, die dafür im Kernel aktiviert werden muss:

Testen von HDMI/SPDIF 5.1 und 7.1-Lautsprechern

In der Beschreibung von ALSA's Lautsprechertest-Dienstprogramm steht, dass dieses nicht mehr als zwei Audiokanäle über HDMI oder SPIDF testet. Dafür muss mplayer verwendet werden, wie aus der Dokumentation von ALSA zu entnehmen ist.

Downloaden Sie entweder eine 5.1 Kanal (FLAC) oder eine 7.1 Kanal (FLAC) Lautsprechertest-Audiodatei:

Spielen Sie die heruntergeladene Audiodatei ab; legen Sie das HDMI- oder SPIDF-Gerät, die PCM-Datei und Anzahl der Kanäle fest, die höchstwahrscheinlich entweder 6 (für 5.1 Surround) oder 8 (für 7.1 Surround) sein wird.

Um 5.1-Kanal mit mplayer zu testen:

user $mplayer -channels 6 "/path/to/downloaded/flac_file.flac" -channels 6

Um 7.1-Kanal zu testen:

user $mplayer -channels 8 "/pfad/zur/heruntergeladenen/flac_datei.flac" -channels 8
Hinweis
Um mplayer ohne Standardgerät zu testen, fügen Sie die zusätzliche Option -ao alsa:device=hw=0.7 an, und passen Sie den Wert von hw= jeweils auf das entsprechende Gerät an.
user $cvlc /pfad/zur/heruntergeladenen/flac_datei.flac
user $cvlc /path/to/downloaded/flac_file.flac

Test microphone

arecord(1) can be used to test a microphone.

The following will record until CTRL+C is pressed, and by default will provide a mono recording as a WAV file in U8 format:

user $arecord /tmp/test.wav

Use aplay(1) to play the saved file.

The file type, number of channels, and file format can be specified via the -t/--file-type, -c/--channels, and -f/--format options, respectively.

If a default audio device is not set, specify a device using arecord's --device option. using the -l/--list-devices option to find the relevant card and device number:

user $arecord --list-devices
Hinweis
The line or microphone channel might need to be unmuted. This can be done via alsamixer(1) or amixer(1) .

Fehlersuche

Refer to the ALSA/troubleshooting page.

Siehe auch

Externe Ressourcen

References