Reading levels from command line... possible?

OSS specific Linux discussion (x86/amd64)

Moderators: hannu, dev, cesium

aolivan
New Member
Posts: 4
Joined: Fri Nov 15, 2013 10:22 am

Reading levels from command line... possible?

Postby aolivan » Fri Nov 15, 2013 10:41 am

Hi forum...

just one totally newby question...
Would it be possible to read the actual level from an audio device from the command line?
I know I can easily "set" mixer settings trough ossmix
I know I can "read" mixer settings too that way...

But I wonder wether it would be possible to have a binary (I have read this is possible with ioctl and API, but I'm not an experienced programmer... :( )that would read the actual value and simply return a value...
That way I could, from userspace, verify remote machines are actually playing, detect silence, verify cabling, etc...

I have experience building from sources, so I think this has not to be much difficult for an expert on the matter (I have read the ossxmix source trying to get a clue... but is still too complex to me), maybe someone could put here the code to build such a binary...

Anyhow, thanks in advance for your patience :D !
Cheers!

cladisch
Member
Posts: 31
Joined: Mon Apr 07, 2008 8:14 am
Location: Earth

Re: Reading levels from command line... possible?

Postby cladisch » Fri Nov 15, 2013 12:59 pm

Most audio devices to not have a mixer control that allows to read the current input level.

You have to use some tool like http://sox.sourceforge.net/sox.html to capture some data and compute its level (in the case of sox, with the stat command).

aolivan
New Member
Posts: 4
Joined: Fri Nov 15, 2013 10:22 am

Re: Reading levels from command line... possible?

Postby aolivan » Fri Nov 15, 2013 1:17 pm

...Aha

Well, at least one clue to further investigate :)
At first seems it is gonna be harder than I thought...

Thank you very much!

igorzwx
Known Member
Posts: 1246
Joined: Sun Jun 28, 2009 9:31 pm

Re: Reading levels from command line... possible?

Postby igorzwx » Fri Nov 15, 2013 1:38 pm

cladisch wrote:Most audio devices to not have a mixer control that allows to read the current input level.

You have to use some tool like http://sox.sourceforge.net/sox.html to capture some data and compute its level (in the case of sox, with the stat command).


OSS Mixer GUI (ossxmix) displays the current input and output levels: vmix0-invu and vmix0-outvu. Right?
There is a source code...

seawright
Member
Posts: 94
Joined: Sat Jan 06, 2007 9:10 pm
Location: Hampshire UK

Re: Reading levels from command line... possible?

Postby seawright » Fri Nov 15, 2013 7:04 pm

Couldn't you just filter the output of ossmix using awk?

e.g.

Code: Select all

ossmix vmix0-outvol |awk '{print $(NF-1)}'
regards
Clive

igorzwx
Known Member
Posts: 1246
Joined: Sun Jun 28, 2009 9:31 pm

Re: Reading levels from command line... possible?

Postby igorzwx » Fri Nov 15, 2013 7:53 pm

seawright wrote:Couldn't you just filter the output of ossmix using awk?

e.g.

Code: Select all

ossmix vmix0-outvol |awk '{print $(NF-1)}'


ossmix shows the "mixer settings" and nothing more.
It does not show actual sound levels.

If you want to know the actual sound levels, you have to measure them with a kind of VU-meters https://en.wikipedia.org/wiki/VU_meter
You may find such VU-meters in Audacity http://wiki.audacityteam.org/wiki/VuMeter
The OSS4 virtual mixer (vmix) also has VU-meters: vmix0-invu and vmix0-outvu
You may find them in OSSXMIX.

seawright
Member
Posts: 94
Joined: Sat Jan 06, 2007 9:10 pm
Location: Hampshire UK

Re: Reading levels from command line... possible?

Postby seawright » Sat Nov 16, 2013 4:42 am

Ah! I see what you mean.
Ok then, how about?

Code: Select all

 ossmix -D |grep outvu |awk -F "=" '{print $NF}'
regards

Clive

igorzwx
Known Member
Posts: 1246
Joined: Sun Jun 28, 2009 9:31 pm

Re: Reading levels from command line... possible?

Postby igorzwx » Sat Nov 16, 2013 8:29 am

seawright wrote:Ah! I see what you mean.
Ok then, how about?

Code: Select all

 ossmix -D |grep outvu |awk -F "=" '{print $NF}'


It seems to work, although it prints the value in a "strange format" ( hex with the prefix 0x https://en.wikipedia.org/wiki/Hexadecim ... esentation ):

Code: Select all

$ ossmix -D |grep outvu |awk -F "=" '{print $NF}'
0x8c8c


He may need to convert it to decimal number:

Code: Select all

$ echo $(($(ossmix -D |grep outvu |awk -F "=" '{print $NF}')))
23901


TEST: Conversion to the "strange format" and vice versa:

Code: Select all

$ echo 0x$(printf '%x\n' 23901)
0x5d5d
$ echo $((0x5d5d))
23901

aolivan
New Member
Posts: 4
Joined: Fri Nov 15, 2013 10:22 am

Re: Reading levels from command line... possible?

Postby aolivan » Mon Nov 18, 2013 2:43 am

:o
You rock man!

I though ossmix values were just settings... not actual vu values...
I have to test it tomorrow, but provide it work, I thing I could manage to have a very spartan, shell scrip based, silence detector...
I thing it would be even possible to write a munin plugin to display an average volume value graph to monitor unatended machines and trigger alarms!!!
Hope it works! wow!

aolivan
New Member
Posts: 4
Joined: Fri Nov 15, 2013 10:22 am

Re: Reading levels from command line... possible?

Postby aolivan » Mon Nov 18, 2013 10:03 am

Yeah it works!

I would have to be more acurate and realize we do have the nice -D option on ossmix that yelds the full card values...
OSS rocks!

I would put the thread as SOLVED.

Out of curiosity... Do you know guys what is the span for the values? is it fixed? varies with the sound card?... I guess 0 means obviously no sound, but I wonder what are the top levels, and wether a logarithmic scaling is applied to the values, and so...

Many thanks to everyone!!!

Edit (copy paste fro the API):
The value returned simply the largest sample value seen on the input since the previous time this call was made (the values will be set to zero after each call). The samples are scaled so that the maximum is 32767 and the minimum is 0. The scale is linear (NOT dB).

igorzwx
Known Member
Posts: 1246
Joined: Sun Jun 28, 2009 9:31 pm

Re: Reading levels from command line... possible?

Postby igorzwx » Mon Nov 18, 2013 11:17 am

aolivan wrote:Yeah it works!
I would have to be more acurate and realize we do have the nice -D option on ossmix that yelds the full card values...


To be more precise, vmix is not a card, it is a kind of PulseAudio
http://manuals.opensound.com/usersguide/vmix.html

Some "professional soundcards" may have VU-meters.

vmix driver may not be loaded by default for "professional soundcards", because it is a kind of "virtual crap".
If you have a kind of LynxTWO, you may test it http://manuals.opensound.com/usersguide/lynxtwo.html

seawright
Member
Posts: 94
Joined: Sat Jan 06, 2007 9:10 pm
Location: Hampshire UK

Re: Reading levels from command line... possible?

Postby seawright » Wed Nov 20, 2013 10:17 pm

Tried using gstreamer audio test source with volume set to maximum:

Code: Select all

gst-launch audiotestsrc freq=880 volume=1.0 ! audioconvert ! osssink

Code: Select all

ossmix -D vmix0-outvu
Value of mixer control vmix0-outvu is currently set to 126:126

Suspect maximum value is 32639, 0x7f7f or 127:127 value being highest possible positive signed integer that can be represented in an eight bit field.
regards

Clive

igorzwx
Known Member
Posts: 1246
Joined: Sun Jun 28, 2009 9:31 pm

Re: Reading levels from command line... possible?

Postby igorzwx » Thu Nov 21, 2013 12:12 am

seawright wrote:Tried using gstreamer audio test source with volume set to maximum:

Code: Select all

gst-launch audiotestsrc freq=880 volume=1.0 ! audioconvert ! osssink

Code: Select all

ossmix -D vmix0-outvu
Value of mixer control vmix0-outvu is currently set to 126:126

Suspect maximum value is 32639, 0x7f7f or 127:127 value being highest possible positive signed integer that can be represented in an eight bit field.


127 does not seem to be the highest value:

Code: Select all

$ ossmix -D vmix0-outvu
Value of mixer control vmix0-outvu is currently set to 144:144


In a word, "ossmix vmix0-outvu" produces the same result:

Code: Select all

$ ossmix vmix0-outvu
Value of mixer control vmix0-outvu is currently set to 144:144


There might be an "ultimate secret documentation" (i.e. source code).

Notice that vmix0-outvu is a "Stereo peak meter"

Code: Select all

$ ossmix -D | grep vmix0-outvu

seawright
Member
Posts: 94
Joined: Sat Jan 06, 2007 9:10 pm
Location: Hampshire UK

Re: Reading levels from command line... possible?

Postby seawright » Thu Nov 21, 2013 1:31 am

Ok so I'm wrong. Definitely eight bits per channel but must be unsigned which in theory would allow up to 0xffff or 255:255
Don't know how to test other than driving an external input with an audio signal generator. Suspect the A to D converter would saturate before that level was reached but don't want to risk damaging my sound card to find out.
regards

Clive

igorzwx
Known Member
Posts: 1246
Joined: Sun Jun 28, 2009 9:31 pm

Re: Reading levels from command line... possible?

Postby igorzwx » Thu Nov 21, 2013 1:48 am

seawright wrote:Ok so I'm wrong. Definitely eight bits per channel but must be unsigned which in theory would allow up to 0xffff or 255:255
Don't know how to test other than driving an external input with an audio signal generator. Suspect the A to D converter would saturate before that level was reached but don't want to risk damaging my sound card to find out.


ossmix says: max=144

Code: Select all

$ ossmix -D | grep vmix0-outvu
80: Stereo peak meter: 'vmix0-outvu' (vmix0-outvu), parent=0, max=144, flags=0x205  Current value=0x0000


max=144 seems to mean 144:144

Since one channel might be silent, one may need a stereo meter.
In this case, "ossmix vmix0-outvu" might be useful (e.g. awk)


Return to “Linux”

Who is online

Users browsing this forum: Google [Bot] and 1 guest