It's done in hardware - something like the an X-Fi has close to the number of transistors of a Pentium 4. It filters the sound based on how sound enters your ear. Of course, it isn't perfect since everybody's ear is shaped differently, but it's a lot better than just putting sound in the left or right channel unfiltered.