Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
script to conveniently set ALSA volume
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
TheEternalVortex
Apprentice
Apprentice


Joined: 15 Oct 2002
Posts: 207
Location: San Jose, CA

PostPosted: Thu Jan 22, 2004 4:26 am    Post subject: script to conveniently set ALSA volume Reply with quote

I made this cool script a while ago, and thought I'd post it here. It's an interface to amixer (so you'll need that installed), and I find it a much easier way to getting/setting volume that that program. For instance I use it to set key bindings in fvwm or to quickly get the current volume. It's written in perl.

Update:
volume is now at version 1.5.1, and I've added an "unmute" and an "automute" feature. It's now also possible to use a different maximum (instead of 100), so that you can set it so the volume can't go higher than a certain point. I fixed a lot of bugs too (mainly dealing with weird user input).

I'd like some people to test it out, as there are probably some bugs present from all the stuff added. So for now it is in beta.

Some samples (updated with new 1.5 features):
Code:

$ volume --help
Usage: volume [OPTION]... COMMAND [VALUE]
Sets ALSA volume.

Commands:
    set        sets the volume to VALUE %
    up         increases volume by VALUE %
    down       decreases volume by VALUE %
    mute       sets volume to 0
    unmute     restores previous volume
    automute   either mutes or unmutes the volume
    max        sets volume to maximum
    current    prints the current volume

Options:
    --help     print this help
    --quiet    does not print any output
    --max=N    uses N as the maximum instead of 100
    --version  print version information

$ volume current
Current volume: 70%
$ volume up 10
Volume changed from 70% to 80%.

$ volume mute
Volume changed from 80% to 0%.

$ volume max
Volume changed from 0% to 100%.

$ volume 67
Volume changed from 100% to 67%.

$ volume automute
Volume changed from 67% to 0%.
$ volume automute
Volume changed from 0% to 67%.

$ volume --max=80 max
Volume changed from 74% to 80%.


Download it here.

Note: If you get any errors you might have to emerge Getopt-Long, although I believe it should come by default.
_________________
-- Andy


Last edited by TheEternalVortex on Fri Jan 30, 2004 1:22 am; edited 2 times in total
Back to top
View user's profile Send private message
TheEternalVortex
Apprentice
Apprentice


Joined: 15 Oct 2002
Posts: 207
Location: San Jose, CA

PostPosted: Sat Jan 24, 2004 10:56 pm    Post subject: Reply with quote

So does anyone have any comments/suggestions, perhaps?
_________________
-- Andy
Back to top
View user's profile Send private message
Moled
l33t
l33t


Joined: 09 Jul 2003
Posts: 635

PostPosted: Sun Jan 25, 2004 12:37 am    Post subject: Reply with quote

tried gnome-alsamixer
?
Back to top
View user's profile Send private message
Andersson
Guru
Guru


Joined: 12 Jul 2003
Posts: 525
Location: Göteborg, Sweden

PostPosted: Sun Jan 25, 2004 11:54 am    Post subject: Reply with quote

TheEternalVortex wrote:
So does anyone have any comments/suggestions, perhaps?

Yes, a few things. You know what would make this a killer app? A command to toggle mute. For all of us who have a mute button on the keyboard. ;) I guess that would need an environment variable to remember the last volume.

I've also missed the option to set a maximum volume other than 100% (since my sound card sounds crappy when I go above 90-something %).

Also, when using up / down, it's not always precise. It doesn't really matter, who can hear the difference between 73% and 74% volume anyway. But it looks a bit sloppy, look:
Code:
prompt> ./volume down 5
Volume changed from 80% to 74%.
prompt> ./volume down 5
Volume changed from 74% to 67%.
prompt> ./volume up 5
Volume changed from 67% to 74%.

Other than that, it's the perfect companion to waif.
Back to top
View user's profile Send private message
TheEternalVortex
Apprentice
Apprentice


Joined: 15 Oct 2002
Posts: 207
Location: San Jose, CA

PostPosted: Mon Jan 26, 2004 3:03 am    Post subject: Reply with quote

Yes, it's not exact because the ALSA program has it go from 0-31, so I can only change it on those values.

The idea to toggle mute is a good one. I'll add that in. Would it be better to use an environment variable or a config file? For now I think I will set it up to use a config file.
_________________
-- Andy
Back to top
View user's profile Send private message
TheEternalVortex
Apprentice
Apprentice


Joined: 15 Oct 2002
Posts: 207
Location: San Jose, CA

PostPosted: Mon Jan 26, 2004 4:31 am    Post subject: Reply with quote

All right, I've added all the requested features, see the first post for info on volume 1.5 beta.
_________________
-- Andy
Back to top
View user's profile Send private message
Andersson
Guru
Guru


Joined: 12 Jul 2003
Posts: 525
Location: Göteborg, Sweden

PostPosted: Mon Jan 26, 2004 7:59 pm    Post subject: Reply with quote

Great! Now it does everything I want :D Thanks.

On a picky note, the output for up and down are different, up has preupnew and postupnew with values displayed (even with the --quiet option).
Code:
prompt> ./volume down 5
Volume changed from 93% to 87%.

prompt> ./volume up 5
preupnew: 27
postupnew: 28.55
Volume changed from 87% to 93%.

prompt> ./volume down 5 --quiet

prompt> ./volume up 5 --quiet
preupnew: 27
postupnew: 28.55
Back to top
View user's profile Send private message
TheEternalVortex
Apprentice
Apprentice


Joined: 15 Oct 2002
Posts: 207
Location: San Jose, CA

PostPosted: Tue Jan 27, 2004 1:44 am    Post subject: Reply with quote

Oh, hah, I forgot to remove some debugging code. Updated version with that fixed, plus fixed another bug.
_________________
-- Andy
Back to top
View user's profile Send private message
MighMoS
Guru
Guru


Joined: 24 Apr 2003
Posts: 416
Location: @ ~

PostPosted: Tue Jan 27, 2004 4:19 pm    Post subject: Reply with quote

You could make it (or have an option to) make sure that /dev/snd/* and /dev/sound/* are group audio and group read/write...
Back to top
View user's profile Send private message
lucida
Apprentice
Apprentice


Joined: 20 Feb 2003
Posts: 191

PostPosted: Thu Jan 29, 2004 9:26 am    Post subject: Reply with quote

If you have snd_pcm_oss module(the oss emulation for alsa), just use aumix to adjust the volume. There are lots of scripts floating around to do vol up/down/mute with aumix.

If you are using the KDE 3.2, just enjoy the new "kmix", it handles the multimedia keyboard pretty well.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
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