initial import of OpenAL native implementation

This commit is contained in:
Brian Matzon 2002-08-11 15:56:00 +00:00
parent 6b87bd6d20
commit e81da42a24
2 changed files with 233 additions and 0 deletions

View File

@ -0,0 +1,114 @@
/**
* $ID$
*
* This is the actual JNI implementation of the OpenAL utility library.
* It handles whatever is needed for proper OpenAL support via using Java.
*
* @author Brian Matzon <brian@matzon.dk>
* @version $Revision$
*/
#include "org_lwjgl_openal_ALUT.h"
/* OpenAL includes */
#include <alut.h>
/**
* This function initializes OpenAL.
*
* C Specification:
* void alutInit(int *argc, char *argv[]);
*/
JNIEXPORT void JNICALL Java_org_lwjgl_openal_ALUT_alutInit (JNIEnv *env, jobject obj, jobjectArray jargv) {
/* obtain the size the array */
jsize argc = (*env)->GetArrayLength(env, jargv);
/* Declare a char array for argv */
const char* argv[128];
int i;
for (i=0;i<argc;i++) {
/* obtain the current object from the object array */
jobject string = (*env)->GetObjectArrayElement(env, jargv, i);
/* Convert the object just obtained into a String */
const char *str = (*env)->GetStringUTFChars(env, string, 0);
/* Build the argv array */
argv[i] = str;
/* Free up memory to prevent memory leaks */
(*env)->ReleaseStringUTFChars(env, string, str);
}
/* Increment argc to adjust the difference between Java and C arguments */
argc++;
/* call the actual implementation */
alutInit(&((int)argc),(char**) argv);
}
/*
* This function loads a WAV file into memory from a file.
*
* C Specification:
* ALboolean alutLoadWAVFile(const char *fname, ALsizei *format, ALsizei *size, ALsizei *bits,
* ALsizei *freq, ALboolean *loop );
*/
JNIEXPORT jobject JNICALL Java_org_lwjgl_openal_ALUT_alutLoadWAVFile (JNIEnv *env, jobject obj, jstring file) {
/*
* NOTE: Since Java doesn't support modification of supplied
* variables (pass by value). We will return a class that
* holds what is needed to unload the file again.
* The data field contains the offset at whcih the data
* segment begins (ie. a pointer). This will *not* work
* on 64 bit platforms, since we use an jint for this.
*/
/* actual file info object */
jobject alutLoadWAVFile_object = NULL;
/* class type to find */
jclass alutLoadWAVFile_class = NULL;
/* method id - will be set to constructor of alutLoadWAVFile */
jmethodID methodID = NULL;
/* sound data vars */
jint format, size, freq;
jboolean loop;
void* data;
ALbyte* filename = (ALbyte*) ((*env)->GetStringUTFChars(env, file, 0));
/* load wave file */
alutLoadWAVFile(filename, &format, (void**) &data, &size, &freq, &loop);
/* get class */
alutLoadWAVFile_class = (*env)->FindClass(env, "org/lwjgl/openal/ALUTLoadWAVFile");
/* get constructor */
methodID = (*env)->GetMethodID(env, alutLoadWAVFile_class, "<init>", "(IIIIZ)V");
/* create object */
alutLoadWAVFile_object = (*env)->NewObject(env, alutLoadWAVFile_class, methodID, format, (int) data, size, freq, loop);
return alutLoadWAVFile_object;
}
/**
* This function loads a WAV file into memory from another memory location.
*
* C Specification:
* ALvoid alutLoadWAVMemory(ALbyte *memory,ALenum *format,ALvoid **data,ALsizei
* *size,ALsizei *freq,ALboolean *loop)
*/
JNIEXPORT void JNICALL Java_org_lwjgl_openal_ALUT_alutUnloadWAV (JNIEnv *env, jobject obj, jint format, jint data, jint size, jint freq) {
alutUnloadWAV(format, (void**) data, size, freq);
}
/**
* This function exits OpenAL.
*
* C Specification:
* void alutExit(ALvoid);
*/
JNIEXPORT void JNICALL Java_org_lwjgl_openal_ALUT_alutExit (JNIEnv *env, jobject obj) {
alutExit();
}

View File

@ -0,0 +1,119 @@
/**
* $ID$
*
* This is the actual JNI implementation of the OpenAL core. It handles
* whatever is needed for proper OpenAL support via using Java.
*
* @author Brian Matzon <brian@matzon.dk>
* @version $Revision$
*/
#include "org_lwjgl_openal_CoreAL10.h"
/* OpenAL includes */
#include <al.h>
/**
* This function returns the current error state and then clears the error state.
*
* C Specification:
* ALenum alGetError(ALvoid);
*/
JNIEXPORT jint JNICALL Java_org_lwjgl_openal_CoreAL10_alGetError (JNIEnv *env, jobject obj) {
return alGetError();
}
/**
* This function retrieves an OpenAL string property.
*
* C Specification:
* ALubyte * alGetString(ALenum pname);
*/
JNIEXPORT jstring JNICALL Java_org_lwjgl_openal_CoreAL10_alGetString (JNIEnv *env, jobject obj, jint param) {
return (*env)->NewStringUTF(env, alGetString(param));
}
/**
* This function generates one or more buffers.
*
* C Specification:
* ALvoid alGenBuffers(ALsizei n,ALuint *buffers);
*/
JNIEXPORT void JNICALL Java_org_lwjgl_openal_CoreAL10_alGenBuffers (JNIEnv *env, jobject obj, jint n, jintArray buffers) {
int* array = (*env)->GetIntArrayElements(env, buffers, 0);
alGenBuffers(n, array);
(*env)->ReleaseIntArrayElements(env, buffers, array, 0);
}
/**
* This function generates one or more sources.
*
* C Specification:
* ALvoid alGenSources(ALsizei n,ALuint *sources);
*/
JNIEXPORT void JNICALL Java_org_lwjgl_openal_CoreAL10_alGenSources (JNIEnv *env, jobject obj, jint n, jintArray sources) {
int* array = (*env)->GetIntArrayElements(env, sources, 0);
alGenSources(n, array);
(*env)->ReleaseIntArrayElements(env, sources, array, 0);
}
/**
* This function fills a buffer with audio data.
*
* C Specification:
* ALvoid alBufferData(ALuint buffer,ALenum format,ALvoid *data,ALsizei size,ALsizei freq);
*/
JNIEXPORT void JNICALL Java_org_lwjgl_openal_CoreAL10_alBufferData (JNIEnv *env, jobject obj, jint buffer, jint format, jint data, jint size, jint freq) {
alBufferData(buffer, format, (void**) data, size, freq);
}
/**
* This function sets an integer property of a source.
*
* C Specification:
* ALvoid alSourcei(ALuint source,ALenum pname,ALint value);
*/
JNIEXPORT void JNICALL Java_org_lwjgl_openal_CoreAL10_alSourcei (JNIEnv *env, jobject obj, jint source, jint param, jint value) {
alSourcei(source, param, value);
}
/**
* This function plays a source.
*
* C Specification:
* ALvoid alSourcePlay(ALuint source);
*/
JNIEXPORT void JNICALL Java_org_lwjgl_openal_CoreAL10_alSourcePlay (JNIEnv *env, jobject obj, jint source) {
alSourcePlay(source);
}
/**
* This function stops a source.
*
* C Specification:
* ALvoid alSourceStop(ALuint source);
*/
JNIEXPORT void JNICALL Java_org_lwjgl_openal_CoreAL10_alSourceStop (JNIEnv *env, jobject obj, jint source) {
alSourceStop(source);
}
/**
* This function deletes one or more sources.
*
* C Specification:
* ALvoid alDeleteSources(ALsizei n,ALuint *sources);
*/
JNIEXPORT void JNICALL Java_org_lwjgl_openal_CoreAL10_alDeleteSources (JNIEnv *env, jobject obj, jint n, jintArray source) {
int* array = (*env)->GetIntArrayElements(env, source, 0);
alDeleteSources(n, array);
(*env)->ReleaseIntArrayElements(env, source, array, 0);
}
/**
* This function deletes one or more buffers.
*
* C Specification:
* ALvoid alDeleteBuffers(ALsizei n,ALuint *buffers);
*/
JNIEXPORT void JNICALL Java_org_lwjgl_openal_CoreAL10_alDeleteBuffers (JNIEnv *env, jobject obj, jint n, jintArray buffer) {
int* array = (*env)->GetIntArrayElements(env, buffer, 0);
alDeleteBuffers(n, array);
(*env)->ReleaseIntArrayElements(env, buffer, array, 0);
}