#!/bin/bash # Set the MIXER_NORM_CONTROL to the name of the ALSA control you want to use to # "normalize" all control values. This value is used to determine the current # volume before calculating the desired new volume, so using a control with # high resolution allow you to use small volume adjustments without "getting # stuck." # If, for example, you're using a volume change that's less than # 100/resolution, the volume will stick at the point where changing the control # value by one results in a greater percentage change (after rounding) than # requested. # Note that PCM controls often have a resolution of 30, whereas Center, # Surround, and LFE may have a resolution of 100. MIXER_NORM_CONTROL=PCM #MIXER_NORM_CONTROL=Center # Set the MIXER_ADJ_AMOUNT to the desired percentage by which you want to # adjust the volume. Note that if using a control whose resolution is less than # 100, the MIXER_ADJ_AMOUNT should be approximately 100/resolution or greater # (i.e. for a PCM control with a resolution of 30, use 3 or higher) to prevent # "getting stuck" at any particular volume. MIXER_ADJ_AMOUNT=3 # Set the VOLUME_CONTROLS to the space separated list of volume controls you # want the script to adjust. Use single quotes around the list. VOLUME_CONTROLS='PCM Surround Center LFE' # Set the BROADCAST_ADDRESS to the address of the frontend on which you want to # display the volume OSD. Using 127.0.0.1 will generally work. BROADCAST_ADDRESS='127.0.0.1' # Relies on amixer reporting volume in the format "[90%]" in any line of output # Please test that your version of amixer does this or you may blow out your # speakers. VOLUME=`amixer sget $MIXER_NORM_CONTROL | awk '/[.*%]/ {split($0,a,"["); split(a[2],a,"%"); print a[1]; exit}'` case "$1" in up|down) if [ $1 = "down" ]; then MIXER_ADJ_AMOUNT=-$MIXER_ADJ_AMOUNT fi NEW_VOLUME="$(($VOLUME + $MIXER_ADJ_AMOUNT))" if [ $NEW_VOLUME -lt 0 ]; then NEW_VOLUME=0 elif [ $NEW_VOLUME -gt 100 ]; then NEW_VOLUME=100 fi mythtvosd --bcastaddr="$BROADCAST_ADDRESS" \ --template='alert' \ --alert_text="Volume: ${NEW_VOLUME}%" > /dev/null 2>&1 & for control in $VOLUME_CONTROLS; do amixer -q set $control ${NEW_VOLUME}% & done ;; mute|unmute) mythtvosd --bcastaddr="$BROADCAST_ADDRESS" \ --template='alert' --alert_text="$1" > /dev/null 2>&1 & for control in $VOLUME_CONTROLS; do amixer -q set $control $1 & done ;; *) echo "Usage: $0 {up|down|mute|unmute}" ;; esac