424. Audio
This page is for getting sound out of a KDOS machine and fixing it when there is none: choosing an output and its volume, playing from an ssh login or a root shell, keeping the mixer levels across boots, and what to check when nothing plays or the sound breaks up.
Sound on KDOS is the PipeWire sound server, started once per user at that user’s first login. WirePlumber decides where each stream goes, and pipewire-pulse serves programs written for PulseAudio. Under PipeWire is ALSA, the kernel’s sound layer, which is all there is when nobody is logged in. A Bluetooth headset is paired on Bluetooth and then behaves as any other output here.
Installation
| Part | Ports |
|---|---|
| The sound server | pipewire, with pipewire-pulse, its ALSA plugin and its own libjack.so.0 |
| The session manager | wireplumber, which also provides wpctl |
| ALSA | alsa-lib, alsa-utils (alsactl, alsamixer, aplay, speaker-test), alsa-ucm-conf |
| Firmware for Intel’s audio DSP | sof-firmware |
| The desktop’s volume control | plasma-pa: the volume applet in the panel’s tray, the Sound page of System Settings and the volume keys |
Every image carries them. No system service runs PipeWire. The three are user services in /etc/kdos/user-services/, which turnstile starts under the user’s own ksvc at the user’s first login of any kind, the desktop, a console on tty2 or the serial line, and stops at the last logout. wireplumber and pipewire-pulse are supervised to restart with pipewire. From fs/etc/kdos/user-services/20_pipewire.sh:
# THE REAL-TIME BUDGET COMES FROM PAM. The turnstile backend runs inside the
# `turnstiled` PAM session, whose pam_limits applies
# /etc/security/limits.d/25-pw-rlimits.conf (pipewire's, for the audio group):
# rtprio 95, nice -19, memlock 4 MiB. Without the group the daemon runs at
# normal priority and an underrun on a busy machine is a click.
#
# WIREPLUMBER (21) AND pipewire-pulse (22) FOLLOW IT. Both connect to this
# daemon's socket and neither exits when it goes away, so each is supervised
# `--restart-with pipewire`: a crash of this one restarts both once it is back.
fs/etc/kdos/user-services/20_pipewire.sh, lines 10–18
See The user’s services and Session and environment.
One service script concerns sound, 50_alsa, which restores the cards’ mixer levels at boot and saves them at shutdown. It is part of the base filesystem; the installer offers it as a choice, on by default:
const Service ki_services[] = {
{ "networkmanager", "NetworkManager", "wired, wifi and VPN", 1 },
{ "bluetooth", "Bluetooth", "bluez daemon", 1 },
{ "alsa", "ALSA state", "restore mixer levels at boot", 1 },
{ "cups", "CUPS", "printing daemon", 1 },
{ "sshd", "OpenSSH server", "accepts remote logins", 0 },
};
src/system/kinstall-core/conf.c, lines 29–35
There is no JACK server and no PulseAudio daemon. JACK programs load PipeWire’s libjack.so.0, and PulseAudio programs talk to pipewire-pulse; see JACK programs on the host.
Configuration
/etc/alsa/conf.d/99-kdos-pipewire.conf
The one file that decides where a plain ALSA program’s sound goes. It defines two devices and points ALSA’s default at one of them, chosen by the environment variable KDOS_ALSA_DEFAULT, PipeWire when it is unset. The mixer control is left on the card. The comments at the top of the file give the rule behind each part; these are its definitions:
pcm.kdos_pipewire {
type pipewire
playback_node "-1"
capture_node "-1"
hint {
show on
description "Default Audio Device (PipeWire)"
}
}
# THE BUILT-IN CARD CHAIN, REACHABLE BY NAME. `sysdefault` is alsa-lib's own
# per-card default -- plug -> softvol -> dmix -- and nothing here overrides it,
# so this name is the card and only the card. It is EXCLUSIVE in both
# directions: while a dmix client holds the device PipeWire cannot open it, and
# while PipeWire holds the device this fails to open. That is the whole reason
# `default` is not this.
#
# IT IS `empty`, A PASS-THROUGH, AND NEVER A SECOND `plug`. `default` below is
# already a plug, and `sysdefault` brings its own; a third between them makes
# alsa-lib's parameter refinement abort the program that opens `default`
# (`Assertion failed: !snd_interval_empty(i)`, exit 134) — aplay, espeak-ng
# and BRLTTY's speech alike — while `aplay -D kdos_card` alone still plays.
pcm.kdos_card {
type empty
slave.pcm "sysdefault"
hint {
show on
description "Sound Card (no sound server)"
}
}
# A PROCESS OUTSIDE EVERY LOGIN HAS NO PIPEWIRE, AND NOTHING STARTS ONE FOR IT.
# PipeWire is one of the user's services (/etc/kdos/user-services), which
# turnstile starts at the user's first PAM login — the desktop, a tty2 or a
# serial-console login — and stops at the last. root gets none, nor does an ssh
# login of a user with no other one (openssh opens no PAM session), nor
# anything init starts. A compiled-in `type pipewire` would
# leave every ALSA program on those paths unable to open a device at all --
# libmikmod's driver, to name the one that matters, opens the literal name
# `default` and parses no options. So the choice is an environment variable:
#
# KDOS_ALSA_DEFAULT=kdos_card kdos-bb
#
# Any pcm name defined above is accepted. An undefined one fails with "Unknown
# PCM <name>" and an absent daemon with "Host is down": both are loud, and
# neither is silence.
pcm.!default {
type plug
slave.pcm {
@func getenv
vars [
KDOS_ALSA_DEFAULT
]
default "kdos_pipewire"
}
}
fs/etc/alsa/conf.d/99-kdos-pipewire.conf, lines 27–82
kdos_card is the sound card with no server in between, and it is exclusive: while a program holds it PipeWire cannot open the card, and the other way round. It is a pass-through, type empty, because default is already a plug and sysdefault starts with one: a third plug between them makes alsa-lib abort any program that opens default. Why the file lives in /etc/alsa/conf.d and why every redefinition carries its ! are in Reaching the graph from a plain ALSA program on the host.
/etc/pipewire/pipewire.conf.d/99-kdos-vm.conf
Under a hypervisor, PipeWire’s quantum, the number of frames it processes per cycle, is raised to keep more audio in the card. On real hardware the rule does not match and PipeWire keeps its own defaults:
context.properties.rules = [
{ matches = [ { cpu.vm.name = !null } ]
actions = {
update-props = {
default.clock.quantum = 4096
default.clock.min-quantum = 4096
default.clock.max-quantum = 8192
}
}
}
]
fs/etc/pipewire/pipewire.conf.d/99-kdos-vm.conf, lines 38–48
The measurements behind the numbers are in The quantum, and why a virtual machine gets a bigger one.
PipeWire’s and WirePlumber’s own configuration is upstream’s, under /usr/share/pipewire and /usr/share/wireplumber. Add an override as a file in a .conf.d directory, /etc/pipewire/ for the machine or ~/.config/pipewire/ and ~/.config/wireplumber/ for one user, rather than editing the files under /usr/share, which the next upgrade replaces.
The mixer levels: 50_alsa and /var/lib/alsa
. /etc/init.d/service_helper
NAME="alsa"
case "$1" in
start)
if ! command -v alsactl >/dev/null 2>&1; then
echo "[SKIP] $NAME: alsactl not found"
exit 0
fi
echo "[KDOS] Restoring ALSA mixer settings..."
# A live ISO has no /var/lib/alsa/asound.state, and a failed restore
# leaves the card exactly as the kernel left it — which for HDA is
# Master MUTED at 0%/-74dB. Every PCM then opens, reports RUNNING and
# plays silence, so the card looks present and working while nothing
# comes out of a console program. The desktop is unaffected only
# because pipewire drives the mixer itself. `alsactl init` applies
# /usr/share/alsa/init/, and answers 99 when it matched a generic rule
# rather than a card-specific one — that is a success here, so its
# status is deliberately ignored.
if ! alsactl restore >/dev/null 2>&1; then
echo "[KDOS] No saved mixer state — applying card defaults..."
alsactl init >/dev/null 2>&1 || true
fi
echo "[KDOS] $NAME ready"
;;
stop)
echo "[KDOS] Saving ALSA mixer settings..."
alsactl store 2>/dev/null || true
;;
status)
if command -v alsactl >/dev/null 2>&1; then
echo "[ OK ] $NAME: alsactl available"
else
echo "[DOWN] $NAME: alsactl not found"
fi
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 1
;;
esac
The saved state is /var/lib/alsa/asound.state, in the directory alsa-utils creates:
install -d "$PKG/var/lib/alsa"
ports/core/audio-io/alsa-utils/build.sh, lines 28–28
Real-time priority
PipeWire runs its threads at real-time priority only when its PAM session allows it. turnstile starts the user’s services inside its own PAM session, whose pam_limits applies pipewire’s /etc/security/limits.d/25-pw-rlimits.conf to members of the audio group: real-time priority 95, nice -19 and 4 MiB of locked memory. KDOS adds a floor of real-time priority 1 for every login, which KWin uses, from fs/etc/security/limits.d/30-kdos.conf:
# The least real-time priority every login gets: 1.
#
# KWin asks for SCHED_RR at the lowest real-time priority for the threads
# that read input and commit frames, so a busy machine does not stall the
# pointer. It gets it only with RLIMIT_RTPRIO >= 1 or CAP_SYS_NICE, and a
# file capability does not survive kpkg's archive, so this limit is the one
# route; without it KWin logs "Failed to gain real time thread priority" and
# runs its compositing at normal priority.
#
# pam_limits reads it at every PAM login — SDDM's, the greeter's (whose own
# 30-sddm.conf says the same for the sddm account), a console login and
# turnstile's session for the user services. `*` is the lowest-precedence
# entry pam_limits knows: a group entry outranks it whatever the file order,
# so the audio group's rtprio 95 in pipewire's 25-pw-rlimits.conf still
# applies to its members. What keeps a process at priority 1 from starving
# the rest of the machine is the kernel's fair-class deadline server
# (/sys/kernel/debug/sched/fair_server), which runs normal tasks for a share
# of every second on each CPU however busy its real-time threads are;
# kernel.sched_rt_runtime_us equals its period on this kernel, so the
# real-time throttle bounds nothing.
# ---------------------------------
* - rtprio 1
fs/etc/security/limits.d/30-kdos.conf
A member of audio keeps 95: a group entry outranks *. Whether it took is visible per thread:
ps -L -o pid,cls,rtprio,comm -p "$(pgrep -x pipewire)"
lists PipeWire’s data-loop.0 thread as FF (SCHED_FIFO) with a real-time priority of 88; a TS there is a thread that was not promoted.
Usage
Choosing the output and its volume
- Click the volume applet in the system tray: it lists every output and input, with a slider each, and the stream of each application playing. Pick the default output there.
- System Settings → Sound sets each device’s profile (stereo, surround, HDMI), its balance and the default output and input.
- The volume keys change the default output’s volume, with an on-screen display.
From a terminal, wpctl does the same:
wpctl status
wpctl set-default <id>
wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+
wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
The <id> is the number wpctl status prints beside each sink.
Testing the output
speaker-test -c 2 -t wav -l 1
plays a voice naming each channel once, through ALSA’s default, which is PipeWire for any login. pw-play <file> plays a file into PipeWire directly.
Playing from an ssh login or a root shell
A console login on tty2 or the serial line starts the user’s PipeWire like the desktop does. An ssh login of a user with no other login has none, because OpenSSH opens no PAM session, and neither does root or anything init starts. Play straight to the card instead:
KDOS_ALSA_DEFAULT=kdos_card aplay sound.wav
kdos_card is exclusive, so this fails while a user’s PipeWire holds the card, with audio open error: Resource busy, and the session has no sound while the program plays.
Keeping mixer levels
Set the levels with
alsamixer(F6chooses the card).Save them at once, rather than waiting for the next shutdown:
sudo alsactl store
Restarting the sound server
service --user restart pipewire
wireplumber and pipewire-pulse restart with it. service --user status shows all three. Programs that were playing reconnect or need restarting, according to the program.
Tips
aplay -Llists the PCM names ALSA knows, with the two from99-kdos-pipewire.confamong them: “Default Audio Device (PipeWire)” and “Sound Card (no sound server)”. Run it after any edit of an ALSA configuration file before believing anything else.aplay -llists the cards and their devices;cat /proc/asound/cardsdoes the same without alsa-utils.pw-topshows every node with its quantum and itsERRcolumn, the count of underruns.pw-metadata -n settingsshows the quantum in force.defaults.pcm.cardanddefaults.ctl.cardin~/.asoundrcchoose the cardkdos_cardandsysdefaultopen, and the cardalsamixershows first. They do not move the session’s sound, which goes through PipeWire.- The microphone privacy lamp in the system tray lights only while a recording stream is running; a click mutes or unmutes every microphone capture.
- After an upgrade of pipewire or alsa-lib,
kdos restartslists the processes still running the old code.
Troubleshooting
Nothing plays in the desktop session.
Is PipeWire running, and does it have a sink?
service --user status pipewire wpctl statusThe services’ logs are
$XDG_RUNTIME_DIR/ksvc/kdos-svc.pipewire.logand the same forwireplumber.If
wpctl statuslists no sinks, another program may hold the card. The owner of the first playback stream is in:cat /proc/asound/card0/pcm0p/sub0/statusUnder PipeWire its
owner_pidis the PipeWire daemon. Another process there is a program that opened the card directly, throughkdos_card,hw:orsysdefault; close it.If the sink exists and is silent, check its volume and mute in the volume applet or with
wpctl status, then the card’s own levels inalsamixer.
A program fails with Host is down. There is no PipeWire for that login. Run it with KDOS_ALSA_DEFAULT=kdos_card, as in Playing from an ssh login or a root shell.
A program fails with Unknown PCM. KDOS_ALSA_DEFAULT names a device that is not defined: alsa-lib prints Unknown PCM <name>, and aplay then audio open error: No such file or directory. aplay -L lists the names that are.
Every ALSA program fails after an edit, with default is not a compound. A redefinition of a name ALSA already has lacks its !; write pcm.!default, not pcm.default. Check with aplay -L.
A console program plays and nothing is heard. The card may be muted. 50_alsa applies the card’s defaults when there is no saved state, and its log, /run/kdos-init.alsa.log, then reads No saved mixer state — applying card defaults.... Unmute in alsamixer, and sudo alsactl store writes /var/lib/alsa/asound.state, which the next boot restores. service status alsa only reports [ OK ] alsa: alsactl available: there is no daemon behind it.
The sound stutters in a virtual machine. An emulated card has no clock of its own. Check that the larger quantum is in force with pw-metadata -n settings, and watch pw-top’s ERR column while it plays. Nothing appears in dmesg: the underrun is the player’s, not the card’s.
An Intel laptop has no sound card. A machine whose audio runs through Intel’s DSP needs the SOF firmware and topology files. kdos doctor checks both in its Hardware section, and dmesg | grep -i sof shows what the driver asked for.
A boxed application has no sound, or takes the card from everything else. See Reaching the graph from inside a box.
Known gaps
kdos doctorcannot check hardware a machine does not have: with no SOF device the SOF check reports only that the firmware is installed,SOF firmware installed (no SOF audio device here), and says nothing about the topology files- Features whose library has no port: FireWire audio interfaces, and PipeWire’s ROC streaming, LC3plus and LDAC decoding
- Broad hardware support is not a goal
See also
- Audio: how the session starts PipeWire, and why it is built as it is
- The system tray: the tray’s audio applet, and the privacy lamps that show what is recording
- Session, screen and media: the volume and microphone keys
- Services:
50_alsain the boot order - Bluetooth, udev and device groups, Users and groups, Microcode and firmware