[Fwd: openal optimizations (fwd)]

Ryan C. Gordon ryan at epicgames.com
Thu Sep 19 13:51:54 EDT 2002


Here's that OpenAL info.

--ryan.



---------- Forwarded message ----------
Date: Mon, 16 Sep 2002 08:09:33 -0700
From: J. Valenzuela <valenzuela at treyarch.com>
To: Ryan C. Gordon <icculus at clutteredmind.org>
Subject: openal optimizations

Dear Ryan;

Vanity compelled me to read the ut2k3 readme and I saw you were asking
about openal optimizations.  I've put together some areas where you
might find exploration fruitful.  In no particular order:

1) --enable-optimizations

Worth mentioning.  This enables processor specific instructions to for
deployment you have to specify a target architecture ( like pentium
pro ) if you want amd users to use it.

2) --enable-empty-locks

When you allocate/deallocate sources in the same thread that you set
source attributes you can try disabling source locking.  By default
the locking is slightly neurotic, but not schizophrenic.

3) lrintf

I did a little preliminary profiling last night and it looks we spend
a lot of time (still!) doing float->int conversion.  I've added a
define to use an explicit call to lrintf instead of relying on the
default float->int conversion in both alf_tpitch and _alFloatMul.  To
enable this, change the USE_LRINT define in src/al_siteconfig.h.  When
I'm satisfied with it I plan to introduce an extension token for use
with alHint.

4) multichannel audio

If you have stereo sources for stuff like music you want to make sure
to use multichannel audio so that you don't get it converted to the
internal format.  You can check for the presence of the extension
alBufferWriteData_LOKI.  It's just like alBufferData except it takes
an internal format hint argument.


#include <AL/alexttypes.h>

int do_music()
{
    PFNALBUFFERWRITEDATAPROC alBufferWriteData;

    ...

    alBufferWriteData = (PFNALBUFFERWRITEDATAPROC)
         alGetProcAddress((const ALubyte *) "alBufferWriteData_LOKI");

    if(alBufferWriteData)
    {
       alBufferWriteData(bid, format, data, size, freq, format);
    }
    else
    {
       alBufferData(bid, format, data, size, freq);
    }

    ...

    return 0;
}

Conversion happens *in-place* if needed atm so don't specify a format
hint wider/bigger than the first format arg.  This is on my to-fix
list.

5) sampling rate / context creation frequency

In a similar vein with point 4, make sure your context and device are
using the same sampling rate.  If they aren't, a lot of fruitless
conversions will take place.

#include <AL/al.h>
#include <AL/alc.h>

...

int init()
{
   const ALubyte *devspec = (const ALubyte *) "'((sampling-rate 
22050)(devices '(alsa)))";
   const ALubyte *safedev = (const ALubyte *) "'((sampling-rate 
22050)(devices '(null)))";
   int attrlist[] = { ALC_FREQUENCY, 22050, 0 };
   ALCDevice *dev;
   ALCContext *cc;

   dev = alcOpenDevice(devspec);
   if(!dev)
   {
      dev = alcOpenDevice(safedev);
   }
   assert(dev);

   cc = alcCreateContext(dev, attrlist);
   if(!cc)
   {
      alcCloseDevice(dev);
      return -1;
   }

   ...

   return 0;
}


--
jv


.





More information about the ut2003 mailing list