Game Development Reference
In-Depth Information
paint_audio : Gets called by the JNI implementation of the Java class
NativeAudio.PaintAudio , described in the “Handling Audio” section.
The Java audio handler will use a thread and loop around calling
NativeAudio.PaintAudio .
NativeAudio.PaintAudio : Uses its JNI companion to call paint_audio to
store audio bytes from the Quake audio buffer into the Java audio buffer,
which will then be played using the Android MediaTrack API.
Tip
snd_android.c is located in the topic source under ch06.Quake/jni/Quake/android .
Listing 6-15. Quake Audio Handler for Android
// in snd_android.c
// This function is called from JNI to fill the audio buffer
// params: stream (Java audio buffer), len: stream size
int paint_audio (void *unused, void * stream, int len)
{
if (!snd_inited)
return 0;
if (shm) {
// make the quake au buffer point to stream
shm->buffer = (unsigned char *)stream;
shm->samplepos += len / (shm->samplebits / 4);
// write sound bytes to stream
S_PaintChannels (shm->samplepos);
return len;
}
return 0;
}
// Audio Initializer
qboolean SNDDMA_Init(void)
{
/* Most of the wav files are 16 bits, 22050 Hz, mono */
/* Fill the audio DMA information block */
shm = &sn;
shm->samplebits = 16;
// malloc max : 7 MB => -12 MB !!
shm->speed = 22050;
shm->channels = 2;
LOGD("SNDDMA_Init Speed %d channels %d", shm->speed, shm->channels);
 
Search WWH ::




Custom Search