views:

69

answers:

1

Have a few questions related to adding sounds to my game, specifically intro music (for splash), background music (loop) and button event sounds. Hope you can share your knowledge on this.

1) Should I use compressed sounds or uncompressed sounds? Or perhaps a combination of the two? Are there any limitations on the iPhone hardware that I should be aware of -- for example, the ability to play multiple compressed sounds?

2) What's the best audio format for my purpose?

3) For background music, I am thinking of using AVAudioPlayer. For button event sounds, I am thinking of using AudioServicesPlaySystemSound, what do you think?

4) Any other issues I should be aware of?

Thank you!

A: 

1) According to the iPhone Application Programming Guide: "Starting in iPhone OS 3.0, nearly all supported audio formats can be used for simultaneous playback—namely, all those that can be played using software decoding, as described in Table 7-1. For the most processor-efficient multiple playback, use linear PCM (uncompressed) or IMA4 (compressed) audio."

But if you're going to be playing a lot of sounds at the same time, you should use either uncompressed or IMA4.

2) You should use the CAF file format because it gives you the most flexibility in what data format to use. You can put MP3, AAC, PCM, IMA4, and pretty much any compressed or uncompressed data in a CAF file (.caf). I typically use CAF files with IMA4 compression at mono, 16-bit, 44.1kHz.

3) That's how I do it in my apps: AVAudioPlayer for voice cues that cause the music levels to duck, and AudioServicesPlaySystemSound for buttons and other UI sound effects.

4) If you use uncompressed PCM data, the file sizes can be huge, but IMA4 is a fairly noisy compression scheme. You can use AAC but then you might be limited by how many AAC sounds you can play at once. Before iPhone OS 3.0, you could only play one AAC or MP3 sound at a time.

lucius
Thanks Lucius, any idea why when I recompress the same caf file over and over using afconvert -f caff -d ima4 audiofile.caf that I get different sizes each time? I will post this in a separate discussion.
Boon