Skip to content

Instantly share code, notes, and snippets.

@x42
Created January 2, 2014 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x42/8225136 to your computer and use it in GitHub Desktop.
Save x42/8225136 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ "$1" = '-h' -o "$1" = '--help' ]; then
me="${0##*/}"
echo "$me: list ALSA devices and relevant information."
exit 0
fi
if [ -e '/proc/asound/version' ]; then
cat '/proc/asound/version'
echo
fi
for (( i=0; i<100; i++ )); do
if [ -d "/proc/asound/card${i}" ]; then
cname="$( cat "/proc/asound/card${i}/id" )"
echo "Card ${i} (${cname}):"
for t in 'p' 'c'; do
case "$t" in
p) typeString='Playback' ;;
c) typeString='Recording' ;;
esac
for (( j=0; j<100; j++ )); do
if [ -d "/proc/asound/card${i}/pcm${j}${t}" ]; then
dname=''
if [ -e "/proc/asound/card${i}/pcm${j}${t}/info" ]; then
dname="$( grep -E '^name: ' "/proc/asound/card${i}/pcm${j}${t}/info" 2>/dev/null | cut -d ' ' -f 2- )"
fi
echo
if [ -n "$dname" ]; then
echo " * ${typeString} Device ${j} (${dname}):"
else
echo " * ${typeString} Device ${j}:"
fi
ownerPID="$( grep -E '^owner_pid' "/proc/asound/card${i}/pcm${j}${t}/sub0/status" 2>/dev/null | tr -cd '0-9' )"
if [ -n "$ownerPID" ]; then
tgid="$( grep -F 'Tgid:' "/proc/${ownerPID}/status" 2>/dev/null | tr -cd '0-9' )"
if [ -n "$tgid" ]; then
ownerPID="$tgid"
fi
ownerName="$( cat "/proc/${ownerPID}/comm" 2>/dev/null )"
echo " used by: ${ownerName} (PID ${ownerPID})"
fi
while read line; do
echo " $line"
done < "/proc/asound/card${i}/pcm${j}${t}/sub0/hw_params"
fi
done
done
echo
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment