[openal] distance model questions

Victorious dtvictorious at gmail.com
Sun May 17 13:29:59 EDT 2015

I've tried it, but it doesn't seem to work properly and creates weird panning effects. Here's what my source setPosition function looks like.

// coordinates converted from Euclidian coordinates to rhs 
if (isPlaying())
		float listenerX, listenerY, listenerZ;
		alGetListener3f(AL_POSITION, &listenerX, &listenerY, &listenerZ);

		math::float3 listenerUp(0.0, 1.0, 0.0), polarPos, listenerPos(listenerX, listenerY, listenerZ); // listenerUp is listener's up orientation
		polarPos = listenerUp*(-1) + listenerPos;
		float dist = polarPos.Distance(listenerPos);
		if (dist < 1) // < default reference distance
			// lerp the source's position with polar pos
			math::float3 lerped = polarPos.Lerp(listenerPos, dist); // 0 replaces sourcePos with polarPos, 1 does the reverse
			x = lerped.x;
			y = lerped.y;
			z = lerped.z;

	alSource3f(source, AL_POSITION, x, y, z);
-----Original Message-----
From: openal [mailto:openal-bounces at openal.org] On Behalf Of Chris Robinson
Sent: Tuesday, May 12, 2015 5:56 PM
To: openal mailing list
Subject: Re: [openal] distance model questions

On 05/12/2015 02:02 AM, Victorious wrote:
> What does ref stand for, the y-coordinate in RHS system of the
> listener?

'ref' is the source's reference distance (1 by default, so that means it 
would be +1 or -1 on the listener's local Y axis, which is the 
orientation's 'up' vector). Basically:

// If the sound source is above the listener's head
polar_pos = listener.up*ref_distance + listener.pos;
// else
polar_pos = listener.up*-ref_distance + listener.pos;

> How does lerping the source with (0, ref, 0) or (0, -ref,
> 0) help?

Lerping it with the above calculated polar position helps prevent the 
sound from panning so strongly when it's near the listener. The closer 
it is to the listener, the less the source's real position influences 
the position the source is set to, thus the less it pans around. So if 
the source was 0.5 units away at a +45 degree angle, rather than a 70% 
pan it would roughly be a 47% pan.

> Also, why is this lerp done when distance(listener, source)
> is < REFERENCE_DISTANCE, and what is the lerp rate that I should use?

You can use any value for the radius you want, although 
REFERENCE_DISTANCE is a sane implicit value (since that's also where the 
sound will stop getting louder as it gets closer, by default). The lerp 
is just a linear interpolation, so when the source is >=radius units 
away the source position is used unmodified, and when it's 0 units away 
the source position is completely overwritten, and when it's at half the 
radius it's a 50% mix of the source's position with the polar position, etc.

> For the conflict, could you just use a different value for the enum?

That would break compatibility, and require a different extension. But 
having multiple "active" extensions for the same behavior isn't that 
nice either.

What I may end up doing is deprecating AL_SOFT_buffer_sub_data (and 
AL_SOFT_buffer_samples, since that borrows the former's enums), and 
replace it with a different extension that doesn't use the offending 
enum value. A configuration option could be made available for apps that 
rely on the buffer_sub_data or buffer_samples, re-exposing those 
extensions and disabling AL_EXT_SOURCE_RADIUS support when set.
openal mailing list
openal at openal.org

More information about the openal mailing list