[openal] distance model questions

Chris Robinson chris.kcat at gmail.com
Mon May 11 14:51:16 EDT 2015

On 05/10/2015 10:44 PM, Victorious wrote:
> Hi,
> I've trying to set up openal-soft so that sounds are played properly
> depending on my current coordinate system. For example, I'd like
> sounds which are a distance of 0.5 and below from the listener to
> appear as if they are centred in the stereo field. Right now, if the
> listener is at (3.9, 3.9, 0.0) and a sound source is at (4.0, 4.0,
> 0.0), it still appears to come fairly far from the right. Hence,
> moving right from that position to somewhere just right of that sound
> causes a quick panning of the sound from right to left which I don't
> want.
> I'm using the default inverse distance clamped model. From the openal
> specification, it looks like the parameters I need to set are
> AL_REFERENCE_DISTANCE and AL_MAX_DISTANCE. I cant to get the desired
> effect though, so any help will be greatly appreciated.

The distance model doesn't really have an effect on panning, just how it 
attenuates with distance (theoretically an implementation could produce 
different panning results for different attenuation models, but nothing 
too different).

Even though it's less than a unit away, a sound that's 45 degrees off 
center is panned about 70% to one side. If you want a smoother 
transition, you have to make the sound move slower. One technique I've 
made use of before is to lerp the source's real position with 0,ref,0 or 
0,-ref,0 (relative to the listener position/orientation) when it's 
within ref_distance units of the source. Though I know this isn't an 
ideal solution.

At one point, OpenAL Soft blended in a centered panning as the source 
moved within the reference distance. I removed this though, since other 
implementations didn't necessarily do it and it didn't work with HRTF, 
so it was unreliable/inconsistent behavior. I've been considering 
bringing the behavior back through the AL_EXT_SOURCE_RADIUS[1] 
extension, rather than implicitly using the reference distance, but 
there's an unfortunate conflict with AL_SOFT_buffer_sub_data as they 
both use the enum value 0x1031 for a source property.

[1] https://icculus.org/alextreg/wiki/AL_EXT_SOURCE_RADIUS

> On a related question, what does clamping do? And how does rolloff
> factor affect these calculations? i.e what does the default value of
> 1 mean?

Clamping clamps the calculated distance between the ref_distance and 
max_distance for the purposes of distance attenuation. That is, a source 
that's more than max_distance units away will be as quiet as 
max_distance units, and a source that's closer than ref_distance units 
will sound as loud as ref_distance units.

The rolloff factor affects how fast it attenuates from the ref_distance. 
perceived_distance = (real_distance - ref_distance)*rolloff_factor +
So a rolloff factor of 1 means perceived_distance = real_distance, and a 
rolloff factor of 2 means it will sound twice as many units away from 
ref_distance (farther *or closer*) as it really is.

More information about the openal mailing list