The officially official Devuan Forum!

You are not logged in.

#1 Yesterday 16:46:09

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

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 Yesterday 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 (Yesterday 22:38:00)

Offline

#3 Today 08:50:39

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

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

Board footer