What's the best format for sound effects on iPhone
Asked Answered
F

5

14

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.

Fonz answered 7/8, 2009 at 14:4 Comment(0)
D
11

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.

Derzon answered 7/8, 2009 at 14:12 Comment(2)
not to be a Debby Downer, but it's very easy to play multiple mp3's at the same time. Just use more than one instance of AVAudio player.Vulgate
At least when I posted this answer, this was not the case. AVAudioPlayer only allowed a single MP3 file to be played at once, while a secondary played would show significant delay, and drops. I would guess this is still the case, moreover for games, where you need precise control over when the sound starts.Derzon
E
2

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.

Emylee answered 7/8, 2009 at 19:22 Comment(2)
I thought CAF was just a container format, and it could contain any of MP3, IMA4, AIFF, etc. Am I wrong?Braiding
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: devworld.apple.com/documentation/MusicAudio/Reference/CAFSpec/…Emylee
B
1

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.

Braiding answered 8/8, 2009 at 4:50 Comment(0)
G
0

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.

Greige answered 7/8, 2009 at 21:35 Comment(0)
R
0

I've been using Microsoft ADPCM WAV format which compresses from 3.25:1 (high quality) to 3.98:1 (default quality). Also I reduce sample rate to 32000 or even 22050 depending on the sound. There is no need to save some files in stereo - mono also reduces the size of file pretty well.

For background music mp3 is fine.

Raymond answered 22/11, 2011 at 3:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.