Thursday, July 16, 2015

3d - Implementing Positional Sound


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.



Answer



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.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...