Quick Audio Framework Comparison in SDK 3.0

July 6, 2009 § Leave a comment

Audio Toolkit (AudioToolbox Framework)
It plays audio but it can’t change pitch or loop.

AVAudioPlayer (AVFoundation Framework)
File-based playback of DRM-free audio in Apple-supported codecs.

Audio Queue Services (AudioToolbox Framework)
It can loop audio but it is painful to re-read the data from the file to adjust the playback frequency. C-based API for buffered recording and playback of audio. It would work for a net radio player, or your own formats and/or DRM/encryption schemes (decrypt in memory before handing off to the queue). Inherent latency due to the use of buffers.

OpenAL
Sample can be pre-loaded. It is easy to adjust the frequency and looping. However, quality is suffered when you stop the looping. The built-in 3D positional audio mixer is too CPU-intensive.

Look for example codes “SoundEngine.h”, “CrashLanding” or “TouchFighter” that use OpenAL.

AudioUnits (aka RemoteIO)
RemoteIO is poorly documented and extremely difficult to implement, similar to AudioQueue Services. Low-level C-based API. Very low latency, as little as 29 milliseconds. Mixing, effects, near-direct access to input and output hardware.

SDK 3.0 AVAudioRecorder

July 6, 2009 § Leave a comment

AVAudioRecorder class in 3.0 SDK allow you to record audio in .caf & .aif. If you like to record it in .mp3, you would have to include your own encorder. You can’t change the encorder.

Only changable encorder settings:

  • AVEncoderAudioQualityKey;
  • AVEncoderBitRateKey;
  • AVEncoderBitDepthHintKey;

									

Memory Leak on AudioServicesCreateSystemSoundID from bad conversion habits

July 6, 2009 § Leave a comment

Audio Toolbox Framework & AVFoundation Framework are the most popular audio frameworks to play audio. AudioQueue, part of Audio Toolbox Framework, requires you to manage buffers and byte level.

Mistakes you don’t want to make:

If you think you can convert the file format from .wav to .aif and then rename the extension from .aif to .caf, it may be just a hack and it’s not a good practice at all. This hack will cause a memory leak on the fuction of AudioServicesCreateSystemSoundID. This is something you don’t want to do in your code.

Proper way to convert files to .caf

afconvert -f caff -d ima4 input.wav output.caf

Audio Toolbox Framework

NSString *sound = @"sound";
NSString *path = [[NSBundle mainBundle] pathForResource:sound ofType:@"caf"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPathath], &soundID);
AudioServicesPlaySystemSound(soundID);

AVFoundation Framework

NSString *sound = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"mp3"];
Player =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:sound] error:nil];
[Player prepareToPlay];
[Player play];

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.

MP3

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

M4A

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.

Where Am I?

You are currently browsing the Audio category at Web Builders.

Follow

Get every new post delivered to your Inbox.