I'm trying to set sound panning in my game depending on camera position, rotation and audio source position.

I was able to set sound panning depending on camera position (listener), and audio source like this:

Vector3 toSourceVector = Vector3::subtract(sourceTransform->position, listenerTransform->position);
float value = MathUtil::clamp(toSourceVector.x, -1.5f, 1.5f);
value = value + 1.5f;
float perc = (value / 3.0f) * 254.0f;
AudioManager::setPanning(254.0f - perc, perc);

Max panning value on the right/left speaker is 254. When I'm standing on the front of the audio source (without rotating my camera), panning values are: 127 and 127, for example, when the audio source is on my right side, panning values are 0 and 254.

Obviously, if I rotate my camera, sound panning is same.

I've got Vector3 with camera (listener) rotation values (x, y, z).

My question is: how to calculate panning values depending on camera rotation too?

  • 1
    \$\begingroup\$ I'd suggest you to take a more advanced sound library with built-in 3D sound effects, something like OpenAL. \$\endgroup\$ Jun 26, 2016 at 15:54
  • 1
    \$\begingroup\$ Unless you're interested in implementing a 3D sound library, there are plenty of 3rd party libraries that do this: OpenAL as mentioned, FMOD, and irrKlang come to mind. \$\endgroup\$ Jun 26, 2016 at 18:50

1 Answer 1


Sorry for answering my own question, but as the final solution, I decided to use ready API called OpenAL, that takes a care of sound panning.

Thanks for everyone's input.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .