In this tutorial I create a simple sound manager class that can play back multiple sounds using OpenAL. It also allows you to play background music as well using the AVAudioPlayer class.
The reason for writing my own sound manager was to see how OpenAL works. Commenters on this blog provided some great links, see the "Sound of music... explosions and lasers", so I decided to work through them and get something working.
This class is simple and provides basic access to playing sounds in OpenAL. It also makes use of all 32 sources OpenAL sources available on the iPhone so that the same sound can be played simultaneously which is great for explosions and laser fire.
One item I have not yet got into the class is 3D sound. OpenAL give you the ability to position the listener in 3D space and to also position each source of sound in 3D space. OpenAL will then work out depending on where the listener is in relation to the sound source what the sound should sound like i.e. volume, pitch etc. The API for this looks simple enough but I've not had time to try it out and wanted to get the core class tutorial published. I will take a look at this area and post any changes I make to the class.
A big thanks goes to www.benbritten.com there is a great OpenAL tutorial on there about getting going with the basics needed and its this well written tutorial which got me off the ground, so a real thanks to Ben.
As usual, please post any questions, suggestions, or issues you spot with the code and I hope you enjoy the tutorial.