Multiple factors:
The slight delay from one ear to the other for left-right, mostly
The shape of your head and ears amplify or dampen certain frequencies at different angles
Also, the floor beneath you and the walls around you cause sound to bounce at you with slight delays and also shape which frequencies are boosted, which can also help determine the direction and distance of sounds
Essentially, sound takes time to propagate through space, and bounces around a lot, interfering with itself, and this all shapes the sound in many subtle ways, filtering or boosting frequencies, tiny echoes and reverberations, things like that, and your brain has gotten very good at extracting information over time.
Edit: regarding how to simulate this in headphones:
Audio through headphones is very “direct”, which means that unprocessed sound almost feels like it’s coming from inside your head.
But the sound can be processed to have the same kind of filtering and reverberation you would hear if it was played to you in a real space and transformed by the shape of your head and ears (called a “head-related transfer function” or HRTF), or simply recorded with microphones placed in a model of a head with ears , which can trick your brain into believing the sound is coming from a particular place.
Latest Answers