site  contact  subhomenews

Simple test if audio muted

December 31, 2021 — BarryK

I am working out how to do things in /usr/sbin/mscw (Multiple Sound Card Wizard). A huge issue for me has been moving from alsa to pulseaudio. Here is a link to earlier work:

https://bkhome.org/news/202111/how-pulseaudio-is-implemented-in-easyos.html

I am still very uncertain about aspects of the interaction between alsa and pa. The single most important feature is /etc/alsa/conf.d/99-pulseaudio-default.conf, that essentially directs alsa output to the pa server.

In mscw, I want a quick check of output volume and muted/unmuted status for a particular card. It can be done using 'pactl' or 'pacmd', pa utilities, however, I wanted to do it at the "alsa level", with an alsa utility...

'amixer' is an alsa utility, and "-c 0" means card #0:

# amixer -c 0 get Master
Simple mixer control 'Master',0
Capabilities: pvolume pvolume-joined pswitch pswitch-joined
Playback channels: Mono
Limits: Playback 0 - 87
Mono: Playback 72 [83%] [-11.25dB] [on]

...that "[on]" means unmuted. However, the volume of "83%" is not what pa sees. We can make amixer see exactly what pa sees, by doing this:

# amixer -c 0 -D pulse get Master
Simple mixer control 'Master',0
Capabilities: pvolume pswitch pswitch-joined
Playback channels: Front Left - Front Right
Limits: Playback 0 - 65536
Mono:
Front Left: Playback 42154 [64%] [on]
Front Right: Playback 42154 [64%] [on]

...that "64%" is the same as pavucontrol and pa-applet (in the systray) show.

My understanding is limited, do not know why there are two different volume levels. However, the mute/unmute is correct for both cases.

Anyway, can put some simple tests into mscw for muted/unmuted and volume:

# amixer -c 0 -D pulse get Master | tail -n 1 | grep -c '\[on\]'
1
# amixer -c 0 -D pulse get Master | tail -n 1 | grep -o '[0-9]*%'
64%

Here is another thing that I don't understand, the difference between "get" and "sget":

# amixer -c 0 sget Master
Simple mixer control 'Master',0
Capabilities: pvolume pvolume-joined pswitch pswitch-joined
Playback channels: Mono
Limits: Playback 0 - 87
Mono: Playback 72 [83%] [-11.25dB] [on]
# amixer -c 0 -D pulse sget Master
Simple mixer control 'Master',0
Capabilities: pvolume pswitch pswitch-joined
Playback channels: Front Left - Front Right
Limits: Playback 0 - 65536
Mono:
Front Left: Playback 42154 [64%] [on]
Front Right: Playback 42154 [64%] [on]

...doesn't seem to be any difference.

Now to see about putting this into mscw...   

Tags: easy