Converting audio to CAF format for playback on iPhone using OpenAL
Solution 1
afconvert -f caff -d LEI16@44100 -c 1 in.wav out.caf
References:
- Apple's Multimedia Programming Guide: Using Audio: Preferred Audio Formats in iOS
-
afconvert(1) man page (use
afconvert -h
for complete info)
Solution 2
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
Solution 3
this is the best for size:
afconvert -f caff -d ima4 original.wav
Solution 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
Dave Verwer
Freelance and independent iOS developer and and author of iOS Dev Weekly
Updated on July 05, 2022Comments
-
Dave Verwer almost 2 years
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?
-
Sergio Acosta over 15 yearsMay I ask how or where did you find out the answer?
-
Jay over 13 yearsTo 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
-
Devang over 12 yearsCan 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 over 12 yearsIs it possible for Mac or windows ?
-
Rafael Sanches almost 12 yearsis this method compatible with adding to UILocalNotification? It compress much better than the first method.
-
Nurbol over 11 years@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.
-
Admin about 10 years@KristopherJohnson both links broken.
-
Chandni - Systematix about 10 yearsError couldn't open input file (-43) what should I do ?
-
Hashem Aboonajmi over 9 yearsyou need to run the above code in the terminal.
in.wav
is the location of sound (just drag & drop the sound file), andout.caf
is output path of the sound with.caf
extension -
Kamil Nomtek.com about 9 yearsGreat, 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.
-
Nuthatch over 6 yearsNote 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"