audio – Calculating stereo sound levels from 3d sound source?

When a sound is emitted in a (first person) game world at some source position relative to the player – based on its distance away we can calculate the factor to multiply the amplitude of the wave that should be sent to the speakers from the inverse of the distance (in a unit of some appropriate “origin” base distance) – fine.

What I am not clear about is how to generate 2 channel stereo left/right sound.

(A) Let’s say when the source is directly in front of the listener in the game world (and at the base distance away) we play the sound wave at the original recording amplitude in both speakers. Let’s denote this by (L,R) = (1.0, 1.0).

(B) Now what if instead the sound source is directly to the right of the listener (and again base distance away). Clearly we play the sound louder in the right speaker than in the left one, right? But how much louder? Should the wave in the right speaker be louder than the wave in the right speaker in situation (A) ? What factor should we multiply the wave by in the left and right speaker? ie What should (L,R) be now?

(C) Now what if the source is at a 45 degree angle forward and off to the right of the listener ? What should (L, R) be in this situation?

How do you calculate (L,R) in general as a function of the relative source position and listener orientation?