2

I want to be able to change the volume from a range of 0% to 40%. Cap it there permanently.

Sometimes depending on the program I'm running, the audio get resetted resulting in a full blast of 100% volume in my headphones.

I tried using different commands. pactl, pacmd, and sink-volume commands, but nothing came as expected.

Thanks in advance if anyone knows how to do this! Google doesn't give out any solution as I've searched a lot.

  • You mentioned the exact programs that should do you what you want. I am not sure what you mean by nothing came as expected. Perhaps you should create a script that you run when required... –  May 18 '17 at 12:58
  • I'm sorry, I don't know how to create scripts. I barely can manage commands. Those I listed are commands found, used mostly to read info about the volume/device/driver, or change the dB volume, but can't limit it permanently. –  May 18 '17 at 13:04
  • No problem, putting the proper commands in a script is no problem. It is just surprising that when you change the values with the Volume Control tool they somehow change back... Unfortunately I cannot replay your configuration as the headphones port is not working in my laptop. –  May 18 '17 at 13:15
  • No problem, I'm keep researching a little bit and the problem lies in alsamixer. PCM=100 and Front=100 are desired values. On the other side if Master goes up more than 30... starts getting really loud. I'll try to find options to limit Master. –  May 18 '17 at 13:24
  • Perhaps you can play with these settings: Increase volume by 5%

    amixer -D pulse sset Master 5%+

    Decrease volume by 5%

    amixer -D pulse sset Master 5%-

    Set volume to 50%

    amixer -D pulse sset Master 50%

    –  May 18 '17 at 13:30
  • I'm new to scripting, but the idea is to tell alsamixer if the volume is higher than 40%, then go to 40%

    function get_volume() { mixer=$(amixer get Master | egrep -o "[0-9]+%") echo number is $mixer }

    Am I in the right direction?

    –  May 18 '17 at 14:46
  • I found amixer get Master give a different output than amixer -D pulse sget Master where the separate channels are concerned. I will have a go at a script, be right back... –  May 18 '17 at 15:05
  • No problem. I'll keep on checking stuff to do. Thanks for replying!

    Some people claim that alsamixer won't save a configuration permanently, and PCM shouldn't be as high as it is (100%).

    –  May 18 '17 at 15:10
  • There are multiple workarounds, but none is as effective as this one I just found: Adjust PCM volume? –  May 18 '17 at 18:11

1 Answers1

0
#!/bin/bash
Lines=$(amixer -D pulse sget Master | grep '[0-9]%' | awk '{printf "%s\n",$5}')

set -- $Lines
lVol=$(echo "$1" | tr -cd [:digit:])
rVol=$(echo "$2" | tr -cd [:digit:])

if ((lVol>rVol))
then hVol=$lVol
else hVol=$rVol
fi

maxVol=40
if ((hVol>maxVol))
then
  echo "One or both channels too loud, setting both to $maxVol"
  amixer -D pulse sset Master ${maxVol}%
fi
# EOF #