The officially official Devuan Forum!

You are not logged in.

#1 2026-05-14 16:46:09

zapper
Member
Registered: 2017-05-29
Posts: 1,265  

How to swap out sound cards at will,

I want to know how to do this to use usb audio and without the following:

anything related to pulseaudio, pipewire, or other obnoxious linux frameworks.

alsa fine though.


Freedom is never more than one generation away from extinction. Feelings are not facts
If you wish to be humbled, try to exalt yourself long term  If you wish to be exalted, try to humble yourself long term
Favourite operating systems: Hyperbola Devuan OpenBSD Gnuinos
Peace Be With us All!

Offline

#2 2026-05-14 22:37:24

delgado
Member
Registered: 2022-07-14
Posts: 291  

Re: How to swap out sound cards at will,

I have 2 sound cards in my alsa only system:
The build-in analog out (used) and the digital HDMI audio (without any physical connection to make a sound).

cat /etc/asound.conf
defaults.pcm.card 1
defaults.ctl.card 1

From time to time the index of the analog out sound card changes from 0 to 1 or back (e.g. after installing a linux distribution for testing purposes). If no sound is present, the index in "asound.conf" has to be adjusted.
A third (USB-)sound card might appear as card index "2" or even mix up the order.

Not sure whether this is helpful, but anyway.

Last edited by delgado (2026-05-14 22:38:00)

Offline

#3 Yesterday 08:50:39

fsmithred
Administrator
Registered: 2016-11-25
Posts: 2,904  

Re: How to swap out sound cards at will,

Here's a script to create or change the file delgado suggested. Run it without an argument and it will display the card names and numbers and let you choose the default card. Run it with the desired card number as an argument and it will set that card as default. e.g.  set-default-card 1

Run it as root or with sudo.

$ cat set-default-card 
#!/usr/bin/env bash
#set-default-card

choose_card () {
	while true ; do
		echo "Enter the card number to set as default."
		read ans
		cardnum="$ans"
		break
	done
}

if [ "$#" -eq 0 ] ; then
	aplay -l
	choose_card
else
	cardnum="$1"
fi

echo "defaults.pcm.card $cardnum
defaults.ctl.card $cardnum" > /etc/asound.conf
/etc/init.d/alsa-utils restart

Offline

#4 Yesterday 19:42:28

zapper
Member
Registered: 2017-05-29
Posts: 1,265  

Re: How to swap out sound cards at will,

@fsmithred does this let you swap out a card whenever and also what should I call file? And where should I put it.


Freedom is never more than one generation away from extinction. Feelings are not facts
If you wish to be humbled, try to exalt yourself long term  If you wish to be exalted, try to humble yourself long term
Favourite operating systems: Hyperbola Devuan OpenBSD Gnuinos
Peace Be With us All!

Offline

#5 Today 09:37:04

fsmithred
Administrator
Registered: 2016-11-25
Posts: 2,904  

Re: How to swap out sound cards at will,

I call it set-default-card.  Put it in /usr/local/bin or somewhere else that's in root's path. Make it executable. Run it with or without the card number or with and without the usb audio device as many times as you want. It replaces the lines in asound.conf and restarts alsa so it takes effect.

Offline

#6 Today 11:53:31

ralph.ronnquist
Administrator
From: Battery Point, Tasmania, AUS
Registered: 2016-11-30
Posts: 1,657  

Re: How to swap out sound cards at will,

Note that the alsa configuration for a program is loaded only once, at program start. So a configuration change like that will be in effect for the programs started after the change (only).

There is however a "refer" element that can be used in the configuration, to be expanded upon sink creation rather than just once initially. Your configuration must include such a "refer" element in order to have a configuration change take effect within an already started program.

Offline

Board footer