Thursday, June 10, 2010

Code to convert .mp3 or .wav audio file to iPhone .caf format

iPhone likes to work with audio files compressed with ima4 and wrapped in the .caf format. On OS X the afconvert command will do this, but I needed something for linux. So I wrote some C code to do the conversion I needed: wav2caf.c

wav2caf takes a wav file as input, and outputs an ima4-compressed .caf file suitable for playing on the iphone. For source code, build, and install instructions, download here.

Caveats: This source code expect the wav file to be 22050 Hz and single channel. SOX will convert just about any audio file (e.g. mp3, m4a) to this format with a command such as "sox -r 22050 -c 1 output.wav"

There's not much to the source file. wav2caf.c looks a bit like aifc2wav, because that's what I started with, then reversed it, sort of. Good luck. If you make improvements let me know.

No comments:

Post a Comment