ALSA has a mechanism to save and restore settings:
# alsactl store
# alsactl restore
It will use a default file (usually /var/lib/alsa/asound.state
) to save settings, and restore them from. The restore operation is usually done automatically at system bootup, usually from a systemd service.
However, it may happen that PulseAudio (the audio server that is often used by default on "recent" distributions), will override the ALSA settings by its own, sometimes messing up things. It may not so easy to teach PulseAudio to behave as you'd like, so a workaround of this kind might be used:
You may want to launch the following script (~/alsarestore.sh
) from the root user crontab.
#!/bin/sh
restore_alsa() {
while [ -z "$(pidof pulseaudio)" ]; do
sleep 1
done
alsactl restore
}
restore_alsa &
It will wait for PulseAudio to launch before calling alsactl restore
(considering the stored configuration is the one you want).
Finally, as root, you may want to add this to crontab -e
:
@reboot ~/alsarestore.sh 2>/dev/null
This work around is inspired from this ArchLinux wiki article.