Game Development Reference
In-Depth Information
// *** SEE SOUND NAMES CLASS ***
} musicnamesWL6;
*/
public static final int [] Music = new int[27];
static {
Music[0] = R.raw.mus_emnycrnr;
Music[1] = R.raw.mus_emnycrnr;
Music[2] = R.raw.mus_marchwar;
Music[3] = R.raw.mus_getthem;
// *** SEE SOUND NAMES CLASS ***
Music[26] = R.raw.pacman;
}
}
Besides sounds, Wolf 3D implements background music, which is processed in the same exact way.
The difference being that background music is big and plays once, whereas sounds are tiny and can play
multiple times during the game. Wolf 3D uses 27 music files defined in the C header audiowl6.h in the
native/gp2xwolf3d folder (see the chapter source code for details). With the mappings in place, the
AudioManager can do its work.
Creating the Audio Manager
AudioManager is a singleton helper class that manages all audio and performs the following tasks:
It starts a sound given its native ID.
It starts background music given its native ID.
It cashes commonly used sounds for better performance.
AudioManager uses a HashMap for clip caching:
HashMap<String, AudioClip> mSounds = new HashMap<String, AudioClip>();
When a sound request comes along, the method void startSound(int sidx) will be invoked where
sidx is the ID of the native sound. Next, the Android resource ID will be extracted using the SoundNames
class:
int id = SoundNames.Sounds[sidx];
Finally, the cache table will be queried. If the table contains the sound, it will be played from cache.
Otherwise, the sound will be loaded from disk and cached for the next event:
if (mSounds.containsKey(key)) {
Search WWH ::




Custom Search