OpenAL programming faq

OpenAL Lite Programming FAQ

How could I determine maximum sources number available for OpenAL ?
Many people use alut for OpenAL initialization and do not know it’s simple to do yourself. You will gain additional control over device and context by doing so.
Do not use alut for that!

  1. Choose audio device (by name or using NULL as name for default device, usually the best hardware driver available)
  2. You can skip this step : create context attributes:
    ALCint attrs[] = {
    ALC_STEREO_SOURCES, stereo_sources,
    ALC_MONO_SOURCES, mono_sources,
    ALC_INVALID, ALC_INVALID,
    }; //stereo_sources and mono_sources are OpenAL hints. Minimal and working for the most people value - 16. Note that stereo source use 2 real mono source. So if you have music thread, only 14 mono sources remain available.
  3. create contexrt alcCreateContext(alc_device, attrs);
  4. Get context attributes:
    ALCInt attr_size;
    alcGetIntegerv(alc_device, ALC_ATTRIBUTES_SIZE, sizeof(attr_size), &attr_size);
    const ALCInt * attributes = (ALCint *)malloc(attr_size * sizeof(ALCint));
    alcGetIntegerv(alc_device, ALC_ALL_ATTRIBUTES, attr_size, attributes);
    Now ‘attributes’ points to the context attributes, arranged as attrs[] array from (2).


How could I open non-default device?

alcGetString(NULL, ALC_DEVICE_SPECIFIER) doesn’t only return default device string. It returns all devices supported by OpenAL, arranged in the following manner:
“Generic Hardware”, 0, “Generic Software”, 0, 0
Just for sanity you could check the presence of ALC_ENUMERATION_EXT, but as long as I remember, OpenAL 1.1 made it mandatory. (fix me?)

I do not want OpenAL mixer thread, I want mixer working from my own thread.

It’s very easy : use attribute ALC_SYNC set in AL_TRUE. Call alcProcessContext(context); from your worker thread.

I’m experiencing weird errors or crashes. What should I do ?

Check the following conditions in your code:

  1. After every single OpenAL call, you call alGetError() and process critical errors for your code. alGetError cleans internal OpenAL error state.
  2. You call alGenSources once while your application starts. You do not use alGetSources(&source, 1); every time you need a single source.
  3. Have debian-amd64? Try my openAL build. Do not forget report bug against debian bug tracker system. OpenAL mistakenly use mmx ia32 builtins on x86_64 architecture. At least disabling all __MMX__ dependent sources helps.

16 sources is not enough. I have more than hundred objects on single level.

You don’t need all hundred sources playing simultaneously. :) OpenAL does not have any source manager. You should write it yourself or take from another project. (Do not forget to read the license)

  1. OpenAL initialization
  2. Tracking object positions, remove distant sounds.
  3. Restart previously removed loops. (helicopters or such)

How could I create stereo source playing music without 3d attenuation.

Set the following source attributes:
alSourcei (source, AL_SOURCE_RELATIVE, AL_TRUE);
alSourcef (source, AL_ROLLOFF_FACTOR, 0.0);
To restore 3d state set it back to default values (AL_FALSE and 1.0 respectively)

©2007 Vladimir Menshakov, Netive Media Group.