Game Development Reference
In-Depth Information
Sound System Changes
Other changes are required to i_sound.c to insert a call to jni_start_sound , as shown in Listing 7-20. The
global variable S_sfx[id].name provides the sound name, which will be sent back to Java and loaded
from the file system, along with its volume.
Listing 7-20. Changes Required to i_sound.c to Insert the jni_start_sound Callback
int I_StartSound(int id, int channel, int vol, int sep, int pitch, int priority)
{
const unsigned char* data;
int lump;
size_t len;
// ...
// The entries DSBSPWLK, DSBSPACT, DSSWTCHN
// and DSSWTCHX are all zero-length sounds
if (len<=8) return -1;
/* Find padded length */
len -= 8;
// Do the lump caching outside the SDL_LockAudio/SDL_UnlockAudio pair
// Use locking which makes sure the sound data is in a malloced area and
// not in a memory mapped one
data = W_LockLumpNum(lump);
// JNI changes: Send a sound request to Java
// id is the sound index, S_sfx[id].name (soundname)
// vol = volume
jni_start_sound(S_sfx[id].name , vol);
// ...
return channel;
}
Changes are also required to s_sound.c to insert a call to jni_set_music_volume (volume) to send the
background music volume back to Java (see Listing 7-21). Note that this function is called within the
game when the user changes the music volume from the options menu.
Listing 7-21. Changes Required to s_sound.c to Insert the Music JNI Callback
void S_SetMusicVolume(int volume)
{
// Return if music is not enabled
if (!mus_card || nomusicparm)
return;
if (volume < 0 || volume > 15)
Search WWH ::




Custom Search