[openal] distance model questions
chris.kcat at gmail.com
Tue May 26 11:56:14 EDT 2015
On 05/26/2015 07:18 AM, Victorious wrote:
> Thanks, that's working pretty well for me.
> I'm trying to do sound culling by distance. What I have so far are
> functions that stop source playback when distance(source, listener)
> >= AL_MAX_DISTANCE (that seems like a good value to use). However,
> I'd like to fine-tune the sound's volume; to preserve the inverse
> model calculations (don't want to switch to linear) but just have it
> fade out faster. Right now, it still sounds quite loud just as the
> listener reaches AL_MAX_DISTANCE before it stops playing.
There generally isn't a need to silence sources at AL_MAX_DISTANCE
specifically. Just set it to a really large value (or leave it at the
default FLT_MAX) so the sound continues to get quieter as it goes
If the problem is that they're too loud when in the distance, then you
can also try decreasing AL_REFERENCE_DISTANCE. Since the reference
distance represents the distance from the sound source where the
listener will hear it at its unmodified volume, you may need to modify
it depending on what exactly the sound is of and what its loudness is.
If that's not enough, you can also try increasing AL_ROLLOFF_FACTOR,
though this can cause sounds to rolloff unnaturally fast.
> My first thought was to do something like 'interpolation' to control
> this; when the source is very close to the listener, there would be
> little modification to the gain, and it would get progressively
> softer and fade to nothing as you leave its max range. How would I do
> that? The distance model I'm using is inverse distance clamped, which
> isn't linear, so I'm not sure how to take that into account.
If the above isn't good enough, a simple way to do this is to lower the
gain the farther the source goes beyond the max distance. So like:
ALfloat gain = 1.0f;
id(dist > max_distance)
gain = max(1.0f - (dist-max_distance)*scale, 0.0f);
alSourcef(source, AL_GAIN, gain);
where 'scale' is the number of units beyond max_distance it needs to be
before truly reaching 0.
More information about the openal