Simple game audio spatialisation techniques use Euclidean geometry to modulate audio pan and volume based on the distance and angle between the listener and sound source. For most applications 2D spatialisation suffices as it can be used in conjunction with standard stereo diffusion systems eg headphones or speakers.

Using Euclidian geometry, the distance between 2 objects with known x and y co-ordinates is caculated by using the formula

`distance = sqrt{(x_2-x_1)^2 + (y_2-y_1)^2}`

which is basically the same as Pythagorus’ Theorum – imagine a right angled triangle with the hypotenuse extending between 2 points representing the listener and sound source. If we know the lengths of the other 2 sides of the triangle we can solve for the hypotenuse.

The resulting distance between the 2 points is used to modulate volume, usually by multiplication with an attenuator factor, eg

`attenuator = 0.002;`

gain = distance * attenuator

The difference in position on the x plane between listener and sound source is used to modulate pan, calculated by the formula

`x_difference = x_2-x_1`

The result is modified by the width of the nominal environment divided by 2 (or the radius of the environment) to create a meaningful value between -1 and 1, eg

`pan = x_difference/(environment_width/2)`

Alternatively, the angle between the listener and sound source can be calculated using the mathematical function atan2 which is possibly preferable as it removes the need for a nominal environment size.

By using atan2 it is possible to convert the angle of the sound source into a useful number, within the range of -PI and PI, which can then be converted using PI to set a pan level of -1 to 1, eg

`pan = atan2((y_2-y_1),(x_2-x_1))/PI`

This technique supposes no difference between an object in front or behind of the listener.