Alsa: where is the current volume level stored?

Kernels & Hardware, configuring network, installing services

Alsa: where is the current volume level stored?

Postby bedtime » 2018-07-25 11:36

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. :?
OS: Debian GNU/Linux (Buster—testing); Kernel: 4.16.0-2-amd64; Shell: sh; WM: i3
Machine: HP ProDesk 600 G3—i7-7700, 8GB RAM, 256 SSD, Intel HD Graphics 630

bedtime
 
Posts: 93
Joined: 2012-12-16 19:34

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

Postby bw123 » 2018-07-25 13:09

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.
User avatar
bw123
 
Posts: 3579
Joined: 2011-05-09 06:02
Location: TN_USA

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

Postby bedtime » 2018-07-25 13:49

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]
OS: Debian GNU/Linux (Buster—testing); Kernel: 4.16.0-2-amd64; Shell: sh; WM: i3
Machine: HP ProDesk 600 G3—i7-7700, 8GB RAM, 256 SSD, Intel HD Graphics 630

bedtime
 
Posts: 93
Joined: 2012-12-16 19:34

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

Postby bw123 » 2018-07-25 14:35

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.
User avatar
bw123
 
Posts: 3579
Joined: 2011-05-09 06:02
Location: TN_USA

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

Postby bedtime » 2018-07-26 17:32

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.
OS: Debian GNU/Linux (Buster—testing); Kernel: 4.16.0-2-amd64; Shell: sh; WM: i3
Machine: HP ProDesk 600 G3—i7-7700, 8GB RAM, 256 SSD, Intel HD Graphics 630

bedtime
 
Posts: 93
Joined: 2012-12-16 19:34


Return to System configuration

Who is online

Users browsing this forum: No registered users and 9 guests

fashionable