tags:

views:

77

answers:

2

There are a lot of reasons for sound not work (no speakers, speakers turned off, volume set to zero, software configuration problems, etc)

How can I discover from within my program if sound is working and being heard?

+6  A: 

The only way to reliably do that is pretty much to ask the user:

play sound;
if (user_hears_sound_dialog)
  sound works;

Edit: Please don't do an unannounced sound test by killing the users ears, potentially blowing his speakers and forcing him to kill the application. It's just not nice, see!

Williham Totland
Agreed! No matter what weird approach someone may come up with (e.g., listen for the echo-back through the microphone + delay and distortion measurements to make sure its not a hardware loopback, e.g., cable from line-out to line-in) it'll ultimately fail when it turns out the user is deaf. Or was listening to his iPod.
derobert
A: 

Of course only the user can decide if sound is working.

Programmatically, I believe that only with a micro you could trace sounds.

Nick D
But how do you know if the microphone is working? ;)
Williham Totland
Alas, the dastardly user plugged a cable between the line-out and line-in (or mic-in) ports.
derobert
probably you can't :o) anyway, you can at least try before asking the user -- if it is critical for some reason, to do that.
Nick D
The problem is that it can give, as derobert points out, a false positive; if this happens the user can now not hear the sound, and you believe it to be working; so you never ask the user. Which is a problem if sound is critical. A big problem.
Williham Totland
On a serious note, if the microphone does not pick up the sound, maybe there isn't a mic, its muted, etc. -> ask the user; if the microphone does pick up the sound maybe the sound card is looped back (some have a mixer control for this), maybe the mic is right next to the speaker, so it hears it despite the speaker volume being way too low, maybe the user is wearing headphones for his iPod -> ask the user. So, checking the mic doesn't get you anything except code complexity.
derobert
@derobert, I don't claim that using micro is a reliable solution. I wrote that "only the user can decide if sound is working".
Nick D