You are not logged in.

#1 2011-07-17 09:43:35

nawitus
Member
Registered: 2009-05-11
Posts: 112

Simple mute script for softvol [ALSA]

I noticed that mute is not supported for softvol mixers in ALSA, so I made a simple script to emulate muting. The volume level is stored in volume.txt. I hope somebody finds this useful! This script changes the Master mixer by default.

mute.sh:

#!/bin/bash
var=$(amixer get Master | grep "Front Left:")
var=$(echo "$var" | sed -ne 's/^[^[]*\[\([^]]*\)\].*/\1/p')
if [ $var == "0%" ]
then
        volume=`cat volume.txt`
        amixer set 'Master' $volume
else
        rm volume.txt
        echo $var > volume.txt
        amixer set 'Master' 0%
fi

You can bind it to mute hotkey for example with xbindkeys:
.xbindkeysrc:

#Mute
"/media/disk/programs/mute.sh"
    m:0x0 + c:121
    XF86AudioMute

(Change the file path accordingly)

Offline

#2 2011-07-17 22:43:32

kachelaqa
Member
Registered: 2010-09-26
Posts: 216

Re: Simple mute script for softvol [ALSA]

nawitus wrote:

mute.sh:

#!/bin/bash
var=$(amixer get Master | grep "Front Left:")
var=$(echo "$var" | sed -ne 's/^[^[]*\[\([^]]*\)\].*/\1/p')
if [ $var == "0%" ]
then
        volume=`cat volume.txt`
        amixer set 'Master' $volume
else
        rm volume.txt
        echo $var > volume.txt
        amixer set 'Master' 0%
fi

nice idea, but there is a simple one-liner for this:

amixer -c0 sset Master toggle

or perhaps:

amixer -c0 sset Headphone toggle

Offline

#3 2011-07-17 23:22:34

nawitus
Member
Registered: 2009-05-11
Posts: 112

Re: Simple mute script for softvol [ALSA]

That doesn't work for me.

Offline

#4 2011-07-18 01:17:00

kachelaqa
Member
Registered: 2010-09-26
Posts: 216

Re: Simple mute script for softvol [ALSA]

nawitus wrote:

That doesn't work for me.

you probably just need to tweak the options slightly. the toggle command simply switches playback off and on for a given control, so you just need to find the control that works on your system.

you can list the controls like this:

$ amixer scontrols
Simple mixer control 'Master',0
Simple mixer control 'Headphone',0
Simple mixer control 'PCM',0
Simple mixer control 'Front',0
...

on my system, only 'Master' and 'Front' can be used to mute the sound - but every system will differ slightly.

maybe something like this will work for you:

amixer set Front toggle

Offline

#5 2011-07-18 09:27:47

nawitus
Member
Registered: 2009-05-11
Posts: 112

Re: Simple mute script for softvol [ALSA]

"on my system, only 'Master' and 'Front' can be used to mute the sound"

Well, that's the main problem, my Master mixer cannot be muted, probably because it's a softvol plugin, not a normal hardware mixer. That's why I created this script.

Offline

#6 2011-07-18 10:37:20

kachelaqa
Member
Registered: 2010-09-26
Posts: 216

Re: Simple mute script for softvol [ALSA]

nawitus wrote:

my Master mixer cannot be muted, probably because it's a softvol plugin, not a normal hardware mixer.

somehow i managed to completely miss that - despite you putting it right there in the subject smile

Offline

Board footer

Powered by FluxBB