[openal] distance model questions

Victorious dtvictorious at gmail.com
Tue May 26 10:18:55 EDT 2015


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. 

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. 

-----Original Message-----
From: openal [mailto:openal-bounces at openal.org] On Behalf Of Chris Robinson
Sent: Monday, May 25, 2015 3:54 PM
To: openal mailing list
Subject: Re: [openal] distance model questions

On 05/25/2015 12:34 AM, Victorious wrote:
> I've just implemented it, and it works very well for simulating 
> axis-aligned planes/lines/solids, except for the fast panning. How do 
> I do the interpolation for this case to prevent it? There are 3 values 
> - x/y/z range, 1 sound radius value for each axis.

In that case, you can combine the two methods, first clamping the source position to the area then lerping based on distance:

float listenerX, listenerY, listenerZ;
alGetListener3f(AL_POSITION, &listenerX, &listenerY, &listenerZ);

x = clamp(listenerX, center_x - x_range, center_x + x_range); y = clamp(listenerY, center_y - y_range, center_y + y_range); z = clamp(listenerZ, center_z - z_range, center_z + z_range);

math::float3 listenerPos(listenerX, listenerY, listenerZ);
math::float3 sourcePos(x, y, z);

float dist = listenerPos.Distance(sourcePos); if(dist < radius) {
     math::float3 polarPos;
     if(sourcePos.z >= listenerPos.z)
         polarPos = listenerPos + math::float3(0, 1, 0);
     else
         polarPos = listenerPos - math::float3(0, 1, 0);

     math::float3 lerped = polarPos.Lerp(sourcePos, dist/radius);
     x = lerped.x;
     y = lerped.y;
     z = lerped.z;
}
alSource3f(source, AL_POSITION, x, y, z); _______________________________________________
openal mailing list
openal at openal.org
http://openal.org/mailman/listinfo/openal



More information about the openal mailing list