Game Development Reference
In-Depth Information
All in all, because of the multiplatform nature of today's mobile landscape (iPhone, Android,
Blackberry, Symbian, and others), most game developers build their engines in portable C.
Then they simply build wrappers to target a specific platform, be it Objective-C for the
iPhone or Java in Android. Keeping that in mind, in this section you will learn how to
cascade the most important events for gaming—audio, video, key, and touch—by using thin
Java wrappers. Let's start with audio.
Handling Audio Independently
Google has made it difficult in Android to handle audio directly on the native side. Before
version 2.x of the SDK, it was simply not worth it to try to implement audio handling natively.
Google used a very obscure audio implementation in the early days (Enhanced Audio
System or EAS), although slowly but surely it has been turning to open standards such as
OpenAL (Audio Library). Nevertheless, I still find it simpler just to read the native audio buffer
and play it using the standard Android AudioTrack API.
Tip The MediaTrack API gives you the power of handling audio independently of the format.
Behind the scenes, the API will detect the binary format and call the appropriate audio driver for any
format supported by the platform: WAV, MP3, OGG, etc.
The process of handling audio directly on the native side can be summarized as follows:
1.
The game engine loads audio assets typically from game files. Audio
assets are simply audio files such as wave (wav) and Ogg Vorbis
(ogg).
2.
The game engine typically initializes the audio hardware and defines
the overall audio properties, such as frequency (in Hz), audio
resolution (16- vs. 32- bit), and number of channels (2 for stereo,
1 for mono).
3.
Whenever an audio event occurs in the game, such as the player
fires a gun or jumps, the engine plays the specific raw audio assets
by writing an audio buffer to the device hardware.
Warning Handling audio in the native side only via OpenAL is not supported in Android versions
prior to 3. Nevertheless, it is the most efficient way of doing it. On the other hand, using a thin Java
wrapper works in all Android versions. It is a bit slower, however.
 
Search WWH ::




Custom Search