# Inverse square law for sound falloff

This topic is 1039 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Our sound engine has a "falloff" function. (used to make the sound get quieter as the listener moves away from the sound) The relavent inputs we have in this function are:

distance (the distance from the sound to the listener)

min (the distance from the sound at which it starts getting quieter)

max (the distance from the sound at which it goes silent)

The function returns a float value between 0.0 and 1.0 with 1.0 meaning full volume and 0 meaning silent.

If the distance is less than min, we want the function to return 1.0. If the distance is greater than max, we want the function to return 0.0 (these 2 things are working)

What we want to happen if the distance is between min and max is that every time the distance between the listener and the sound is doubled, the volume falloff number is halved (so if the min distance is 1 then at a distance of 2 the return would be 0.50, at 4 it would be 0.25, at 8 it would be 12.5 etc). Can anyone help me with the math for this?

##### Share on other sites

I think it should be:

((distance - max) / (min - max))^2

clamped between 0 and 1 (reaches 1 at distance = min, and 0 at distance = max)

Although keep in mind that this is only a very loose approximation of "real" sound falloff; in real life sound does not fall off with the inverse square of distance except in laboratory scenarios, because sound has a large wavelength so reflective surfaces, diffraction and atmospheric conditions have a very significant effect on how far sound propagates... but it's probably okay for a game

Edited by Bacterius

##### Share on other sites

You should use 1/r instead of 1/r^2 to be physically correct for sound. The sound intensity falls off as 1/r^2, but sound pressure (what you hear) falls off as 1/r.

##### Share on other sites

Ok so we have a test map with a sound that has a max value of 15 (where it starts getting quieter) and a min value of 30 (where it stops completly)

http://www.wolframalpha.com/input/?i=Plot[%28%28d+-+30%29+%2F+%2815+-+30%29%29,+{d,+15,+30}] is a graph of linear falloff and http://www.wolframalpha.com/input/?i=Plot[%28%28d+-+30%29+%2F+%2815+-+30%29%29+^+2,+{d,+15,+30}] is a graph of logarithmic falloff. Which one would sound more like real life would sound? (this is an FPS game btw)

Guessing that the 1/r mentioned by Aressera matches the "linear falloff" graph.

##### Share on other sites

Neither. The way you are proposing, with a min and max value, while maybe good for artists, is not physically correct. I would try both and see which sounds the best in your case. Realistically, there should be no minimum, but even this will not sound very good.

The issue is that realistic sound involves computing the equivalent of global illumination to handle the indirect sound (very important for realism), and it's not as easy to fake as with light because 100+ bounces must be computed, not just a few. Most games totally ignore the indirect sound or fake it using an artificial reverberator. The result is that the ratio of direct to indirect sound does not behave the same as in the real world, and this ratio is critical for distance perception and realistic localization.

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 24
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633695
• Total Posts
3013373
×