How does a sound card determine if headphones are plugged in?
This is actually two questions in one.
First, how do soundcards (the cheap ones) "detect" whether the headphones are plugged in? By measuring resistance or by some other technique?
Second, can I somehow have different sound outputs sent to the speakers and the headphones? I'm guessing no, at least no on the cheap ones. What does one need to accomplish that?
(I've no idea about anything related to sound save of listening to mp3's, so this may be overly simple question to some.)
Solution 1:
The audio ports detect that something has been plugged in by monitoring for a change in resistance across the port. When nothing is plugged in the resistance is infinite, but when a coil is plugged in (speaker or mic) there is now a measurable resistance, and the computer pops up and asks you what it is you plugged in.
EDIT: I've been digging, and instead of trying to figure out what the audio adapter manufacturers are doing, I decided to look at the jack manufacturers to figure out if there are internal mechanical switches, as well as perhaps suggested uses.
Turning to Digi-key, I found that there are a few different mechanical ways the jacks provide for detection. The most common DOES seem to be a separate, internal switch circuit based on the position of the inner-most blade in the barrel; and they are only a couple cents more per unit than a non-switched jack. Here's a dual barrel surface mount by Tyco that I think looks similar to what can be on a motherboard.
Interestingly on many (most?) the detection switch is actually reversed. So the switch is closed until the plug is inserted, here's one by CUI.
This one by Schurter is crazy; it's a "stereo" jack that all three rings (including the ground) are switched. So it could tell you how deep the plug is pushed I guess ;) Only $6.50 each!
Using these switches DOES seem to be the more likely way they're doing it, and what I've been told in the past is probably incorrect, or at least not correct across-board.
I'm going to disect one Monday -- I gotta see if that switch is at least in the jacks Intel's been using. :)
If you are aiming to have the same sound on both headphones and speakers, then you may want to look into getting an audio jack y-adapter (splitter):
If you want different sounds on each a headphone and a speaker set then you're probably dependent on the abilities of the software mixer provided by your audio adapter's manufacturer, and/or the software you're using.
Depending on your situation, you may want to consider getting a secondary audio card as well, that way you can point different applications at each audio device.
Solution 2:
As pipTheGeek stated, another option to the electrical resistance measurement is a mechanical switch.
Switch pushed down - something's plugged in.
You can test this by plugging a Y-adapter or size adapter into the jack. If the jack acts like there's something plugged into the port, you have a mechanical switch.
The adapter won't make any connections between the lines and ground so it shouldn't count as an output device to the resistance measurement.