views:

1441

answers:

4

What is the recommended audio format for storing and playing back short (2-3 sec) audio sound effects on the iPhone or iToouch?

The iPhone audio SDK documentation indicates that the iPhone supports audio in several formats - however there are drawbacks to each:

  • MP3: This is a highly compressed, but also high-quality encoding format that preserves the richness of music and spoken voice. However, only a single mp3 stream can be played at a time on the iPhone because it requires use of the hardware decoder. This excludes mp3 as a format for sound effects, since they will interrupt background music and/or any user music being played.
  • WAV: The iPhone only supports WAV files if they are PCM - encoded and do not require any compression codecs. While WAV supports many different sampling rates and bit-depths, it results in very large files (180k / sec for 16-bit/44.1kHz/stereo audio). The large size becomes prohibitive when you have many effects to rapidly play.
  • AIFF: Has similar problems to WAV files - it's unclear if any compression codecs are supported. Supposedly Apple Lossless compression is supported - but I can't find any tools that can generate AIFF in using this compression.
  • Custom: You can use the iPhone low-level APIs to play your own audio from any source. But this seems like overkill for playing a simple sound effect in a game. I certainly don't want to write my own audio layer and encoder/decoder just for this.

Any recommendations would be appreciated... it would also be helpful if someone could recommend a reasonably priced tool for processing audio that can generate the recommended format. Thanks.

+5  A: 

You can use IMA4 compressed files, which provide a 1:4 compression from WAV files and are decompressed by hardware (you can load them with an AVAudioPlayer).

As for MP3, you can only play one file simultaneously in that format, that's why it's not recommended for sound effects where you could have more than one at the same time.

I'm using IMA4 files with OpenAL, so I'm decompressing them manually with a code based on this post.

pgb
A: 

I've had pretty good luck with CAF format files although WAV comes close in size.

As for tools, Audacity is free and reasonably functional. I mainly use Amadeus Pro (around US$40). Pretty decent and generates all the iPhone supported audio formats (including MP3, AIFF, WAVE, AAC, and CAF). A nice feature is that it supports AudioUnit and VST plug-ins so you can add SoundFX.

I've also heard good things about Fission (by Rogue Amoeba) but haven't actually used it. Their other audio products are pretty solid.

The AVAudioPlayer framework is pretty good at playing short clips, but you may want to pre-load the sounds (call prepareToPlay) and keep them around if you can spare the memory.

Ramin
I thought CAF was just a container format, and it could contain any of MP3, IMA4, AIFF, etc. Am I wrong?
mahboudz
CAF files can contain other types of file formats as chunks, but they have their own 64-bit header, metadata, and track layout. You still need a converter tool that can import the other types and write to CAF. Here's the spec: http://devworld.apple.com/documentation/MusicAudio/Reference/CAFSpec/CAF_overview/CAF_overview.html
Ramin
A: 

The only format I've been able to get to work is CAF. It is also the one in most the code examples from apple. If you are using short sound effects the size won't be a problem.

+1  A: 

Take a look at the afconvert command line utility on your Mac. It does many conversions between different audio formats, and if you have a lot of sounds, you can script the conversions...

I use SoundToolbox and AVAudioPlayer with sounds mostly in uncompressed linear PCM, created in GarageBand.

SoundToolbox is great for playing a short little "Boing" or "click" or other sounds that you trigger to play and you don't care about stopping or messing with their volume etc.

If you want to stop a playing sound or to know if the sound is done playing, AVAudioToolbox is nice. If you want to play sounds with control over the left and right components of the sound, then look at OpenAL.

If you haven't already, read Apple's iPhone Application Programming Guide on Sound support.

If sound is important to your app, you may want to take advantage of some of features available to you for very little work.

mahboudz