[openal] distance model questions

Victorious dtvictorious at gmail.com
Tue May 26 15:35:35 EDT 2015


Hm, just thought of this: could the following be better? 

The inverse rolloff clamped model is used when distance(source, listener) <= threshold% of sound's hearing range. Otherwise, a custom formula or an alternative distance model is used.

I plugged some numbers into the linear models, and it looks like gain doesn't hit 0 when sound is at max_distance (not sure why I thought it did).
// with a rolloff factor of 1,
gain = (1 - (distance - referenceDistance) / (maxDistance - referenceDistance));

Looks like the only way to have 0 gain is if refDistance = distance and/or maxDistance = referenceDistance.

From: openal [mailto:openal-bounces at openal.org] On Behalf Of Chris Robinson
Sent: Tuesday, May 26, 2015 11:56 PM
To: openal mailing list
Subject: Re: [openal] distance model questions

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 farther away.

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.
_______________________________________________
openal mailing list
openal at openal.org
http://openal.org/mailman/listinfo/openal



More information about the openal mailing list