Working with Audio in iPhone Applications

iPhone OS SDK’s AVAudioPlayer class supports many different audio file formats:

  • AAC
  • HE-AAC
  • AMR
  • ALAC
  • iLBC
  • IMA4
  • linear PCM
  • µ-law and a-law
  • MP3

Different formats consumes CPU resources differently.  Specifically, AAC, MP3 , and ALAC (Apple Lossless) uses hardware-based decoding and the device can play only a single instance of one of these formats at a time through hardware.

Then there’s the file size issue.  Compressed formats such as AAC and MP3 can make your application a lot smaller.  For example, 64kbps MP3 can pack one minute of audio in 100KB.  Using an uncompressed format such as AIFF or WAV can be as large as 1MB or more per minute of audio.

Then, there’s the complexity of audio looping.  AVAudioPlayer class supports looping during playback.  With compressed formats, looping can get tricky.  Unless the MP3 file was created specifically for precise looping, you are better off using an uncompressed format such as AIFF or WAV.

With proper manipulation, you can still control the size of an AIFF file by adjusting the data format and sampling rate.  The application afconvert on Mac OS X can do that very nicely.  I find the combination of AIFF with I8 and 22,050 hz sampling rate gives me reasonable audio in AIFF format:

    afconvert -f AIFF -d I8@22050 input.aif output.aif

This generally results in an AIFF file that is about 25% the size of the original since most AIFF files uses 16-bit and sampled at 44.1 kHz.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: