2014-03-01 53 views
0

我是using this script通過keybindigs更改pulseaudio中的音量,但它具有0%100%的限制。如何允許脈衝音頻腳本通過bash增加音量超過100%

由於pulseaudio允許音量增加超過100%(我的筆記本電腦仍然很低),我想調整它以允許最大音量爲140%150%

請注意,只要評論行105 ~ 111腳本的工作原理或那個,但沒有限制值(什麼可以破壞我的揚聲器)。我真正想要的是設置一個可配置的限制100%

這是,實際上,更多bash問題比pulseaudio

Gist with the complete script

回答

0

我設法改變它通過添加一個新的變量和一些數學。

OVERMAX值(調整到所需的最大百分比)用於設置新的百分比值。所以130%變成100%

#!/bin/sh 
# pulsevol.sh 
# PulseAudio Volume Control Script 
# Original 2010-05-20 - Gary Hetzel <[email protected]> 
#  
# Modified 2010-10-18 by Fisslefink <[email protected]> 
# - Added support for multiple sinks and Ubuntu libnotify OSD 
# 
# Usage: pulsevol.sh [sink_index] [up|down|min|max|overmax|toggle|mute|unmute] 
# 

EXPECTED_ARGS=2 
E_BADARGS=65 

if [ $# -ne $EXPECTED_ARGS ] 
then 
    echo "Usage: `basename $0` [sink_index] [up|down|min|max|overmax|toggle|mute|unmute]" 
    exit $E_BADARGS 
fi 

SINK=$1 
STEP=5 
MAXVOL=65537 # let's just assume this is the same all over 
#MAXVOL=`pacmd list-sinks | grep "volume steps" | cut -d: -f2 | tr -d "[:space:]"` 
OVERMAX=130 # how much the volume can raise over 100% 

getperc(){ 
    VOLPERC=`pacmd list-sinks | grep "volume" | head -n1 | cut -d: -f3 | cut -d% -f1 | tr -d "[:space:]"` 
} 

getperc; 

up(){ 
    VOLSTEP="$(($VOLPERC+$STEP))"; 
} 

down(){ 
    VOLSTEP="$(($VOLPERC-$STEP))"; 
} 

max(){ 
    pacmd set-sink-volume $SINK $MAXVOL > /dev/null 
} 

min(){ 
    pacmd set-sink-volume $SINK 0 > /dev/null 
} 

overmax(){ 
    SKIPOVERCHECK=1 
    if [ $VOLPERC -lt 100 ]; then 
     max; 
     exit 0; 
    fi 
    up 
} 

mute(){ 
    pacmd set-sink-mute $SINK 1 > /dev/null 
    notify-send " " -i "notification-audio-volume-muted" -h int:value:0 -h string:synchronous:volume 
} 

unmute(){ 
    VOLSTEP="$(($VOLPERC-0))"; 
    SKIPOVERCHECK=1 
    pacmd set-sink-mute $SINK 0 > /dev/null 
} 

toggle(){ 
    M=`pacmd list-sinks | grep "muted" | cut -d: -f2 | tr -d "[:space:]"` 
    if [ "$M" = "no" ]; then 
     mute 
     exit 0; 
    else 
     unmute; 
    fi 
} 

case $2 in 
up) 
    up;; 
down) 
    down;; 
max) 
    max 
    exit 0;; 
min) 
    min 
    exit 0;; 
overmax) 
    overmax;; 
toggle) 
    toggle;; 
mute) 
    mute; 
    exit 0;; 
unmute) 
    unmute;; 
*) 
    echo "Usage: `basename $0` [sink_index] [up|down|min|max|overmax|toggle|mute|unmute]" 
    exit 1;; 
esac 

VOLUME="$((($MAXVOL/100) * $VOLSTEP))" 
MAXCHECK="$(($MAXVOL * $OVERMAX/100 ))" 

if [ -z $SKIPOVERCHECK ]; then 
    if [ $VOLUME -gt $MAXCHECK ]; then 
     VOLUME=$MAXCHECK 
    elif [ $VOLUME -lt 0 ]; then 
     VOLUME=0 
    fi 
fi 

pacmd set-sink-volume $SINK $VOLUME > /dev/null 

VOLPERC=`pacmd list-sinks | grep "volume" | head -n1 | cut -d: -f3 | cut -d% -f1 | tr -d "[:space:]"` 
VOLPERC="$(($VOLPERC * 100/$OVERMAX))" 

if [ "$VOLPERC" = "0" ]; then 
     icon_name="notification-audio-volume-off" 
    else 
     if [ "$VOLPERC" -lt "33" ]; then 
      icon_name="notification-audio-volume-low" 
     else 
      if [ "$VOLPERC" -lt "67" ]; then 
       icon_name="notification-audio-volume-medium" 
      else 
       icon_name="notification-audio-volume-high" 
      fi 
     fi 
fi 

notify-send " " -i $icon_name -h int:value:$VOLPERC -h string:synchronous:volume 

要點:https://gist.github.com/paulodiovani/67906a5bf0392de51eca

0

只是增加MAXVOL喜歡的東西100000(其初始值的150%,65537)。

+0

它不工作。任何超過65537的MAXVOL值都會導致VOLSTEP超過100%,計算VOLUME時會增加很多。這種方式容易超過200%,不能降低。 – paulodiovani