We hear sound effects and music in almost every type of media we encounter daily. Many notable games such as Pac-Man, Angry Birds, and Fruit Ninja can be recognized just by their theme music or sound effects alone. Aside from the visual imagery we see in games, sounds help impact the mood conveyed in the storyline and/or during game play. Quality sound effects and music that pertain to the theme of your game helps give a realistic feel to the experience.
In this chapter, you will learn how to apply sound effects and music that can be added to your applications. You have the visual appeal down from creating Breakout and Panda Star Catcher in the previous chapters. Now, let's enhance the sensory experience for our ears!
The main points you'll be going over are:
Let's create some more magic!
The Corona audio system has advanced Open Audio Library (OpenAL) features. OpenAL is designed for the efficient rendering of multichannel three-dimensional positional audio. The general functionality of OpenAL is encoded in source objects, audio buffers, and a single listener. A source object contains a pointer to a buffer, the velocity, position and direction of the sound, and the intensity of the sound. Buffers contain audio data in the PCM format, either 8- or 16-bit, in either mono or stereo format. The listener object contains the velocity, position and direction of the listener, and the general gain applied to all sounds.
For more information on the Corona audio system, you can go to http://developer.coronalabs.com/partner/audionotes. General information on OpenAL can be found at http://www.openal.org.
The following are the sound formats that are compatible with iOS and Android platforms:
.wav
format.mp3
, .aif
, .caf
, and .aac
formats.mp3
, .aif
, .caf
, .ogg
, and .aac
formats.mp3
and .ogg
formats.mp3
and .ogg
formatsFile extensions are ignored when building in Android, so files are considered the same regardless of the extension. The workaround for the mean time is to change the filenames to differentiate between file extensions. See the examples listed here:
tap_aac.aac
tap_aif.aif
tap_caf.caf
tap_mp3.mp3
tap_ogg.ogg