LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-18-2006, 07:06 PM   #1
pete1234
Member
 
Registered: May 2005
Distribution: Slack, FreeBSD,NetBSD, OpenBSD, Open Solaris, Minix
Posts: 172

Rep: Reputation: 30
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)?
 
Old 10-19-2006, 10:07 AM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
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.
 
Old 10-19-2006, 10:17 AM   #3
pete1234
Member
 
Registered: May 2005
Distribution: Slack, FreeBSD,NetBSD, OpenBSD, Open Solaris, Minix
Posts: 172

Original Poster
Rep: Reputation: 30
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.
 
Old 10-19-2006, 10:52 AM   #4
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
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.
 
Old 10-19-2006, 10:59 AM   #5
pete1234
Member
 
Registered: May 2005
Distribution: Slack, FreeBSD,NetBSD, OpenBSD, Open Solaris, Minix
Posts: 172

Original Poster
Rep: Reputation: 30
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.

Last edited by pete1234; 10-19-2006 at 11:02 AM.
 
Old 10-19-2006, 11:11 AM   #6
pete1234
Member
 
Registered: May 2005
Distribution: Slack, FreeBSD,NetBSD, OpenBSD, Open Solaris, Minix
Posts: 172

Original Poster
Rep: Reputation: 30
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.
 
Old 10-19-2006, 11:29 AM   #7
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
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.
 
Old 10-19-2006, 11:44 AM   #8
pete1234
Member
 
Registered: May 2005
Distribution: Slack, FreeBSD,NetBSD, OpenBSD, Open Solaris, Minix
Posts: 172

Original Poster
Rep: Reputation: 30
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.
 
Old 10-19-2006, 02:05 PM   #9
soggycornflake
Member
 
Registered: May 2006
Location: England
Distribution: Slackware 10.2, Slamd64
Posts: 249

Rep: Reputation: 31
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...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sound card Issues in Suse 9.3 with a ??Conexant?? Sound card in Gateway laptop hackerarchangel Linux - Hardware 3 12-30-2005 11:35 PM
Changing primary sound card or disabling a sound card tfr Linux - Hardware 2 02-10-2005 08:33 AM
If you have a PCI sound card, should you disable the on-board sound card? jtp51 Linux - Newbie 1 10-06-2004 10:42 AM
keep onboard sound card enabled when a second sound card has been added ViralHex Linux - Hardware 0 06-08-2004 01:06 PM
Diabling onboard sound card and enabling pci slot sound card abhatia Linux - Hardware 4 01-12-2004 02:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration