LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Is the sound card in use? (https://www.linuxquestions.org/questions/programming-9/is-the-sound-card-in-use-493666/)

pete1234 10-18-2006 07:06 PM

Is the sound card in use?
 
I'm just wondering if there's a simple way (that could be used in a shell script) to tell if the sound card is in use (as in audio is being played)?

tuxdev 10-19-2006 10:07 AM

If you lsof /dev/dsp, you will get all processes that have the sound device open. This tells you if sound is opened for recording too. It will not tell you if it is currently getting read() or write(). Those issues probably don't really matter for your app, though.

pete1234 10-19-2006 10:17 AM

Thanks for the reply. Though that won't work for my app. I need to know if audio has been stopped for any reason, be it paused / stopped by a user or if a live stream is dropped.

tuxdev 10-19-2006 10:52 AM

If you ls -lu /dev/dsp, it shows the last access time. The problem here is that the number is that the granularity is too big, but I know I can write a simple C app that would be able to get you an unformatted access timestamp in seconds quite easily. There might be a standard program to get that info, but I don't know from the top of my head what it is.

pete1234 10-19-2006 10:59 AM

If you feel like writing the app I'd appreciate it. In the mean time I'll put google to work for the standard program. Thanks for the reply.

pete1234 10-19-2006 11:11 AM

The stat command gives me the access time in seconds, however using the stat command changes the access time of the file, and there's no preserve flag.

tuxdev 10-19-2006 11:29 AM

The access time is probably being updated because it is following the link. I noticed that stat times weren't useful on the device itself. The 10 second C app I did that doesn't follow links didn't work because the value would be updated too late. I suppose that makes sense because that is how reader-writer locks work. Turns out ls -lu has the same problem as stat. Thinking further, access time might be completely the wrong idea.

The only way to really know whether read() and write() is happening or not may be to catch the system call, sort of like how installwatch does it to track installations. I don't really want to go there, but it is a potential solution.

pete1234 10-19-2006 11:44 AM

Running strace on the audio player gives me output that I could use, but it's a bit load intensive. Oh well, that's for giving it a shot.

soggycornflake 10-19-2006 02:05 PM

How about this?

Code:

#!/bin/sh
dialog --yesno "Do you hear sound coming from the speakers?" 10 30
if [[ $?== 0 ]]; then
    #... sound playing...
else
    #... sound not playing...
fi

Sorry, couldn't resist, you did ask for a _simple_ way... :D


All times are GMT -5. The time now is 04:32 AM.