Advertisement

Inverse square law for sound falloff

Started by January 23, 2016 04:30 AM
3 comments, last by Aressera 8 years, 7 months ago

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?

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 smile.png

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Advertisement

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.

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.

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.

This topic is closed to new replies.

Advertisement