I can't understand how to limit playing sound to the distance of the source to the audio listener position

I can’t understand how to limit playing sound to the distance of the source to the audio listener position.
I want to limit it to 100 WU from source to listener but it not working: setMaxDistance(100).
what is the usage of setRefDistance()?

You should read the javadoc for setMaxDistance() because you misunderstand what it means.


1 Like

I read it, before.
limiting distance is not possible?

At a quick glance it is likely that one might misunderstand the javadoc especially if you are not familar with the word ‘attenuated’. MaxDistance is not the distance at which sound is no longer audible- it is the distance at which the sound is no longer being reduced.

Setting the refDistance is how you determine the rate at which audio is reduced over distance. So If you set the maxDistance too low while refDistance is too high, then the volume is liable to never drop off to 0 (fully inaudible) regardless of how far away you are.



And I quote the javadoc which more or less says similar: “Max distance sets where this fall-off stops and the sound will never get any quieter than at that distance. If you want a sound to fall-off very quickly then set ref distance very short and leave this distance very long.

Emphasis added.


I also found this behaviour irritating. I created my own (if I’m honest kind of hacky) sound nodes which keep track of the “ears” location and turn themselves off and on automatically at a “max range”. This allows me to have small situational noises without running out of audio channels.

As far as I’m aware there isnt a way to get a max range on audio nodes without something like that


I would agree. I am curious why the official audio node was written the way it was (using ref distance and max distance) and if there is a good reason for it? Currently it can be hard to fine-tune a sound’s proper volume over distance. But maybe that is just the nature of how it must be done to produce realistic sound drop offs? I am curious to know.

My game had botched sound for 2 years until I finally tested a multiplayer game and realized that many of my spell sounds were waaay too loud or too quiet at a distance - but i never knew due to the fact that all of the spell sounds were coming from a first person perspective in solo mode. I never thought to test my sound 10000 units away to ensure it was dropping off as intended, but that is indeed necessary to be sure of.

Having a forced-drop off point like your hacked audio nodes sounds like it would indeed make the fine tuning process for audio node’s a lot less tedious. But also I wonder if it could make the sound drop-off sound less realistic if it is not done carefully?


Because we didn’t. We call OpenAL.

Yes, definitely.

Also, if the audio node is part of your scene and you are paging parts of the scene in and out then the audio node will already be clipped with distance.

Edit: also keep in mind that the reasons OpenAL did it that was is likely because of how the formula works. Distance falloff is some kind if inverse exponential. Where it’s half and then half again and then half again is probably easier to find inputs for than “where it’s zero”… (because it’s basically never 0 in a purely mathematical sense).

It’s easy to make sound fall-off quickly. Set ref distance low and max distance very high. (which is what the javadoc says). Beyond that will require tuning… which is pretty much always going to be the case anyway. We’re only talking about which value to tune. I think openAL doesn’t bother to play the sound anymore when the volume is effectively 0 but someone would have to test it.