Steve Litt via plug on 26 Jun 2023 22:23:23 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[PLUG] ALSA hassle workaround: was Red Hat cutting back RHEL source availability


Rich Freeman via plug said on Mon, 26 Jun 2023 06:34:06 -0400

>Really though some of my main linux frustrations are with things that
>DON'T use udev, like ALSA devices.  I can't ensure they have
>consistent numbers/etc as all the flexibility of udev rules doesn't
>apply to them.

I have these alsa-numbers problems whenever I reboot or accidentally
disconnect my usb video card. This is a real problem because I use
Jitsi extensively and need to troubleshoot sound problems withing
seconds, not minutes. So I made two shellscripts. The first one, called
quickalsa.sh, which must be run from your home directory, follows:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
cp -p .asoundrc asoundrc.bup
echo '' >> .asoundrc
echo '' >> .asoundrc

echo '# WARNING: Must change card number in both' >> .asoundrc
echo '#  ~/.asoundrc and /d/bats/alsa.sh !!!!!' >> .asoundrc
echo '#  Use Vim :bn, which is next buffer,' >> .asoundrc
echo '#  to access alsa.sh!!!!!' >> .asoundrc
echo '#  The -c arg in alsa.sh is the card num!!!!!' >> .asoundrc

echo '' >> .asoundrc

echo '#========================================================' >>
.asoundrc cat /proc/asound/cards | sed -e's/^/#/' >> .asoundrc
echo '#========================================================' >>
.asoundrc

echo '' >> .asoundrc
echo '# Delete this comment and stuff between equal signs when done
troubleshooting.' >> .asoundrc

gvim .asoundrc /d/bats/alsa.sh
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

As you can see, three lines wrapped because of email, but it's pretty
obvious which three.

The preceding shellscript calls /d/bats/alsa.sh. Obviously /d/bats must
be changed to wherever alsa.sh resides. alsa.sh follows:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#!/bin/sh


# CRITICAL!!!  Change number after -c to match card number
lxterminal -e "alsamixer -c 0 -V playback"
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Last but not least, the following .asoundrc is the starting point:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# CRITICAL!!!    For "hw:num:othernum" in slave, match num to card number 
# CRITICAL!!!    See comments at bottom for readout of card numbers

pcm.!default {
	# Must be type plug
	type plug
	slave.pcm "my_arbitrary_name"
}

pcm.my_arbitrary_name  {
	# Must be type dmix
 	type dmix
	# Must be ipc_key 1024, I don't know why
 	ipc_key 1024
 	slave {
		# Card comma device. Device is probably 0
		# Preceding numbers are what needs to change
		# If your card order changes.
		# cat /proc/asound/cards for list
		pcm "hw:0,0"

		# Following stuff probably unnecessary, possibly
		harmful, #     but might help with certain songs
		#period_time 0
		#period_size 1024
		#buffer_size 4096
		#rate 44100
	}
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Now just run the quickalsa.sh shellscript, and follow the directions.

By the way, this thing can be made more robust by creating a template
.asoundrc and having quickalsa.sh copy that to .asoundrc after backing
up the current .asoundrc to asoundrc.bup.

SteveT

Steve Litt 
Autumn 2022 featured book: Thriving in Tough Times
http://www.troubleshooters.com/bookstore/thrive.htm
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug