Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to create a widget for awesome wm that controls and monitors volume.

Getting and setting the speaker volume is easy in ALSA and PulseAudio, but how about getting the actual signal strength?

By this I mean the actual noise you hear, e.g. if no sound is playing it is zero. Just like you would see of an amplifier (the VU-monitor).

Usually I can manage to find a file in /proc/ that holds some value as to what is being used (eg. /proc/stat for cpu usage), but this is not the case this time.

The goal is really to show a real-time audio display (preferrably separate L/R channels) that resembles the gain VU-monitor from an amplifier.

note that the question is not about how to program this for awesome wm, but how to get the values that can be used to do it

share|improve this question
add comment

1 Answer 1

I don't think this is trivial, and this question should probably be moved to stackoverflow.

There is as far as I know no sysfs or procfs interface for accessing the final (ALSA) [audio] mix; there's not even a guarantee that there is such a thing in software, as some hardware (such as emu10k1) performs its own mixing, although I admittedly have no idea how that works.

There's also the matter of multiple audio outputs (digital(like SPDIF), analog, headphons or speakers, etc) and multiple speaker configurations on the same card, not to mention the possibility of multiple cards.

The best bet is presumably to try to tap into whichever ALSA device is used (Presumably hw0 if mixing is occurring in a sound subsystem like pulseaudio, or dmix if no sound subsystem is used), since this is the "last step" before the audio reaches hardware. That being said, I have no idea if this is possible; probably not.

If you can assume that the user is using something like pulseaudio, then the task becomes much easier. Software such as pavucontrol implements this already, as seen under the Playback tab, as well as pre-final-mix stages under Output devices. Technically, this involves getting the audio stream itself, then converting it to the frequency domain (eg by performing StFt) in order to visualize it in some fashion; all you really need for this is access to the audio stream, and pulseaudio can provide this (like pavucontrol does) via a sink.

I'm not being of much help, am I? If I were you and just wanted this for my desktop, and if I were using pulseaudio(which I myself happen to use), my first goal would be to attempt to obtain the final mix stream. The guys in this thread seem to have figured out an eloquent method of doing that using only pactl and pacmd, which could quite easily be done programmatically as well.

When you've got ahold of the audio stream, only the math remains :-)

share|improve this answer
    
do you know the ncmpcpp visualiser? Something like this could be attempted? –  romeovs Apr 11 '12 at 17:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.