Game Development Reference
In-Depth Information
From the digital perspective, a monaural or monophonic sound (mono for short), is nothing
more than a long one-dimensional array of values representing a continuous signal.
Stereophonic or multichannel sounds are represented by a few channels and stored as
interleaved arrays, where the sample from one channel is followed by the sample from the
other channel and so on. OpenAL expects us to submit this data as a sequence of buffers.
The main concepts of OpenAL library are devices, contexts, listeners, audio sources, and
sound buffers :
Sound wave
(air pressure)
Analog-to-Digital
converter
Physical sound
source
Microphone
Random
Access
Memory
Central Processing Unit
Storage (files)
Sound wave
(air pressure)
Digital-to-Analog
converter
Listeners
Speaker
The sound produced in a virtual environment is played back through the speakers after
processing by a sequence of ilters. The material covered in this chapter will allow you to
create a portable audio subsystem for your game.
Initializing OpenAL and playing the .wav iles
In this recipe, we present the simplest possible example to play uncompressed audio iles in
PCM format (pulse-code modulation, http://en.wikipedia.org/wiki/Pulse-code_
modulation ). This example just plays a single ile in an ininite loop. We will create a single
device, a single device context, and an audio source. All of this is done in a single dedicated
thread, but we should not worry about multithreading issues because OpenAL functions are
guaranteed to be thread-safe.
Getting ready
The source code and build scripts for the OpenAL library can be found in the 0_OpenAL folder,
and precompiled static libraries are included with each of the examples for this chapter. For
Windows, we use dynamic linking with OpenAL. Explanations on how to load iles from the
Android .apk package can be found in the Chapter 4 , Organizing a Virtual Filesystem . The
complete source of the example for this recipe can be found in the 0_AL_On_Android folder.
 
Search WWH ::




Custom Search