Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Alsa: where is the current volume level stored?

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
bedtime
Posts: 146
Joined: 2012-12-16 19:34
Has thanked: 1 time
Been thanked: 6 times

Alsa: where is the current volume level stored?

#1 Post by bedtime »

If I wanted to know how much memory I was using, I could type:

Code: Select all

$ cat /proc/meminfo
Then I could just use grep or awk to extract the info from there. That's what I want to do with the current volume level of alsa. I would the volume level so I can print it out in my status bar (a dzen2 bar in i3 window manager). I understand that I could just run

Code: Select all

$ amixer get Master
and extract from there, but I don't want to call a program to do it as it's less efficient that way; the command to display it would be called about every 1/2 a second, and currently using awk to extract info from the aforementioned command is quite costly. There is a noticable difference in cpu usage when it is turned on, so I have it updating every second instead, and when I'm changing the volume levels it takes that second to refresh, which is undesirable.

I will be updating the statusbar to read a /dev/shm/volume file. I would still have to read the current volume into that file, but only when it changes (so not having to run that command every second), but I would still need to extract the volume, and I do want to do this efficiently.

I can see that there is a /proc/asound, but I've looked, and maybe I've missed something—entirely possible—but I've yet to find it. Maybe it is stored in ram? Hopefully not. :?

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

Re: Alsa: where is the current volume level stored?

#2 Post by bw123 »

Code: Select all

/usr/share/doc/alsa-utils/README.Debian              1688/3249               51%
they were saved (see below).  The levels are stored in the file
/var/lib/alsa/asound.state.
resigned by AI ChatGPT

bedtime
Posts: 146
Joined: 2012-12-16 19:34
Has thanked: 1 time
Been thanked: 6 times

Re: Alsa: where is the current volume level stored?

#3 Post by bedtime »

bw123 wrote:

Code: Select all

/usr/share/doc/alsa-utils/README.Debian              1688/3249               51%
they were saved (see below).  The levels are stored in the file
/var/lib/alsa/asound.state.
Perhaps this is what is used to grab the initial volume at startup, but not realtime volume; a simple ls -la /var/lib/alsa/asound.state showed the same time stamp after I changed the volume, so it seems it doesn't hold those values.

I checked the document and nothing pertaining to what I'm looking for. I'm beginning to think more and more that the levels are just stored in ram. :(

*EDIT*

I might as well add my temporary solution incase anyone is interested:

volume.sh

Code: Select all

#!/bin/sh

# Change the volume
amixer sset Master $1

# Get the new volume and store it for later retrieval
echo $(amixer get Master | awk -F'[\\[.|\\]]' 'NR==5{print $4 "dB [" $7"]"}') >/dev/shm/volume

# Dislay the volume (for troubleshooting)
cat /dev/shm/volume

# Store the new volume so it persists after boot
/usr/sbin/alsactl store
Change the volume by issuing (a 2+, 2-, or toggle for mute):

Code: Select all

$ ./volume.sh 2+
Retrieve the volume within a script of your choice with:

Code: Select all

...
volume=$(cat /dev/shm/volume)
echo $volume
...
Exampe output:

Code: Select all

-36dB [on]

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

Re: Alsa: where is the current volume level stored?

#4 Post by bw123 »

check man alsactl there may be a way to get it to update the file more often, or set the nice level to make things nicer. I don't think skipping amixer is going to be that much more efficient, but I think it's great that you want to experiment with it.

good luck.
resigned by AI ChatGPT

bedtime
Posts: 146
Joined: 2012-12-16 19:34
Has thanked: 1 time
Been thanked: 6 times

Re: Alsa: where is the current volume level stored?

#5 Post by bedtime »

bw123 wrote:check man alsactl there may be a way to get it to update the file more often, or set the nice level to make things nicer. I don't think skipping amixer is going to be that much more efficient, but I think it's great that you want to experiment with it.

good luck.
Thanks. Checked it and nothing pertaining to such.

Anyways, the above solution is working fine for now, so I'm happy. If something else comes along, I'm all ears.

Post Reply