What are the best practices for playing sounds in iPhone games? Specifically, what are the best practices while playing sounds simultaneously without affecting other processing much. Is there any recommendation about how sound files must be made to suit the processing?
From Technical Note TN2199, relative to the use of OpenAL
Use the alBufferDataStatic API, found in the oalStaticBufferExtension.h header file, instead of the standard alBufferData function. This eliminates extra buffer copies by allowing your application to own the audio data memory used by the buffer objects.
If your application renders several audio buffers simultaneously, you should typically use a lower sample rate, such as 22kHz. When rendering a single source, a 44.1kHz sample rate may be most efficient. Experiment and analyze the performance of your application. Individual circumstances determine the best tradeoff between sample rate and the number of audio sources being rendered.
A link with general audio tips for iPhone.
And my personal opinion:
- Preload the sounds into memory ( load screens is the better place for this ).
- Use formats with high compression to take less memory. Like .ogg.
- To the musics, try to load them via streaming, because them can occupy a lot of memory.
- The spacial sounds ( sounds with a position ) needs to be mono, if the game needs them, it's a memory saving.
- Put a sample limit, more than 5 or six sounds at same time can be confusing and they don't contribute.
If your game is developed in c++, you can use a library like cAudio or make yourself a OpenAL wrapper, these approach has the benefit that you only has the functionality that you needs.
Rule of thumb: don't allocate/deallocate memory into gameplay. This is applicable to sounds and the other resources like images.
there is a game engine named cocos2D, and it contains an audio engine named cocosdenshion. it's a three layer object oriented sound engine. you can easily select a layer and starting working with that. and it's all based on openAL, you can surly get enough ideas from cocosdension even if you don't want to use it directly. and it's under MIT License so you can use that without any worry.