[Openal] Distance model

Tristan Grimmer tri at tactile3d.com
Wed Dec 21 16:41:44 PST 2005


Hi again,

Just trying to figure this out.  The first thing to note is that I'm 
using the Creative SDK installer version of OpenAL1.1.  Not currently 
set up to build and link from source (but might need to... we'll see).
I get the incorrect behaviour of sources making sounds when at gain 0.0 
with the INVERSE_DISTANCE model.  The INVERSE_DIST_CLAMPED doesn't seem 
to be a problem... but I'd rather use INVERSE_DISTANCE as I already have 
a source management scheme.

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->flRollOffFactor)));
       else
          pSource->lAttenuationVolume = 10000;
    }
    break;
...

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?

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 
off?  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 
triggered.

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.

Again, I apologize if I'm missing something.... maybe a lack of 
understanding of the dB scale.  I hope I was looking at the correct 
function.

Regardless, it seems as if setting gain to 0.0 and using the 
INVERSE_DISTANCE model is not working.  Basically in my sound rendering 
update function I set ALL playing sources to gain 0.0 and I still hear 
positional sounds when I get close enough (somewhere inside the 
reference distance).  There seems to be a fairly sharp ramp-up between 
completely silent and full volume as I move closer.

Any thoughts would be appreciated.

--tristan




More information about the Openal mailing list