I need to fix and maintain the master volume in PulseAudio (so that I don't blow up my speakers). E.g. call gfaaudio -v 25
to fix volume at 25%. Is there a cleaner way to get this done?
gfaaudio:
#!/bin/bash
usage="Usage: `basename $0` [-v VOL] "
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo $usage
echo " -h, --help for help"
exit
fi
#############################
Dcard="alsa_card.usb-Musical_Fidelity_Musical_Fidelity_V90-DAC_24_96-00-M2496"
Dout="iec958-stereo"
Dname="alsa_output.usb-Musical_Fidelity_Musical_Fidelity_V90-DAC_24_96-00-M2496.iec958-stereo"
VOL=30
#############################
while [ $# -gt 0 ]; do
case "$1" in
-v)
shift
[ $# -gt 0 ] && VOL="$1";;
-*)
echo "Option not supported: $1" >&2
echo $usage >&2
exit 1;;
*) break;;
esac
shift
done
pacmd set-card-profile "$Dcard" output:"$Dout"
pacmd set-default-sink "$Dname"
[ -z "$(pidof -x gfaaudioloop)" ] || killall gfaaudioloop
gfaaudioloop "$Dname" "$VOL" &
exit
gfaaudioloop:
#!/bin/bash
if [[ $# != 2 ]]; then
echo "number of arguments not 2" >&2
exit 1
fi
while : ; do
exits=$(pactl set-sink-volume "$1" "$2"%)
exitc=$?
[ ! -z "$exits" -o $exitc -ne 0 ] && break
sleep 0.5
done
exit