4

I'm in the process of porting an application from Windows to Mac OS X. It is using OpenAL for handling the sound, but I'm getting a strange behavior in the initialization of the sound engine on Mac OS X (the code is running on a MacBook Pro).

Here is the code:

int InitSoundEngine(void* data[NB_BUFFERS], size_t data_size[NB_BUFFERS])
{
    ALCdevice *device;
    ALCcontext *context;
    ALenum format;
    ALuint buffers[NB_BUFFERS];

    device = alcOpenDevice(NULL);
    if (device == NULL)
        goto failed;

    context = alcCreateContext(device, NULL);
    if (context == NULL)
        goto failed;

    alcMakeContextCurrent(context);

    format = alGetEnumValue("AL_FORMAT_51CHN16");
    if (format == 0)
        goto failed;

    alGenBuffers(NB_BUFFERS, buffers);
    if (alGetError() != AL_NO_ERROR)
        goto failed;

    for (int i = 0; i < NB_BUFFERS; ++ i)
    {
        alBufferData(buffers[i], format, data[i], data_size[i], 48000);
        if (alGetError() != AL_NO_ERROR)
            goto failed;
    }

    return NO_ERROR;

 failed:
    /* Cleanup omitted for brievety */
    return INITIALIZATION_FAILED;
 }

This fails when during the call to alBufferData, with an error of AL_INVALID_VALUE. While tracing the code, we discovered that alGetEnumValue("AL_FORMAT_51CHN16") is returning 0xfffffffful, and we suspect this is the root of the issue.

The alGetEnumValue says:

ALuint alGetEnumValue(const ALchar *enumName);

Returns 0 if the enumeration can not be found, and sets an AL_INVALID_VALUE error condition. The presence of an enum value does not guarantee the applicability of an extension to the current context. A non-zero return indicates merely that the implementation is aware of the existence of this extension.

I think I use the function correctly. Is there a bug in the Mac OS X implementation of OpenAL ? Is 5.1 output supported via OpenAL on Mac OS X ? Is it supported via Core Audio (porting to Core Audio could be an option if this is true) ? Should I convert my audio from 5.1 to another format (3.1, stereo, ...) ?

Sylvain Defresne
  • 42,429
  • 12
  • 75
  • 85

1 Answers1

3

That enum belongs to the AL_EXT_MCFORMATS extension. It is not available on Mac OS X.

Yes, CoreAudio can handle 5.1 (or any, I think) speaker setup. I don't know the details of how to feed it data though.

OneSadCookie
  • 296
  • 1
  • 2