You are not logged in.
Pages: 1
So this is another tiny utility to be added to the toolbox for AlsaTune or other interface, for use in a pure alsa system. This is just the rough prototype, I need to do more testing, and more thinking about possible errors and edge-cases and dealing with them.
It would be great if someone with multiple cards could test, I only have one machine that has two cards and I have tested on it and all the single-card machines and this works fine so far. Curious about systems with more cards and those with sub-devices, and also other possible areas to edit that aren't in my config (you can see in the script it changes for hw, plughw, and card).
This works by merely editing ~/.asoundrc, it uses aplay to get the card list, then seds your choice into the config file. It doesn't require re-booting or even re-loading alsa, you just need to close and re-open any running sound instances like your music player after editing is complete. It also creates a backup of your old config, but for testing purposes you should definitely backup whatever you have now for an .asoundrc.
#!/bin/bash
# soundswitch - simple card switcher for AlsaTune that mods ~/.asoundrc
# TO-DO: deal with subdevices? Any other prefixes common in larger asound files
# (like card, hw, or plughw below) that need added?
CARDS=$(aplay -l | grep "^card [0-9]")
CHOICE=$(echo "$CARDS" | yad --list --title="Select Sound Card" \
--column="Card" --width=550 --height=200 --window-icon=info --button="Apply:0" --button="Cancel:1")
[ $? -ne 0 ] && exit 1
CARD_NUM=$(echo "$CHOICE" | cut -d'|' -f1 | grep -o -E '[0-9]' | head -n 1)
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=4
exit 1
fi
# Backup
cp ~/.asoundrc ~/.asoundrc.bak
# Replace all card #'s with new card #'s
sed -i "s/hw:[0-9],/hw:$CARD_NUM,/g; s/plughw:[0-9],/plughw:$CARD_NUM,/g; s/card [0-9]/card $CARD_NUM/g" ~/.asoundrc
yad --window-icon=info --text-align=center --width=300 --center --title="Sound" \
--text="\nSound card switched to Card $CARD_NUM\n\nConfig backed up to ~/.asoundrc.bak" --button=gtk-ok:0https://sourceforge.net/projects/vuu-do/ New Vuu-do isos uploaded October 2025!
Vuu-do GNU/Linux, minimal Devuan-based Openbox and Mate systems to build on. Also a max version for OB.
Devuan 5 mate-mini iso, pure Devuan, 100% no-vuu-do.
Devuan 6 version also available for testing.
Please donate to support Devuan and init freedom! https://devuan.org/os/donate
Offline
@greenjeans, like'ish your script...wont work for me, running a corner-case here ![]()
Suggestions...
Have a default when 'sed' fails/ .asoundrc is empty ore doesn't exist.
Have the window size itself to the number of entries in the list (its annoying to have to keep resizing to make a selection).
Offline
^^Much appreciated!
No .asoundrc is a case, at the start of this endeavour I am writing this to be included in AlsaTune/Vuu-do which will already have an .asoundrc in the system, but like other things I want to also make a generic/portable version that can be used anywhere so that's the next target for functionality.
Window-size: How many cards are in your list? I had envisioned entries for just a couple, can you elaborate? Do I need a scroll function?
https://sourceforge.net/projects/vuu-do/ New Vuu-do isos uploaded October 2025!
Vuu-do GNU/Linux, minimal Devuan-based Openbox and Mate systems to build on. Also a max version for OB.
Devuan 5 mate-mini iso, pure Devuan, 100% no-vuu-do.
Devuan 6 version also available for testing.
Please donate to support Devuan and init freedom! https://devuan.org/os/donate
Offline
Window-size: 11 Lines (four of those are for the GPU alone)
So for a Twin GPU system that could be eight just to start with.
I suppose a scrollbar would cover all bases, don't want to push you to loose the KISS aspect though.
Offline
Ummm, GPU? Ya lost me there somewhere...
https://sourceforge.net/projects/vuu-do/ New Vuu-do isos uploaded October 2025!
Vuu-do GNU/Linux, minimal Devuan-based Openbox and Mate systems to build on. Also a max version for OB.
Devuan 5 mate-mini iso, pure Devuan, 100% no-vuu-do.
Devuan 6 version also available for testing.
Please donate to support Devuan and init freedom! https://devuan.org/os/donate
Offline
Ummm, GPU?
Outputs are capable of carrying digital sound as well as video, so consequently show up in ALSA as individual sink devices.
ls -ld /proc/asound/card1/pcm*
dr-xr-xr-x 4 root root 0 Nov 18 13:07 /proc/asound/card1/pcm3p
dr-xr-xr-x 4 root root 0 Nov 18 13:07 /proc/asound/card1/pcm7p
dr-xr-xr-x 4 root root 0 Nov 18 13:07 /proc/asound/card1/pcm8p
dr-xr-xr-x 4 root root 0 Nov 18 13:07 /proc/asound/card1/pcm9pLast edited by g4sra (2025-11-18 13:10:27)
Offline
Ahh I gotcha, and that's the kind of thing I need to know to proceed, problem is I don't have a machine around here to test, I get one line on my single-card lappy, two on the library machine...without having a complex machine with multiple outputs around to test on it's gonna make it really hard for me to extend this script. I kinda need to see what things are doing, my methods involve a lot of trial-and-error.
Basic philosophy/use-case is for Vuu-do as it already has a working alsa system, and is meant for simple everyday garden-variety use, just a quick switch for those machines that have an analog and an HDMI output as most of the time the dual-setups default to HDMI as card 0.
At least at this stage...baby steps...but i'd like to pursue it and figure out all the edge-cases and sub-devices and such so I can package it with AT for general use at some point.
https://sourceforge.net/projects/vuu-do/ New Vuu-do isos uploaded October 2025!
Vuu-do GNU/Linux, minimal Devuan-based Openbox and Mate systems to build on. Also a max version for OB.
Devuan 5 mate-mini iso, pure Devuan, 100% no-vuu-do.
Devuan 6 version also available for testing.
Please donate to support Devuan and init freedom! https://devuan.org/os/donate
Offline
a lot of trial-and-error
With the work you put in for the benefit of others I judge that you are entitled to use the computer science term for that, stepwise refinement ![]()
i'd like to pursue it and figure out all the edge-cases
I don't mind throwing it at my workstation on occasion and reporting back, I guarantee it is an edge case, my /etc/asound.conf contains 724 lines.
Offline
Hah, I love it...yep...Vuu-do Linux, handcrafted using stepwise refinement and multi-solutional iterations (hit-or-miss). ![]()
Thanks for the help, I really appreciate it and at some point i'll take you up on the offer to test the next version.
724 lines in asound.conf? Holy crap, that's epic! Yeah I can see where my little script probably wouldn't be good for that system, but it's a dang fine one for testing the limits of it for sure.
https://sourceforge.net/projects/vuu-do/ New Vuu-do isos uploaded October 2025!
Vuu-do GNU/Linux, minimal Devuan-based Openbox and Mate systems to build on. Also a max version for OB.
Devuan 5 mate-mini iso, pure Devuan, 100% no-vuu-do.
Devuan 6 version also available for testing.
Please donate to support Devuan and init freedom! https://devuan.org/os/donate
Offline
Yeah...so it seems there's no scroll function or auto-sizing for the yad list dialog, at least not in the old versions being used in the repo. For the moment I added a little height. arrgh.
I added an error check to look for ~/.asoundrc right at the start and exit if there isn't one. But now i'm thinking in the error message to also add the ability to copy a simple .asoundrc (to be shipped with the mxeq/AT package) to the users home if there isn't one, and then continuing (or hit cancel to back out of course).
I'll be modding AT a fair bit to add a button for the card-switcher and some other functions including a button to test sound, using aplay to play a .wav file I made, just 3 seconds of a 500hz note, the idea being you can test whatever changes you made with the card-switcher right there in the gui after doing it, without having to cycle audio/video apps on and off.
https://sourceforge.net/projects/vuu-do/ New Vuu-do isos uploaded October 2025!
Vuu-do GNU/Linux, minimal Devuan-based Openbox and Mate systems to build on. Also a max version for OB.
Devuan 5 mate-mini iso, pure Devuan, 100% no-vuu-do.
Devuan 6 version also available for testing.
Please donate to support Devuan and init freedom! https://devuan.org/os/donate
Offline
Pages: 1