Gentoo Forums
Gentoo Forums
Quick Search: in
Command to alter volumes?
View unanswered posts
View posts from last 24 hours

rackathon
 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
Aynjell
Veteran
Veteran


Joined: 28 Jun 2004
Posts: 1116

PostPosted: Fri Oct 28, 2005 10:18 pm    Post subject: Command to alter volumes? Reply with quote

Is there a command that can be used to alter volumes? I need to be able to alter the volume entirely with a single command. No fudging with a UI, just something like:

<command> <device> <mixer> -5
or
<command> <device> <mixer> +5

Mainly, so I can bind commands to alter volumes. Using stuff like kmix is always a painful process.
_________________
CPU: 3800+ X2 (2.5Ghz)
GPU: eVGA 7600GT (640/1700)
MOBO: DFI SLI-DR (Surprisingly good!)
RAM: 2 x OCZ Gold 1024 DDR500 3-4-3-7 (2048)
HDD: Western Digital Raptor
Back to top
View user's profile Send private message
yabbadabbadont
Veteran
Veteran


Joined: 13 Mar 2003
Posts: 4311
Location: Ozark Plateau

PostPosted: Fri Oct 28, 2005 11:17 pm    Post subject: Reply with quote

setmixer

smixer

cmix

I think all of these will do what you want.
Back to top
View user's profile Send private message
Aynjell
Veteran
Veteran


Joined: 28 Jun 2004
Posts: 1116

PostPosted: Fri Oct 28, 2005 11:20 pm    Post subject: Reply with quote

Awesome, I appreciate the response. if it works, kudos, man!
_________________
CPU: 3800+ X2 (2.5Ghz)
GPU: eVGA 7600GT (640/1700)
MOBO: DFI SLI-DR (Surprisingly good!)
RAM: 2 x OCZ Gold 1024 DDR500 3-4-3-7 (2048)
HDD: Western Digital Raptor
Back to top
View user's profile Send private message
ppurka
Veteran
Veteran


Joined: 26 Dec 2004
Posts: 1124

PostPosted: Sat Oct 29, 2005 3:36 am    Post subject: Reply with quote

If you are using alsa then try something similar:
Code:
amixer sset 'PCM' 2%+
amixer sset 'PCM' 2%-
amixer sset 'PCM' mute
amixer sset 'PCM' unmute
You could have other options such as 'Surround', 'Center', 'LFE', etc. instead of 'PCM'.

amixer is provided by the alsa-utils package, i think.
Back to top
View user's profile Send private message
Aynjell
Veteran
Veteran


Joined: 28 Jun 2004
Posts: 1116

PostPosted: Sat Oct 29, 2005 12:40 pm    Post subject: Reply with quote

ppurka, I love you.
_________________
CPU: 3800+ X2 (2.5Ghz)
GPU: eVGA 7600GT (640/1700)
MOBO: DFI SLI-DR (Surprisingly good!)
RAM: 2 x OCZ Gold 1024 DDR500 3-4-3-7 (2048)
HDD: Western Digital Raptor
Back to top
View user's profile Send private message
ppurka
Veteran
Veteran


Joined: 26 Dec 2004
Posts: 1124

PostPosted: Sat Oct 29, 2005 4:20 pm    Post subject: Reply with quote

Aynjell wrote:
ppurka, I love you.
:lol:
Back to top
View user's profile Send private message
Aynjell
Veteran
Veteran


Joined: 28 Jun 2004
Posts: 1116

PostPosted: Sat Oct 29, 2005 4:29 pm    Post subject: Reply with quote

Hrm, not much of a script writer, but is there a way to check if it's muted, and if it is, unmute it, otherwise just mute? So I can apply that to my mute key. Going through kmix can be painful. :(
_________________
CPU: 3800+ X2 (2.5Ghz)
GPU: eVGA 7600GT (640/1700)
MOBO: DFI SLI-DR (Surprisingly good!)
RAM: 2 x OCZ Gold 1024 DDR500 3-4-3-7 (2048)
HDD: Western Digital Raptor
Back to top
View user's profile Send private message
yabbadabbadont
Veteran
Veteran


Joined: 13 Mar 2003
Posts: 4311
Location: Ozark Plateau

PostPosted: Sat Oct 29, 2005 5:20 pm    Post subject: Reply with quote

Code:
/home/yoiks $ amixer get PCM | grep -q "\[on\]"
/home/yoiks $ echo $?
0


This is if the PCM device is unmuted. The exit status ($?) will be 1 if it is muted.
Back to top
View user's profile Send private message
yabbadabbadont
Veteran
Veteran


Joined: 13 Mar 2003
Posts: 4311
Location: Ozark Plateau

PostPosted: Sat Oct 29, 2005 5:24 pm    Post subject: Reply with quote

Code:
if amixer get PCM | grep -q "\[on\]"; then
    amixer sset 'PCM' mute
else
    amixer sset 'PCM' unmute
fi


This will toggle the muted state of the specified simple device.

EDIT: change the amixer sset commands to amixer -q sset if you don't want to see any console output. Don't change the line in the if statement though.
Back to top
View user's profile Send private message
ppurka
Veteran
Veteran


Joined: 26 Dec 2004
Posts: 1124

PostPosted: Sat Oct 29, 2005 8:42 pm    Post subject: Reply with quote

This is a script I use when I use alsa (currently I am using nvsound driver). The way to use it is:
Code:
volmute increase    --- to increase volume
volmute decrease    --- to decrease volume
volmute mute    --- to mute/unmute


The script:
Code:
#!/bin/bash
volsetting=`amixer sget 'PCM' | grep off`
    case "$1" in
    mute)
        if [[ x"$volsetting" = x"" ]]; then
            amixer sset 'PCM' mute
            amixer sset 'Surround' mute
            amixer sset 'Center' mute
            amixer sset 'LFE' mute
        else
            amixer sset 'PCM' unmute
            amixer sset 'Surround' unmute
            amixer sset 'Center' unmute
            amixer sset 'LFE' unmute
        fi
    ;;
    increase)
        amixer sset 'PCM' 2%+
        amixer sset 'Surround' 2%+
        amixer sset 'Center' 2%+
        amixer sset 'LFE' 2%+
    ;;
    decrease)
        amixer sset 'PCM' 2%-
        amixer sset 'Surround' 2%-
        amixer sset 'Center' 2%-
        amixer sset 'LFE' 2%-
    ;;
    *)
        echo "This is not an acceptable command!";
        echo -e "Use \033[01;33mmute\033[01;00;0m, \033[01;33mincrease\033[01;00;0m or \033[01;33mdecrease\033[01;00;0m as options!";
        echo;
    esac
Back to top
View user's profile Send private message
djlosch
n00b
n00b


Joined: 27 Aug 2005
Posts: 67

PostPosted: Tue Nov 01, 2005 1:12 am    Post subject: Reply with quote

awesome script! thanks!
_________________
I'm not your attorney. This post isn't legal advice. Always consult an attorney licensed to practice in your jurisdiction.
tapthehive - fakebillgates
Back to top
View user's profile Send private message
mnxAlpha
Apprentice
Apprentice


Joined: 14 Sep 2004
Posts: 210

PostPosted: Tue Nov 01, 2005 1:28 am    Post subject: Reply with quote

Possibly a simpler way. Kmix has an option somewhere to set global keyboard shortcuts. I can't check exactly where that is at the moment, because I'm in Gnome, but it's there somewhere. I think you right-click on the master volume slider and select "Global Shortcuts" or something like that. I had it set up using the volume up / down and mute buttons on my keyboard, but it works with normal keys and modifiers. Gnome has a similar option, configured from the keyboard options applet.
Back to top
View user's profile Send private message
soroh6
Apprentice
Apprentice


Joined: 06 Nov 2002
Posts: 227

PostPosted: Sat Jul 07, 2007 12:33 am    Post subject: Reply with quote

I guess this is terribly old thread, but that script above is working great for me :)

Code:
#!/bin/bash
volsetting=`amixer sget 'PCM' | grep off`
case "$1" in
        *)
        if [[ x"$volsetting" = x"" ]]; then
                amixer -q sset 'Master' mute
                amixer -q sset 'PCM' mute
                amixer -q sset 'Surround' mute
                amixer -q sset 'Center' mute
                amixer -q sset 'LFE' mute
        else
                amixer -q sset 'Master' unmute
                amixer -q sset 'PCM' unmute
                amixer -q sset 'Surround' unmute
                amixer -q sset 'Center' unmute
                amixer -q sset 'LFE' unmute
        fi
esac

I just needed the mute version of it for hotkeys, so I modified it to only do muting. :) Maybe this bump will be useful to someone else. Also added the -q's so theres no output.
_________________
:: soroh -*~
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum