Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best format for sound effects on iPhone

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.

like image 549
LBushkin Avatar asked Aug 07 '09 14:08

LBushkin


2 Answers

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.

like image 142
pgb Avatar answered Sep 16 '22 22:09

pgb


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.

like image 40
Ramin Avatar answered Sep 20 '22 22:09

Ramin