I am trying to put 3Dish audio in a game I'm developing, and I'm unsure how to do positional sound. I want to be able to adjust the volume of the audio's channels depending on how far it is and the orientation.

  • \$\begingroup\$ Are you fine with/are you currently using any middleware for sound? What sound API are you currently using? \$\endgroup\$ – Tetrad Apr 25 '11 at 15:59
  • \$\begingroup\$ I'm using Flash. All I have control over is the volume of the left and right channels. \$\endgroup\$ – Ryan S Apr 25 '11 at 16:19

Since you didn't mention any API for sound I'll give you the general answer.

First get the distance between the audio listener and the audio source
d(L,S) = sqrt((x2-x1)2 + (y2-y1)2 + (z2-z1)2)

Then you define a distance where you don't want it to be audible anymore, lets say 150m

If your distance is 40 meters from the source, then the volume is about 73%.

To give you an equation that would be:
or (1-(40/150)) = about .73
That will be the percentage of volume from 1 to 100%

That's assuming you want the volume to change linearly with your position change.

| improve this answer | |
  • 1
    \$\begingroup\$ Just realized you want this multichannel. To do that, you can use what I've said to get the main volume, then for the individual volume, you can take the rotation that would be looking straight at the audio source, then subtract that from your actual look rotation. You can then take the Y value of this resulting vector and say -90 degrees is completely in the right channel, 90 degrees is completely in the left channel. I cant answer you in the case of flash so this answer is probably useless if you don't understand vectors well. \$\endgroup\$ – brandon Apr 25 '11 at 16:37
  • \$\begingroup\$ You'd need to split that volume appropriately for the left and right channels depending on the angle between the listener and the source too. \$\endgroup\$ – Ray Dey Apr 25 '11 at 16:41
  • \$\begingroup\$ Lol beat me to it :P \$\endgroup\$ – Ray Dey Apr 25 '11 at 16:41
  • 1
    \$\begingroup\$ Other than linear, what options do I have? What is the relationship between volume and distance in real life? Also, I just realized that something will sound the same from in front of you as behind you. What do games do to distinguish this? \$\endgroup\$ – Ryan S Apr 25 '11 at 17:48
  • 1
    \$\begingroup\$ It's known as sound attenuation. There are (fairly advanced) equations for it. In a simple case you can use linear falloff (as described in the answer), exponential or exponential squared falloff (1/d or 1/d^2, respectively. \$\endgroup\$ – Ray Dey Apr 25 '11 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.