73

I am using the SoundEngine sample code from Apple in the CrashLanding sample to play back multiple audio files. Using the sample caf files included with CrashLanding everything works fine but when I try and use my own samplesconverted to CAF using afconvert all I get is a stony silence ;)

Does anyone have settings for afconvert that will produce a CAF file capable of being played back through OpenAL?

1
  • Thought I'd push you over the "999" edge, Dave !
    – user279521
    Jul 28, 2010 at 17:24

5 Answers 5

190
afconvert -f caff -d LEI16@44100 -c 1 in.wav out.caf

References:

6
  • May I ask how or where did you find out the answer? Oct 31, 2008 at 22:54
  • @KristopherJohnson both links broken.
    – user234736
    Mar 7, 2014 at 6:09
  • Error couldn't open input file (-43) what should I do ? Mar 25, 2014 at 3:54
  • you need to run the above code in the terminal. in.wav is the location of sound (just drag & drop the sound file), and out.caf is output path of the sound with .caf extension Oct 13, 2014 at 9:30
  • 5
    Great, but this reduces channels from 2 to 1, essentially: it's a conversion from stereo to mono! If this is not what you want, just remove "-c 1" from the command. Apr 7, 2015 at 18:55
51

Simple bash script to convert the mp3 files in a folder to caf for iphone

#!/bin/bash
for f in *.mp3; do
  echo "Processing $f file..."
  afconvert -f caff -d LEI16@44100 -c 1 "$f" "${f/mp3/caf}"
done
4
  • 1
    To make the script more compatible with different file types, I modified the afconvert line to: afconvert -f caff -d LEI16 "$f" "${f/mp3/caf}" otherwise I would get errors
    – Jay
    Dec 17, 2010 at 4:28
  • Can you tell me where do I store this string ? I don't know anything abouy bash script. In which format I have to store it ?
    – Devang
    Sep 10, 2011 at 7:03
  • Is it possible for Mac or windows ?
    – Devang
    Sep 10, 2011 at 7:40
  • 1
    @Devang it's easily done in Mac, just open up TextEdit, save the text to a file, then open up Terminal, navigate to your saved file, type: chmod +x <filename> to make it executable, and use it directly. If you use something like Cygwin on Windows you can do the same thing.
    – powerj1984
    Aug 30, 2012 at 20:00
17

this is the best for size:

afconvert -f caff -d ima4 original.wav

4

thanks for the info.

also, if you're looking into additional compression with openAL, this might be of interest:

"iPhone, OpenAL, and IMA4/ADPCM" http://www.wooji-juice.com/blog/iphone-openal-ima4-adpcm.html

1
  • 1
    is this method compatible with adding to UILocalNotification? It compress much better than the first method. Apr 30, 2012 at 17:49
4

It looks like the -c is not working today, I got it with following:

afconvert -f caff -d LEI16 input.m4a output.caf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.