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)?
|
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.
|
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.
|
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.
|
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.
|
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.
|
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. |
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.
|
How about this?
Code:
#!/bin/sh |
All times are GMT -5. The time now is 04:32 AM. |