Game Development Reference
In-Depth Information
You'll find playing music and audio using the SimpleAudioEngine is straightfor-
ward, as shown here:
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"blues.mp3" loop:YES];
[[SimpleAudioEngine sharedEngine] playEffect:@"alien-sfx.caf"];
You may want to preload sound effects especially when the game starts, to avoid a
small delay when each sound effect is first played. This is also easily accomplished:
[[SimpleAudioEngine sharedEngine] preloadEffect:@"alien-sfx.caf"];
For music and longer speech files, playing MP3 files is the preferred choice. Note that
you can play only one MP3 file in the background at a time. Technically, it's possible
to play two or more MP3 files, but only one can be decoded in hardware. The extra
strain on the CPU is undesirable for games, so playing multiple MP3 files at the same
time, or merely crossfading two music tracks, is something you might want to avoid
unless your app's design calls for it.
This also means that short-lived sound effects should not be in MP3 format. For those
audio effects, I've had good experiences with 16-bit PCM (uncompressed) audio in
either the WAV or CAF file format. The sampling rate can be 22.5 kHz for most game
sound effects, unless you need or want crystal-clear audio quality, in which case use
44.1 kHz.
A good and complete audio-editing tool for Mac OS X is Audacity, which you can
download for free from http://audacity.sourceforge.net . If you need
only to quickly convert audio files from one format to another, possibly changing some
basic settings such as sampling rate, I recommend SoundConverter, which was deve-
loped by Steve Dekorte. The tool is free to use for files up to 500KB in size, and the li-
cense to use SoundConverter without restrictions is just $15. You can download
SoundConverter from http://dekorte.com/projects/ shareware/SoundCon-
verter/.
A free alternative to SoundConverter is the command-line tool afconvert . Familiar-
ity with Terminal is recommended. You can do a lot with afconvert , but being a
command-line tool, you'll also have to type a lot. To get help for afconvert , open
the Terminal app and type the following:
afconvert -h
Search Nedrilad ::




Custom Search