Using OpenAL on iOS in a PVRShell application

This topic contains 0 replies, has 1 voice, and was last updated by  Martin Kraus 7 years, 2 months ago.

Viewing 1 post (of 1 total)
  • Author
  • #30329


    I know that there are good reasons not to include audio support in the PowerVR SDK. However, I spent a few hours this week to include basic audio support to a simple demo game. Here are a few tips (which would have saved me some hours 😉 but you still have to read about the OpenAL API to know how to actually use OpenAL:

    – A good, free documentation of the OpenAL API is available one, in particular here:

    – A more detailed description is given in “Beginning iPhone Games Development”

    – Good OpenAL/iOS examples are “oalTouch” and “MusicCube”; in particular “oalTouch” comes with two files “MyOpenALSupport.c” and “MyOpenALSupport.h”, which are very useful to load sound files. I had to use
       extern “C” {
       #include “MyOpenALSupport.h”
    to include it in the cpp file. (I’m mentioning this because I never know when it is necessary; thus, I tend to forget it.)

    – It is straightforward to open an OpenAL device and context in a PVRShell application (see the OpenAL documentation); however, it is more difficult to react well to interrupts of the application, e.g. by phone calls or alarms (see the discussion in the “Beginning iPhone Games Development”). Since I’m only programming demos, I tend to ignore these problems

    – To load sound data I came up with this code (probably there are better alternatives):

       #include <CoreFoundation/CFString.h>
            ALenum  error = AL_NO_ERROR;
            ALenum  format;
            ALsizei size;
            ALsizei freq;
            CPVRTString filename = CPVRTResourceFile::GetReadPath() + “Pendulum.wav”;
            CFStringRef cffilename = CFStringCreateWithCString(kCFAllocatorDefault,
                 filename.c_str(), kCFStringEncodingMacRoman);
            CFURLRef fileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cffilename,
                 kCFURLPOSIXPathStyle, false);
            if (fileURL)
                m_BackgroundAudioData = MyGetOpenALAudioData(fileURL, &size, &format, &freq);
                if((error = alGetError()) != AL_NO_ERROR) {
                    PVRShellSet(prefExitMessage, “ERROR: Cannot load sound.”);
                    return false;
                // use the static buffer data API
                alBufferDataStaticProc(m_uiBackgroundAudioBuffer, format,
                   m_BackgroundAudioData, size, freq);           
                if((error = alGetError()) != AL_NO_ERROR) {
                    PVRShellSet(prefExitMessage, “ERROR: Cannot attach audio data.”);
                    return false;
            else {
                PVRShellSet(prefExitMessage, “ERROR: Cannot find file.”);
                return false;

    m_uiBackgroundAudioBuffer has been generated with OpenAL before this code and the buffer is released when quitting the application; m_BackgroundAudioData is of type “void *” and is also released when quitting the application (with “free(m_BackgroundAudioData)”)

    – one good source of sound clips is GarageBand; and I’m using Audacity to convert to mono (which is necessary for the 3d effects of OpenAL).

    Hope this helps,


Viewing 1 post (of 1 total)
You must be logged in to reply to this topic.