Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
Are you fine with/are you currently using any middleware for sound? What sound API are you currently using? –  Tetrad Apr 25 '11 at 15:59
    
I'm using Flash. All I have control over is the volume of the left and right channels. –  echeese Apr 25 '11 at 16:19

1 Answer 1

up vote 7 down vote accepted

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:
1-(d(L,S)/maxDistance)
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.

share|improve this answer
    
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. –  brandon Apr 25 '11 at 16:37
    
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. –  Ray Dey Apr 25 '11 at 16:41
    
Lol beat me to it :P –  Ray Dey Apr 25 '11 at 16:41
1  
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? –  echeese Apr 25 '11 at 17:48
1  
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. –  Ray Dey Apr 25 '11 at 21:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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