Determine current volume from C/C++

Hi

I am trying to determine the current Volumio volume from a C++ program.

It appears not to be the MPD volume. On a PC running MPD on Ubuntu I can use libmpdclient to get the current volume using the example program
https://github.com/cmende/libmpdclient/blob/master/src/example.c

If I run this same program on a Raspberry Pi Zero W with an I2S PCM5102A DAC running Volumio and using the Software Mixer it always returns 40 for the volume.

How can I get the current volume value shown in the Volumio UI?

Thanks

Adrian.

Some more information…

Running alsamixer, I can see that the default sound card is bcm2835 ALSA, and has a volume of 40. I imagine this is why libmpdclient is returning 40. The second sound card is snd_rpi_hifiberry_dac and is the card used by Volumio and has the volume I want to read.

I am not looking for a way to read the volume on this specific device, but a general way of reading the Volumio volume.

volumio_alsamixer.png

EDIT:

mpc status

Also returns 40% for the volume

Your best bet is to use Volumio’s REST API:
volumio.github.io/docs/API/REST_API.html

Use the getstate method, while connecting to localhost:3000

Thanks!

I wrote a test program using libcurl and I can extract the volume in around 50ms, which should be fine for my needs.

I am finding that the call to the API can be very slow (on a Raspberry Pi Zero W). If I change the song that is playing and try to retrieve the Volumio status then a call can typically take seven seconds to return the status, this is just after the song has started to play.

I am using libcurl and can see the delay on my OLED display, but it also affects the command line, e.g. running running curl or wget on the Volumio machine. It also affects ‘volumio volume’. It can also been seen on the Web UI by playing a song and then changing the volume, the volume display reverts to the original volume value and then after a delay of several seconds the new volume is again displayed.

It isn’t a big issue for displaying the volume on the OLED, but I changed to using the Volumio status for the artist and title and found the delay too long for those details (which could take several seconds to display after a song has started), and so I went back to using the MPD status.

Is there a quicker way of getting the Volumio volume (or the Volumio status information)?

I notice there is a script /tmp/getvolume that returns the volume. Will this script always be present on a running system? Are there any issues in using it to get the current volume?

Thanks

Adrian.