[Openal] Distance model
dpeacock at creativelabs.com
dpeacock at creativelabs.com
Thu Dec 22 08:51:20 PST 2005
> I'm looking at the SetNonEAXSourceLevels function. It appears to
> implement the distance model. But I have some questions:
> I see this:
> switch (pContext->DistanceModel)
> case AL_INVERSE_DISTANCE:
> case AL_INVERSE_DISTANCE_CLAMPED:
> if ((pSource->flMaxDistance >= pSource->flRefDistance) &&
> (pSource->flRefDistance > 0.0f))
> if ((((flDistance - pSource->flRefDistance) /
> pSource->flRefDistance) * pSource->flRollOffFactor) > -1.0f)
> pSource->lAttenuationVolume = (ALint)(-2000 * log10(1.0f +
> (((flDistance - pSource->flRefDistance) / pSource->flRefDistance) *
> pSource->lAttenuationVolume = 10000;
> So my first thought is that the first "if" should not refer to
> flMaxDistance in the AL_INVERSE_DISTANCE case at all. the max distance
> should not have any affect at all with this model... no matter what it's
> value... right?
I'll change the code so that Max Distance only has to be >= Reference
Distance for the Inverse Distance Clamped model.
> My second thought has to do with the second "if". In the
> INVERSE_DISTANCE model, the flDistance can get really small... and the
> expression in the if close to -1... so we get to the
> pSource->lAttenuation = 10000; line. Is that always enough to turn it
In millibels, -10000 is assumed to be silent (at least in Direct Sound),
between -10000 and 0 the sound is attenuated (such that -602mb is half
volume, -1204mb is quarter volume etc ...), 0 is unadjusted gain, and
anything above 0 represents amplification. The non clamped formula
approaches infinite gain as the distance from the listener approaches zero
so there has to be a special case that simply sets an arbitrary high
amplification level (e.g 10000 == 100mb Amplification).
> I'm not sure how it accomplishes this based on how it's used later
> (it gets clamped between -10000 and 0).... and it seems... well,
> discontinuous... the attenuation can get larger before the else is
In Open AL, there are properties for setting the Max Gain possible on a
Source and the Min Gain possible on a Source. These 'clamps' happen after
distance based attenuation and Source Gain attenuation, but before Listener
> The last thing I don't understand is where step 2) (the multiplication
> by the gain) happens. I see a IDirectSoundBuffer_SetVolume, but there
> was no multiplication before that.
The Source Gain (converted to millibels) is added in below all the distance
model attenuation code (line 3744 if you have the latest code). (In a
decibel scale volumes are added together, rather than multiplied as with a
linear scale). On lines 3747 and 3748 the source volume is clamped
according to Min and Max Gains (also converted to millibels).
I think I should probably change this line ...
lVolume = pSource->lVolume + pSource->lAttenuationVolume;
lVolume = (pSource->lVolume == -10000) ? -10000 : pSource->lVolume +
So as to preserve a silent Source (Gain == 0) no matter how much
amplification is set by the distance model (including infinite
Does that make sense ?
More information about the Openal