You can use the [head-related transfer function](https://en.wikipedia.org/wiki/Head-related_transfer_function) (HRTF) that positions sound sources somewhere in 3D space and then calculate what parts of it go into each ear.
Despite you only having two ears, the shape of your ears and how your brain processes the information can help tell you where a sound is coming from in terms of forward vs back and up and down. The HRTF effectively simulates that for a song or for sounds in a game environment.
Latest Answers