Take the 2-minute tour ×

I'm having a hard time trying to record something other than linear PCM on the iPhone :-( The samples I've found (SDK's SpeakHere, Zdziarski's and Sadun's books and the one at trailsinthesand.com) all use linear PCM but I'd like a commonly used compressed format instead (no ima4 or whatever the name is...).

I just cannot figure out how to tweak the sample code to be used with, for example AAC, MP3 or AMR instead. Any suggestions and hints for how to do that are much appreciated!

(Btw, I do not think an MP3-encoder nor AMR-encoder are available due to licensing issues, but AAC does exist, or???)

Edit/Update: I stumbled upon the following text in Apple's "iPhone Application Programming Guide", 2009-01-06, page 137, section: Recording Audio:
"You can record audio in any of the formats listed in “Preferred Audio Formats in iPhone OS” (page 140)", and as preferred audio formats on page 140 are: "For compressed audio when playing one sound at a time, and when you don’t need to play audio simultaneously with the iPod application, use the AAC format packaged in a CAF or m4a file."
Thus, I interpret that as a clear indication that it is indeed, not only possible, but even preferable, to record audio in AAC format wrapped up in a m4a file, which is just what I want. But still, I am not able to achieve that?!

Thanks, /John

share|improve this question
add comment

5 Answers

up vote 4 down vote accepted

Keep looking at those docs. In "Core Audio Essentials", the section "Core Audio Plug-ins: Audio Units and Codecs" notes that:

iPhone OS contains the recording codecs listed in Table 2-5. As you can see, neither MP3 nor AAC recording is available. This is due to the high CPU overhead, and consequent battery drain, of these formats.

Table 2-5 lists several formats, but as the text notes does not include the ones you're looking for. If you want those formats you'll have to bring your own encoder.

share|improve this answer
Thanks for the reference to that documentation! That makes it clear that I have to get an external encoder. –  John Lane Mar 24 '09 at 20:57
add comment

It is possible in iPhone 3GS and iPod 2nd generation and above. They have a hardware enconder for AAC. There is an Apple example project for this that does exactly what you want to do:


share|improve this answer
add comment

A tip for using faac to convert from iPhone-output linear pcm files to aac format:

I found by experimentation that you have to use the -X flag on the command-line version of faac (running on Mac OS X), which "swaps the input bytes." (I guess it changes the endian-ness.)

So, for example, if you audio recorded the file linear.pcm on your iPhone, you could then run:

faac -XP linear.pcm

on your mac to convert that into the aac file linear.aac.

I'm guessing this means you might be able to use faac within your app to do the conversion, if you wanted to, since it's a C library.

Also note that, technically, the files output by iPhone's audio services are usually CAF files, Core Audio Format, which is sort of a wrapper format around a bunch of possible encodings: Apple's docs on CAF. The above command line works fine for me even though linear.pcm starts with the caff header.

share|improve this answer
add comment

Have you tried Lame mp3 encoder? Or faac/faad AAC codecs? You can embed them in ffmpeg for even more audio codecs.

share|improve this answer
I'd rather not use yet another lib if that can be avoided, so no, I have not tried any of those libs. For example, it sure must be possible to record in AAC on iPhone without resorting to external tools, right? –  John Lane Mar 24 '09 at 11:04
From developer.apple.com/iphone/library/documentation/MusicAudio/…, AAC, MP3 and AMR should be natively available on iPhone. I suggested open source alternatives because I thought that this didn't match your needs. –  mouviciel Mar 24 '09 at 11:40
I think these codecs all are capable decoders but when it comes to encoding I do not think MP3 and AMR is capable. I do not know about AAC. Again, my question is: how do I tweak the existing samples to use something other than linear PCM? –  John Lane Mar 24 '09 at 11:57
add comment

Why don't try TPAACAudioConverter written by the legendary Michael Tyson ?


share|improve this answer
add comment

Your Answer


