Objective-C Audio experiment

July 5, 2009 § Leave a comment

I couldn’t find any good information on Audio performance and quality. I am sharing my experiement here.

System Audio Services, declared in AudioToolbox/AudioServices.h only supports .caf, .aif, or .wav files. The audio data in the file must be in PCM or IMA/ADPCM (IMA4) format.  The file’s audio duration must be less than 30 seconds.

AVAudioPlayer supports .m4a, .mp3, .wav, .aif, and .caf.

Simulator is not a reliable tool to test and verify audio performance and quality.

  • AudioServicePlaySystemSound doesn’t play 128 bitrate 44,100 sampling rate wave, aif and caf audio files on simulator even it plays on device
  • Simulator won’t be able to reproduce the speaker sound
  • Simulator can’t tell the audio performance between AudioServicePlaySystemSound & AVAudioPlayer

Using the same .wav audio file, by default, AVAudioPlayer is much much louder than AudioServicePlaySystemSound on device. Both sound the same on simulator. I suspect iphone use different hardware mechanism to play AudioServicePlaySystemSound and AVAudioPlayer.

I don’t notice much differences in audio quality among audio formats in .wav, .aif, .caf, .mp3, .m4a in device & simulator. However for the same audio file, the file sizes are much smaller in m4a (44KB), and mp3 (96MB), compared to wav (1MB), AIF (1MB), and CAF (1MB). File sizes do not correspond to rendering time based on profiling on simulator.

Which Audio format to consider for iphone app

July 1, 2009 § 1 Comment

I am reporting my experiment here. I use a single simple audio file stereo 128 bitrate with 44,100 sample rate M4a file.

Original file size in M4A: 44KB

Conversion Results:

MP3 96KB (Switch)
WAV 1MB (Switch)
AIF 1MB (Switch)
CAF 1MB (Audacity)

I use another MP3 audio file to test the conversion.

Original file size in M4A: 16KB

Conversion Results:

AIF 96KB (Switch)
WAV 96MB (Switch)
CAF 96KB (Audacity)
AAC 14.5KB (iTune)
AAC 24KB (Gargage Band)

These conversion results indicate MP3 & M4A are by far the smallest in file sizes. Nothing is gained from converting from Mp3 or M4A to wave, aif, even caf, most preferred apple audio format Apple Core Audio.

It seems like M4A is the best audio format for file size. However, it is difficult to find open source free audio conversion to convert Mp3 to M4A. Switch, Audacity won’t support MP3/M4A conversion. Using iTune is not convenience to locate the final audio file location.

If you have a very small audio file in Mp3, you gain very little from converting to M4A. In this case, my Mp3 file is 16KB and converted AAC (Equivalent to M4A) is 14.5KB.

I never find any articles on audio file comparison. I have been using the assumed popular audio format. I learn my lessons here.

Audio File Size MP3 vs M4A

July 1, 2009 § Leave a comment

I am reporting the impact of bitrate on audio file size in both MP3 & M4A. Here I use a single simple sound file.


64 kbps (52KB)
128 kbps (100KB)
192 kbps (148KB)


64 kbps (32KB)
128 kbps (44KB)
192 kbps (52KB)

Note: kbps refers to bitrate and KB refers to file size.

You can keep a high bitrate in M4A with much smaller file size. This is a small audio file. You will see more dramatic reduction if you use an audio with much longer audio length.

MP3 vs M4A

July 1, 2009 § Leave a comment

M4A stands for MPEG 4 Audio. MP4 has better quality and smaller file size than MP3. Unlike MP3, M4A does not require any licenses or payments to stream and distribute content. MP3 requires you to pay royalities on content you distribute in MP3 format.

M4A files tend to sound much better than MP3 files encoded at the same bitrate.

Audio Quality based on Sample Rate and Bit Rate

July 1, 2009 § 2 Comments

Sampling rate refers to sound frequency range, from 8,000 to 96,000. Usually 8,000 is selected for audio recording, 44,100 is for CD recording, and 96,000 is for film theater recording.

The higher sampling rate the file is, the wider the frequency range is. Highs will be higher, lows will be lower; higher is better quality. You won’t notice the differences on lower quality headphones or speakers. The quality difference will be noticeable in high quality headphones and speakers.

Bit rate refers to how many “bits” of space the file takes per sec of audio. The higher the bit rate, the higher quality the audio is.

Of course high sampling rates and high bit rates would give the best quality. However sampling rates do not affect file size as much as bit rates.

When you save audio in wave you will be selecting audio quality based on sample types. WHen you save audio in mp3, your audio quality is based on bitrate.

Sample Rates:

  • 8,000
  • 11,025
  • 16,000
  • 22,050
  • 32,000
  • 44,100
  • 48,000
  • 88,200
  • 96,000

Sample Types:

  • 8 bit
  • 16 bit
  • 24 bit
  • 32 bit
  • 32 bit float


  • 16 kbps
  • 18 kbps
  • 20 kbps
  • 24 kbps
  • 32 kbps
  • 40 kbps
  • 48 kbps
  • 56 kbps
  • 64 kbps
  • 80 kbps
  • 96 kbps
  • 112 kbps
  • 128 kbps
  • 160 kbps
  • 192 kbps
  • 224 kbps
  • 256 kbps
  • 320 kbps

AVFoundation framework AVAudioPlayer supports the following:

  • mp3
  • m4a
  • caf
  • aif
  • wav

Objective-C AVAudioPlayer

April 25, 2009 § Leave a comment

This gives a summary of AVAudioPlayer. AVAudioPlayer is part of AVFoundation framework. AVFoundation framework is only available after iPhone OS 2.2.

  • play multiple audio simultaneously
  • provide each audio volume control
  • allow to mix audio
  • support 2 extra format .mp3, m4a in addition to .caf, .aif., and .wav
  • play loop
  • read audio play time
  • select one channel for mono or two channels for stereo audio
  • read audio duration
  • read audio output level

To play multiple audio simultaneously, create a new AVAudioPlayer object for each sound. Design your audio player like a multitrack mixing board. Each AVAudioPlayer object is one track.

Objective-C AudioServicesPlaySystemSound

April 25, 2009 § Leave a comment

This gives a summary of AudioServicesPlaySystemSound. It assists you to decide if this is best option to play audio in your iphone app.

  • audio must be less than 30 sec
  • audio must be PCM or IMA4 formats
  • audio must be in .ca, .aif, or .wav
  • audio can’t play from memory
  • audio play from disk files
  • audio play immediately
  • audio play at existing sound level
  • audio can’t play loop
  • audio can’t manage stereo

Objective-C Troublesome MPVolumeView

April 19, 2009 § 1 Comment

This is probably the only way to control the system volume. However MPVolumeView is poorly documented with little flexibility.

MPVolumeView is part of MediaPlayer. If you use the MediaPlayer to play the audio, it calls up a stand-alone screen.

Below is a work around to use MPVolumeView to control the system volume for the app, not specific to play a single audio file.

Add framework MediaPlayer.framework to your project.

Add this line to .h header file:
#import <MediaPlayer/MediaPlayer.h>

Add code to .m source file:
volumeView = [[[MPVolumeView alloc] initWithFrame:CGRectMake(200,100,100,200)] autorelease];
[volumeView sizeToFit];
[self.view addSubview:volumeView];

Basically when the users change volume, the system volume will change immediately. It provides you the UISlider so you don’t have to create UISlider object.

However the application is very limited. First it won’t work at all for landscape orientation. No matter how you customize it with UISlider properties and rotate it, it won’t work. Secondly, avoid to put it to – (void)viewDidLoad method on the MainViewController, it would crash.

Putting the MPVolumeView on the main app is not a good idea. Many apps leave the volume control on views other than the MainView.

From researching around, I’ve found a Notification class you can use for volume change. I should alert that it is not tested.

[[NSNotificationCenter defaultCenter] addObserver:self

// Method

- (void) volumeChanged:(NSNotification *)notify
[volumeView _updateVolumeFromAVSystemController];

Optimized uncompressed audio file for iPhone SDK Development

April 18, 2009 § Leave a comment

It is possible to keep the sample rate as high as 44,100 Hz, CD quality on uncompressed audio.

The most important decision you would have to make are the Sample Format type and quality.

Even .mp3 is one-tenth of audio file size compared to .wav, .mp3 is considered a compressed audio files. It may be ideal for system sound for audio less than 30 sec for playing a sound at a time.

For multiple audio file playing, it is ideal to take the extra time and efforts to use .caf audio files, optimized for Apple iPhone. .caf is uncompressed.

These are valuable tips in keeping the audio files optimized for audio intensive applications. Reduce the silence heading and tail of audio. Or even fade out ending portion of audio. Consider starting the audio at a prompt starting point.

Improving Workflow in Audio Preparation for iPhone SDK development

April 18, 2009 § Leave a comment

Apple offers command line on Mac OS X to convert multiple files to preferred audio format for iPhone in CAF (Apple Core Audio File).

However, very often your raw audio files are not production-ready. It means that it requires optimization. You would need to use many optimized audio files so your audio files won’t be CPU-intensive, taking up too much memory, or even halt the application.

Audacity allows you to edit the audio and export it to preferred audio format without taking extra steps on command line.

You can set your preference. Select CAF (Apple Core Audio File) as Header. You can select Encording Signed 16 bit PCM.

Other options:

  • Signed 8 bit PCM
  • Signed 16 bit PCM
  • Signed 24 bit PCM
  • Signed 32 bit PCM
  • Unsigned 8 bit PCM
  • 32 bit float
  • 64 bit float
  • U-LAW
  • A-LAW
  • GSM 6.10
  • 32kbs G721 ADPCM
  • 24kbs G723 ADPCM
  • 12 bit DWVW
  • 16 bit DWVW
  • 24 bit DWVW
  • 16 bit DPCM
  • 8 bit DPCM

Other combination options:

  • AIFF (Apple/SGI 16 bit PCM)
  • AIFF (Apple/SGI 32 bit PCM)
  • AIFF (Apple/SGI 8 bit PCM)

This is important to note that you are exporting Uncompressed Export Format. Keep in mind that you won’t be able to play multiple compressed audio files.

My experience is don’t try to use the highest quality audio hoping the app will adjust the audio play experience. Highest audio sample rate 96,000 Hz, theater quality, probably won’t deliver the same hearing experience. 44,100 Hz is the CD quality for music. 8,000 Hz is for voice recording.

Audacity Sample Rate Options:

  • 32-bit float
  • 24-bit
  • 16-bit

Audacity 7 Standard Rate Options:

  • 96,000
  • 44,100
  • 22,050
  • 16,000
  • 11,025
  • 8,000

Most iPhone SDK recording app is using 8,000 Hz for voice digital recording on iphone.

SampleRate is the number of samples that will be captured per second.

FormatID is used to set the codec (compressor/decompressor) that will be used for recording. PCM stands for Pulse-code modulation and is uncompressed audio data.

RecordState audio;

audio.dataFormat.SampleRate = 8000.0;
audio.dataFormat.FormatID = kAudioFormatLinearPCM;
audio.dataFormat.FramesPerPacket = 1;
audio.dataFormat.ChannelsPerFrame = 1;
audio.dataFormat.BytesPerFrame = 2;
audio.dataFormat.BytesPerPacket = 2;
audio.dataFormat.BitsPerChannel = 16;
audio.dataFormat.Reserved = 0;
audio.dataFormat.FormatFlags =
                kLinearPCMFormatFlagIsBigEndian |
                kLinearPCMFormatFlagIsSignedInteger |

At this point there is very little to almost none information on best practices and audio combination in optimized music or audio-intensive iPhone SDK Applications.

Where Am I?

You are currently browsing the Audio category at Web Builders.


Get every new post delivered to your Inbox.