Converting audio to CAF format for playback on iPhone using OpenAL

63,351

Solution 1

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

References:

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

Share:
63,351
Dave Verwer
Author by

Dave Verwer

Freelance and independent iOS developer and and author of iOS Dev Weekly

Updated on July 05, 2022

Comments

  • Dave Verwer
    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
    Sergio Acosta over 15 years
    May I ask how or where did you find out the answer?
  • Jay
    Jay over 13 years
    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
  • Devang
    Devang over 12 years
    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
    Devang over 12 years
    Is it possible for Mac or windows ?
  • Rafael Sanches
    Rafael Sanches almost 12 years
    is this method compatible with adding to UILocalNotification? It compress much better than the first method.
  • Nurbol
    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
    Admin about 10 years
    @KristopherJohnson both links broken.
  • Chandni - Systematix
    Chandni - Systematix about 10 years
    Error couldn't open input file (-43) what should I do ?
  • Hashem Aboonajmi
    Hashem Aboonajmi over 9 years
    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
  • Kamil Nomtek.com
    Kamil Nomtek.com about 9 years
    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.
  • Nuthatch
    Nuthatch over 6 years
    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"