You are not logged in.
Pages: 1
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
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 1From 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
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 restartOffline
@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
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
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
@ralph.ronnquist
Not sure what you mean by that refer element.
just sayin
EDIT:
I tried what he suggested and something didn't work, I don't know why.
EDIT: again, I see what happened.
I should mention my previous setup here. It also uses sndio as well and alsa-sndio:
#
# ALSA
#
# ALSA settings by default
defaults.ctl.card 0
defaults.pcm.card 0
defaults.pcm.device 0
defaults.pcm.subdevice -1
defaults.rawmidi.card 0
defaults.rawmidi.device 0
defaults.rawmidi.subdevice -1
defaults.hwdep.card 0
defaults.hwdep.device 0
defaults.timer.card 0
defaults.timer.device 0
defaults.timer.subdevice 0
#
# sndio on ALSA (alsa-sndio)
#
# Uncomment it to use sndio sound server on PCM (this requires alsa-sndio)
pcm.default sndio
# sndio PCM settings by default
defaults.pcm.sndio.device snd/0
defaults.pcm.sndio.volume 127
#defaults.pcm.sndio.playback.device snd/0
#defaults.pcm.sndio.playback.volume 127
#defaults.pcm.sndio.capture.device snd/0
# Uncomment it to use sndio sound server on RawMIDI (this requires alsa-sndio)
#rawmidi.default sndio
# sndio RawMIDI settings by default
defaults.rawmidi.sndio.device midi/0
I need all of this to stay there probably.
and the 0s to switch to 1s probably.
In this setup I notice 0 is the one that plays and 1 is the one tat doesn't.
Whichever is set to sound card 0 in alsamixer is the one that plays. If this helps let me know.
Last edited by zapper (Today 18:05:51)
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
I've changed the order of sound cards in some systems with the following lines in /etc/modprobe.d/alsa.conf (or alsa-base.conf)
options snd-usb-audio index=0
options snd-hda-intel index=-2I think it requires a reboot for the change to take effect.
Offline
Possibly something in here that might help, dunno as I don't have a usb card or a multi-card machine to test on:
#!/bin/sh
# soundswitch – Simple utility to change soundcards, part of AlsaTune.
# Copyleft greenjeans 2025. This is FREE software with NO warranty, use at your own risk!
if [ ! -f ~/.asoundrc ]; then
yad --error --title="Error" --width=400 --center --text-align=center --window-icon=error \
--text="\nNo config file (.asoundrc) found in user's home.\n\nChoose <b>Okay</b> to install a generic version,\nor choose <b>Cancel</b> to abort.\n" \
--button="Okay:0" --button="Cancel:1" --fixed
if [ $? -eq 0 ]; then
cp /usr/share/alsatune/.asoundrc ~/.asoundrc
else
exit 1
fi
fi
CARDS=$(aplay -l | grep "^card [0-9]")
CHOICE=$(echo "$CARDS" | yad --list --title="Select Sound Card" \
--column="Choose card/device" --width=550 --height=300 --window-icon=audio-speakers \
--button="Apply:0" --button="Cancel:1")
[ $? -ne 0 ] && exit 1
# Extract both card and device number from the selected line
CARD_NUM=$(echo "$CHOICE" | grep -o 'card [0-9]' | cut -d' ' -f2)
DEV_NUM=$(echo "$CHOICE" | grep -o 'device [0-9]' | head -n1 | cut -d' ' -f2)
[ -z "$DEV_NUM" ] && DEV_NUM=0 # safety net
if [ -z "$CARD_NUM" ]; then
yad --title="Error" --width=300 --center --text-align=center --window-icon=error \
--text="\nNo card was selected. Exiting..." --no-buttons --timeout=3
exit 1
fi
cp ~/.asoundrc ~/.asoundrc.bak 2>/dev/null || true
# Replace card/device number(s).
sed -i \
-e "s/hw:[0-9]*,[0-9]/hw:$CARD_NUM,$DEV_NUM/g" \
-e "s/plughw:[0-9]*,[0-9]/plughw:$CARD_NUM,$DEV_NUM/g" \
-e "s/card [0-9]/card $CARD_NUM/g" \
~/.asoundrc
yad --title="AlsaTune" --window-icon=audio-speakers --text-align=center --width=340 --center \
--text="\nNow using Card $CARD_NUM – Device $DEV_NUM\n\nConfig backed up to ~/.asoundrc.bak\n" \
--button=gtk-ok:0 --fixedhttps://sourceforge.net/projects/vuu-do/ Vuu-do GNU/Linux, Devuan-based Openbox systems.
Devuan 6 mate-mini iso, pure Devuan, 100% no-vuu-do, mostly
Please donate to support Devuan and init freedom! https://devuan.org/os/donate
https://devuanusers.com/
Offline
Pages: 1