Mobile native Wearable native

OpenAL

OpenAL is a software interface to audio hardware, which allows you to specify the objects and operations in producing high-quality audio output. Tizen offers OpenAL as a native API, since OpenAL can be used for a variety of audio playback tasks (such as sound effects in games), and it has an excellent performance for real-time rendering. For more information, see OpenAL 1.1 specification.

OpenAL has 3 fundamental objects:

  • Sources

    Sources store various attributes, such as velocity, position, direction, and intensity of the sound, that are used for rendering and have an associated buffer which contains audio data for playback.

  • Buffers

    Buffers store compressed or uncompressed audio data in the PCM format, either 8- or 16-bit, and in the mono or stereo format.

  • Single listener

    Each audio context has only 1 listener. The listener attributes are used to represent where the user is hearing the audio from.

Each object can be changed independently; the setting of one object does not affect the setting of others.

The main features of the OpenAL API include:

  • Creating a context

    You must first open an audio device through which your audio stream flows. After the device is successfully opened, create and activate a context. Once your device is associated with a current context, your commands are applied to that context.

    To create a context:

    // Open default device
    device = alcOpenDevice(NULL); 
    if (device != NULL) 
    {
       // Create context
       context=alcCreateContext(device, NULL); 
       if (context != NULL) 
       {
          // Set active context
          alcMakeContextCurrent(context); 
       }
    }
    

    When your audio stream is no longer needed or inactive for a long time, destroy the context by calling the alcDestroyContext() function.

    Note
    The device cannot fall into a sleep state while the context is not destroyed. To avoid unwanted battery consumption, destroy the context punctually.
  • Requesting a source and buffer

    To play a sound, a source object is required. Through the source, you can update the stream attributes, such as the default gain and the position of the sound.

    In addition, you need an audio buffer that contains your audio data.

  • Controlling the audio stream

    When the source and buffer are ready, you can manage the playback by playing, stopping, rewinding, or pausing your audio stream. All the control commands are operated with the source you have acquired.

To use OpenAL, you must create a context and the initial set of buffers, load the buffers with sample data, create sources, attach the buffers to the sources, set the locations and directions for the listener and sources, and set the initial values for the OpenAL state global.

Go to top