Converting audio to CAF format for playback on iPhone using OpenAL
Asked Answered
M

5

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?

Murky answered 31/10, 2008 at 16:19 Comment(1)
Thought I'd push you over the "999" edge, Dave !Lingerie
M
191
afconvert -f caff -d LEI16@44100 -c 1 in.wav out.caf

References:

Murky answered 31/10, 2008 at 22:34 Comment(6)
May I ask how or where did you find out the answer?Fettle
@KristopherJohnson both links broken.Flatt
Error couldn't open input file (-43) what should I do ?Caskey
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 extensionTiossem
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.Milky
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"Callow
I
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
Intimidate answered 10/3, 2010 at 1:2 Comment(4)
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 errorsLegendary
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 ?Nib
Is it possible for Mac or windows ?Nib
@Nib 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.Michele
F
17

this is the best for size:

afconvert -f caff -d ima4 original.wav

Frequentative answered 1/5, 2012 at 0:14 Comment(0)
L
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

Lamori answered 16/11, 2008 at 19:24 Comment(1)
is this method compatible with adding to UILocalNotification? It compress much better than the first method.Toting
C
4

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

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

Compliancy answered 27/2, 2013 at 1:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.