Configure alsa automatically


#1

Bspwm-minimal uses plain alsa instead of pulseaudio. This is sometimes irritating, because my test system is a laptop where alsa does not work out of the box. The default sound cart is set to hdmi even though there are no hdmi devices connected. And I suck at configuring alsa.

After some digging, I found out how to set the default sound card to something that actually makes sound. However, the configuration is obviously not portable. I would like to automate this configuration for new installations.

Anybody got ideas on how to do this?


Replacing Pulseaudio with Alsa
#2
#!/usr/bin/env bash

for card in $(awk '/ \[/ {print $1}' /proc/asound/cards); do
	if amixer -c $card get Master &> /dev/null; then
		working_card="$card"
		break
	fi
done

[[ -n $working_card ]] && echo "defaults.pcm.card $working_card
defaults.ctl.card $working_card" > ~/.asoundrc

I put this in the autostart, seems to work okay. Anyone got ideas for improvements?


#3

Some ideas:

  • bash is not needed, convert to das for faster execution
  • if sound is working, do nothing
  • trigger it from volume script if sound is not working
  • autostart it from limepanel

#4

@oberon I recall that you had a script in i3 edition. Would this be a useful addition to it?


#5

set defaults in /etc/asound.conf ?
(normally set to default to Pulseaudio with other DE’s)

https://alsa.opensrc.org/MultipleCards


#6

How would that work in practice? I don’t know what hardware user has or how his cards are ordered or named, or which device he wants to use, so I don’t see how I could use a static configuration file.


#7

it would have to be fix for users that have similar card configuration

cat /proc/asound/cards
or
aplay -l + arecord -l
to get card numbers

then most of the time would be:

Have to do post-install configuration in other DEs where HDMI grabs default too


#8

What we have currently in i3 is simply scripts to install and remove pulse :slight_smile:


#9

I know. I was thinking, if someone is removing pulseaudio, would it be good to automatically configure alsa so that they don’t lose sound if their system is weird like mine?


#10

As we all know, many people (apart from ourselves) can have trouble getting sound (for various reasons).

For those of us that prefer not to use PA, having a little script that we could run that removes PA (if it exists) & then makes the right settings for ALSA would be a real blessing (& sometimes quite a time saver too).

I do hope that such a script comes out of your work @Chrysostomus.

If such a script is born, I expect that it would make its way in to a number of other distros that prefer not to use PA, too. :slight_smile:


#11

Sure, I can do that now that I have the parts. Just add a few uninstall commands and make it a bit more verbose.