CAF, or Core Audio Format, is Apple’s native audio container format. It can store both compressed and uncompressed audio and is particularly well suited to audio used inside iOS, tvOS and macOS applications.
CAF is a good choice for sound effects, interface sounds, game audio and other short audio clips because it:
- Handles very short sounds efficiently
- Supports a wide range of audio codecs and sample formats
- Does not have the 4 GB file-size limitation associated with standard WAV files
- Works natively with Apple audio APIs
- Is compatible with AVAudioPlayer, AudioToolbox and SpriteKit methods such as SKAction.playSoundFileNamed
Converting WAV to CAF
macOS includes a command-line utility called afconvert, which can convert audio files without requiring additional software.
To convert a WAV file into a CAF file containing 16-bit, little-endian, signed linear PCM audio, run:
afconvert -f caff -d LEI16 early_exit.wav early_exit.caf
The arguments used in this command are:
- -f caff sets the output container format to Core Audio Format
- -d LEI16 sets the audio data format to little-endian, signed, 16-bit integer PCM
- early_exit.wav is the source audio file
- early_exit.caf is the generated CAF file
Because the output remains uncompressed linear PCM, the conversion does not introduce compression artefacts. The resulting file may be larger than a compressed format such as AAC or MP3, but it can be decoded and played with very little processing overhead.
Choosing an Appropriate Sample Rate
By default, afconvert will generally preserve the source file’s sample rate and channel configuration. For short application sound effects, it may be worth reducing these values when full-quality stereo audio is unnecessary.
For example, the following command creates a mono CAF file at 44.1 kHz:
afconvert -f caff -d LEI16@44100 -c 1 early_exit.wav early_exit.caf
Here:
- @44100 specifies a sample rate of 44,100 Hz.
- -c 1 converts the audio to a single mono channel.
Mono audio can significantly reduce file size and is often sufficient for interface sounds and non-positional effects.
Inspecting the Converted File
You can inspect the resulting file using the afinfo command:
afinfo early_exit.caf
This displays information including:
- Audio data format
- Sample rate
- Channel count
- Duration
- Estimated file size
Checking the output is useful when preparing a large collection of sound effects, as source files may contain inconsistent sample rates, channel counts or bit depths.
Playing CAF Audio in an iOS Application
A CAF file can be played using AVAudioPlayer in the same way as many other supported audio formats:
import AVFoundation
var audioPlayer: AVAudioPlayer?
func playSound() {
guard let url = Bundle.main.url(
forResource: "early_exit",
withExtension: "caf"
) else {
return
}
do {
audioPlayer = try AVAudioPlayer(contentsOf: url)
audioPlayer?.prepareToPlay()
audioPlayer?.play()
} catch {
print("Unable to play audio: \(error)")
}
}
In a SpriteKit application, a short CAF sound can also be played using an action:
let sound = SKAction.playSoundFileNamed(
"early_exit.caf",
waitForCompletion: false
)
run(sound)
CAF Versus WAV
CAF and WAV can both store uncompressed PCM audio, but CAF is often a better fit for Apple-platform development.
WAV is widely supported across different operating systems and audio-editing tools, making it a useful source and interchange format. CAF is more closely integrated with Apple’s Core Audio technologies and supports larger files and more flexible metadata.