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?

Chris Hanson
  • 54,380
  • 8
  • 73
  • 102
Dave Verwer
  • 6,140
  • 5
  • 34
  • 30

5 Answers5

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

References:

Kristopher Johnson
  • 81,409
  • 55
  • 245
  • 302
Dave Verwer
  • 6,140
  • 5
  • 34
  • 30
  • May I ask how or where did you find out the answer? – Sergio Acosta Oct 31 '08 at 22:54
  • @KristopherJohnson both links broken. –  Mar 07 '14 at 06:09
  • Error couldn't open input file (-43) what should I do ? – Chandni - Systematix Mar 25 '14 at 03: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 – Hashem Aboonajmi Oct 13 '14 at 09: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. – Kamil Nomtek.com Apr 07 '15 at 18:55
  • Note the `LEI16@44100` specifies the format of the wave file. This would be a common default: little-endian integer 16-bit at 44.1 kHz sampling rate. If your output file sounds like noise, check the wave file format. "Get Info" in Finder will show channels, sample rate, and bits per sample under "More Info" – Nuthatch Nov 29 '17 at 03:09
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
tomwilson
  • 1,014
  • 10
  • 12
  • 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 '10 at 04: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 '11 at 07:03
  • Is it possible for Mac or windows ? – Devang Sep 10 '11 at 07: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 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 '12 at 20:00
17

this is the best for size:

afconvert -f caff -d ima4 original.wav

scurioni
  • 2,344
  • 1
  • 18
  • 14
4

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

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

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

Steph Thirion
  • 9,313
  • 9
  • 50
  • 58