Game Development Reference
In-Depth Information
Listing 7-5. Java/C Audio Handlers
// jni_quake.c
extern int paint_audio (void *unused, void * stream, int len);
JNIEXPORT jint JNICALL Java_quake_jni_Natives_PaintAudio
( JNIEnv* env, jobject thiz, jobject buf )
{
void *stream;
int len;
stream = (*env)->GetDirectBufferAddress(env, buf);
len = (*env)->GetDirectBufferCapacity (env, buf);
paint_audio (NULL, stream, len );
return 0;
}
// snd_android.c
qboolean SNDDMA_Init(void)
{
// most of the wav files are 16 bits, 22050 Hz, stereo
dma.samplebits = 16;
dma.speed = 22050;
dma.channels = 2;
LOGD("SNDDMA_Init Speed %d channels %d", dma.speed, dma.channels);
dmapos = 0;
// Sample size
dma.samples = 32768;
dma.samplepos = 0;
dma.submission_chunk = 1;
dmasize = (dma.samples * (dma.samplebits/8));
dma.buffer = calloc(1, dmasize);
snd_inited = 1;
return 1;
}
Audio initialization in Listing 7-5 consists of telling Quake II information about its format,
such as
Resolution : 16 bit
Frequency : 22 kHz
Number of channels : Two for stereo
Buffer size
Search WWH ::




Custom Search