diff --git a/src/java/org/lwjgl/openal/ALC.java b/src/java/org/lwjgl/openal/ALC.java new file mode 100644 index 00000000..5fb557a2 --- /dev/null +++ b/src/java/org/lwjgl/openal/ALC.java @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2002 Light Weight Java Game Library Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'Light Weight Java Game Library' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + package org.lwjgl.openal; + +/** + * $Id$ + * + * This is the context class for OpenAL. This class implements functions + * in alc.h + * + * @author Brian Matzon + * @version $Revision$ + */ +public class ALC { + + static { + try { + System.loadLibrary(org.lwjgl.Sys.getLibraryName()); + } catch (UnsatisfiedLinkError ule) { + System.out.println("Failed to load OpenAL library: " + org.lwjgl.Sys.getLibraryName()); + ule.printStackTrace(); + } + } + + /** Creates a new instance of ALC */ + public ALC() { + } + /** + * Returns strings related to the context. + * + * @param device ALCdevice to query + * @param pname Property to get + * @return String property from device + */ + public native String getString(ALCdevice device, int pname); + + /** + * Returns integers related to the context. + * + * @param device ALCdevice to query + * @param pname Property to get + * @param size Size of destination buffer provided + * @param integerdata address of ByteBuffer to write integers to + */ + public native void getIntegerv(ALCdevice device, int pname, int size, int integerdata); + + /** + * Opens the named device. If null is specied, the implementation will + * provide an implementation specic default. + * + * @param devicename name of device to open + * @return opened device, or null + */ + public native ALCdevice openDevice(String devicename); + + /** + * Closes the supplied device. + * + * @param device ALCdevice to close + */ + public native void closeDevice(ALCdevice device); + + /** + * Creates a context using a specified device. + * + * @param device ALCdevice to associate context to + * @param attrList address of ByteBuffer to read attributes from + * @return New context, or null if creation failed + */ + public native ALCcontext createContext(ALCdevice device, int attrList); + + /** + * Makes the supplied context the current one + * + * @param context ALCcontext to make current + * @return true if successfull, false if not + */ + public native boolean makeContextCurrent(ALCcontext context); + + /** + * Tells a context to begin processing. + * + * @param context context that should begin processing + */ + public native void processContext(ALCcontext context); + + /** + * Gets the current context + * + * @return Current ALCcontext + */ + public native ALCcontext getCurrentContext(); + + /** + * Retrives the device associated with the supplied context + * + * @param context ALCcontext to get device for + * @param ALCdevice associated with context + */ + public native ALCdevice getContextsDevice(ALCcontext context); + + /** + * Suspends processing on supplied context + * + * @param context ALCcontext to suspend + */ + public native void suspendContext(ALCcontext context); + + /** + * Destroys supplied context + * + * @param context ALCcontext to Destroy + */ + public native void destroyContext(ALCcontext context); + + /** + * Retrieves the current context error state. + * + * @param device ALDdevice associated with context + * @return Errorcode from ALC statemachine + */ + public native int getError(ALCdevice device); + + /** + * Query if a specified context extension is available. + * + * @param device device to query for extension + * @param extName name of extension to find + * @return true if extension is available, false if not + */ + public native boolean isExtensionPresent(ALCdevice device, String extName); + + /** + * Retrieves the address of a specified context extension function. + * + * @param device device to query + * @param extName name of extension to find + * @return address of function + */ + public native int getProcAddress(ALCdevice device, String extName); + + /** + * retrieves the enum value for a specified enumeration name. + * + * @param device Device to query + * @param enumName name of enum to find + * @return value of enumeration + */ + public native int getEnumValue(ALCdevice device, String enumName); +} \ No newline at end of file diff --git a/src/java/org/lwjgl/openal/ALCcontext.java b/src/java/org/lwjgl/openal/ALCcontext.java new file mode 100644 index 00000000..a1a7ccce --- /dev/null +++ b/src/java/org/lwjgl/openal/ALCcontext.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2002 Light Weight Java Game Library Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'Light Weight Java Game Library' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + package org.lwjgl.openal; + +/** + * $Id$ + * + * Wrapper class, to make ALC contexts behave like the orginal api. + * + * @author Brian Matzon + * @version $Revision$ + */ +public class ALCcontext { + + /** address of actual context */ + public final int context; + + /** + * Creates a new instance of ALCcontext + * + * @param context address of actual context + */ + public ALCcontext(int context) { + this.context = context; + } +} diff --git a/src/java/org/lwjgl/openal/ALCdevice.java b/src/java/org/lwjgl/openal/ALCdevice.java new file mode 100644 index 00000000..b59cd6ba --- /dev/null +++ b/src/java/org/lwjgl/openal/ALCdevice.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2002 Light Weight Java Game Library Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'Light Weight Java Game Library' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + package org.lwjgl.openal; + +/** + * $Id$ + * + * Wrapper class, to make ALC devices behave like the orginal api. + * + * @author Brian Matzon + * @version $Revision$ + */ +public class ALCdevice { + + /** address of actual device */ + public final int device; + + /** + * Creates a new instance of ALCdevice + * + * @param device address of actual device + */ + public ALCdevice(int device) { + this.device = device; + } +} diff --git a/src/native/common/org_lwjgl_openal_ALC.h b/src/native/common/org_lwjgl_openal_ALC.h new file mode 100644 index 00000000..226f9f6c --- /dev/null +++ b/src/native/common/org_lwjgl_openal_ALC.h @@ -0,0 +1,133 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_lwjgl_openal_ALC */ + +#ifndef _Included_org_lwjgl_openal_ALC +#define _Included_org_lwjgl_openal_ALC +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_lwjgl_openal_ALC + * Method: getString + * Signature: (Lorg/lwjgl/openal/ALCdevice;I)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_lwjgl_openal_ALC_getString + (JNIEnv *, jobject, jobject, jint); + +/* + * Class: org_lwjgl_openal_ALC + * Method: getIntegerv + * Signature: (Lorg/lwjgl/openal/ALCdevice;III)V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_openal_ALC_getIntegerv + (JNIEnv *, jobject, jobject, jint, jint, jint); + +/* + * Class: org_lwjgl_openal_ALC + * Method: openDevice + * Signature: (Ljava/lang/String;)Lorg/lwjgl/openal/ALCdevice; + */ +JNIEXPORT jobject JNICALL Java_org_lwjgl_openal_ALC_openDevice + (JNIEnv *, jobject, jstring); + +/* + * Class: org_lwjgl_openal_ALC + * Method: closeDevice + * Signature: (Lorg/lwjgl/openal/ALCdevice;)V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_openal_ALC_closeDevice + (JNIEnv *, jobject, jobject); + +/* + * Class: org_lwjgl_openal_ALC + * Method: createContext + * Signature: (Lorg/lwjgl/openal/ALCdevice;I)Lorg/lwjgl/openal/ALCcontext; + */ +JNIEXPORT jobject JNICALL Java_org_lwjgl_openal_ALC_createContext + (JNIEnv *, jobject, jobject, jint); + +/* + * Class: org_lwjgl_openal_ALC + * Method: makeContextCurrent + * Signature: (Lorg/lwjgl/openal/ALCcontext;)Z + */ +JNIEXPORT jboolean JNICALL Java_org_lwjgl_openal_ALC_makeContextCurrent + (JNIEnv *, jobject, jobject); + +/* + * Class: org_lwjgl_openal_ALC + * Method: processContext + * Signature: (Lorg/lwjgl/openal/ALCcontext;)V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_openal_ALC_processContext + (JNIEnv *, jobject, jobject); + +/* + * Class: org_lwjgl_openal_ALC + * Method: getCurrentContext + * Signature: ()Lorg/lwjgl/openal/ALCcontext; + */ +JNIEXPORT jobject JNICALL Java_org_lwjgl_openal_ALC_getCurrentContext + (JNIEnv *, jobject); + +/* + * Class: org_lwjgl_openal_ALC + * Method: getContextsDevice + * Signature: (Lorg/lwjgl/openal/ALCcontext;)Lorg/lwjgl/openal/ALCdevice; + */ +JNIEXPORT jobject JNICALL Java_org_lwjgl_openal_ALC_getContextsDevice + (JNIEnv *, jobject, jobject); + +/* + * Class: org_lwjgl_openal_ALC + * Method: suspendContext + * Signature: (Lorg/lwjgl/openal/ALCcontext;)V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_openal_ALC_suspendContext + (JNIEnv *, jobject, jobject); + +/* + * Class: org_lwjgl_openal_ALC + * Method: destroyContext + * Signature: (Lorg/lwjgl/openal/ALCcontext;)V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_openal_ALC_destroyContext + (JNIEnv *, jobject, jobject); + +/* + * Class: org_lwjgl_openal_ALC + * Method: getError + * Signature: (Lorg/lwjgl/openal/ALCdevice;)I + */ +JNIEXPORT jint JNICALL Java_org_lwjgl_openal_ALC_getError + (JNIEnv *, jobject, jobject); + +/* + * Class: org_lwjgl_openal_ALC + * Method: isExtensionPresent + * Signature: (Lorg/lwjgl/openal/ALCdevice;Ljava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL Java_org_lwjgl_openal_ALC_isExtensionPresent + (JNIEnv *, jobject, jobject, jstring); + +/* + * Class: org_lwjgl_openal_ALC + * Method: getProcAddress + * Signature: (Lorg/lwjgl/openal/ALCdevice;Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_org_lwjgl_openal_ALC_getProcAddress + (JNIEnv *, jobject, jobject, jstring); + +/* + * Class: org_lwjgl_openal_ALC + * Method: getEnumValue + * Signature: (Lorg/lwjgl/openal/ALCdevice;Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_org_lwjgl_openal_ALC_getEnumValue + (JNIEnv *, jobject, jobject, jstring); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/native/win32/org_lwjgl_openal_ALC.cpp b/src/native/win32/org_lwjgl_openal_ALC.cpp new file mode 100644 index 00000000..46771ebd --- /dev/null +++ b/src/native/win32/org_lwjgl_openal_ALC.cpp @@ -0,0 +1,341 @@ +/* + * Copyright (c) 2002 Light Weight Java Game Library Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'Light Weight Java Game Library' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * $Id$ + * + * This is the actual JNI implementation of the OpenAL context/device library. + * + * @author Brian Matzon + * @version $Revision$ + */ +#include "org_lwjgl_openal_ALUT.h" + +/* OpenAL includes */ +#include + +/** + * This function returns strings related to the context. + * + * C Specification: + * ALubyte * alcGetString(ALCdevice *device, ALenum token); + */ +JNIEXPORT jstring JNICALL Java_org_lwjgl_openal_ALC_getString (JNIEnv *env, jobject obj, jobject device, jint token) { + jclass class_device = env->GetObjectClass(device); + jfieldID field_device = env->GetFieldID(class_device, "device", "I"); + jint deviceaddress = env->GetIntField(obj, field_device); + + return env->NewStringUTF((const char*) alcGetString((ALCdevice*) deviceaddress, (ALenum) token)); +} + +/** + * This function returns integers related to the context. + * + * C Specification: + * ALvoid alcGetIntegerv(ALCdevice *device, ALenum token, ALsizei size, ALint *dest); + */ +JNIEXPORT void JNICALL Java_org_lwjgl_openal_ALC_getIntegerv (JNIEnv *env, jobject obj, jobject device, jint token, jint size, jint dest) { + jclass device_class = env->GetObjectClass(device); + jfieldID device_field = env->GetFieldID(device_class, "device", "I"); + jint deviceaddress = env->GetIntField(obj, device_field); + + alcGetIntegerv((ALCdevice*) deviceaddress, (ALenum) token, (ALsizei) size, (ALint*) dest); +} + +/** + * This function opens a device by name. + * + * C Specification: + * ALCdevice *alcOpenDevice( const ALubyte *tokstr ); + */ +JNIEXPORT jobject JNICALL Java_org_lwjgl_openal_ALC_openDevice (JNIEnv *env, jobject obj, jstring tokstr) { + ALubyte* tokenstring = (ALubyte*) (env->GetStringUTFChars(tokstr, 0)); + + /* get device */ + ALCdevice* device = alcOpenDevice(tokenstring); + + /* get ready to create ALCdevice instance */ + jobject alcDevice_object = NULL; + jclass alcDevice_class = NULL; + jmethodID alcDevice_method = NULL; + + /* find class and constructor */ + alcDevice_class = env->FindClass("org/lwjgl/openal/ALCdevice"); + alcDevice_method = env->GetMethodID(alcDevice_class, "", "(I)V"); + + /* create instance */ + alcDevice_object = env->NewObject(alcDevice_class, alcDevice_method, (int) device); + + /* clean up */ + env->ReleaseStringUTFChars((jstring)tokenstring, 0); + + return alcDevice_object; +} + +/** + * This function closes a device by name. + * + * C Specification: + * void alcCloseDevice( ALCdevice *dev ); + */ +JNIEXPORT void JNICALL Java_org_lwjgl_openal_ALC_closeDevice (JNIEnv *env, jobject obj, jobject device) { + jclass device_class = env->GetObjectClass(device); + jfieldID device_field = env->GetFieldID(device_class, "device", "I"); + jint deviceaddress = env->GetIntField(obj, device_field); + + alcCloseDevice((ALCdevice*) deviceaddress); +} + +/** + * This function creates a context using a specified device. + * + * C Specification: + * ALCcontext* alcCreateContext( ALCdevice *dev, ALint* attrlist ); + */ +JNIEXPORT jobject JNICALL Java_org_lwjgl_openal_ALC_createContext (JNIEnv *env, jobject obj, jobject device, jint attrlist) { + /* get device address */ + jclass device_class = env->GetObjectClass(device); + jfieldID device_field = env->GetFieldID(device_class, "device", "I"); + jint deviceaddress = env->GetIntField(obj, device_field); + + ALCcontext* context = alcCreateContext((ALCdevice*) deviceaddress, (ALint*) attrlist); + + /* get ready to create ALCcontext instance */ + jobject alcContext_object = NULL; + jclass alcContext_class = NULL; + jmethodID alcContext_method = NULL; + + /* find class and constructor */ + alcContext_class = env->FindClass("org/lwjgl/openal/ALCcontext"); + alcContext_method = env->GetMethodID(alcContext_class, "", "(I)V"); + + /* create instance */ + alcContext_object = env->NewObject(alcContext_class, alcContext_method, (int) context); + + return alcContext_object; +} + +/** + * This function makes a specified context the current context. + * + * C Specification: + * ALCboolean alcMakeContextCurrent(ALCcontext *context); + */ +JNIEXPORT jboolean JNICALL Java_org_lwjgl_openal_ALC_makeContextCurrent (JNIEnv *env, jobject obj, jobject context) { + /* get context address */ + jclass context_class = env->GetObjectClass(context); + jfieldID context_field = env->GetFieldID(context_class, "context", "I"); + jint contextaddress = env->GetIntField(obj, context_field); + + return alcMakeContextCurrent((ALCcontext*) contextaddress); +} + +/** + * This function tells a context to begin processing. + * + * C Specification: + * void alcProcessContext(ALCcontext *context); + */ +JNIEXPORT void JNICALL Java_org_lwjgl_openal_ALC_processContext (JNIEnv *env, jobject obj, jobject context) { + /* get context address */ + jclass context_class = env->GetObjectClass(context); + jfieldID context_field = env->GetFieldID(context_class, "context", "I"); + jint contextaddress = env->GetIntField(obj, context_field); + + alcProcessContext((ALCcontext*) contextaddress); +} + +/** + * This function retrieves the current context. + * + * C Specification: + * ALCcontext* alcGetCurrentContext( ALvoid ); + */ +JNIEXPORT jobject JNICALL Java_org_lwjgl_openal_ALC_getCurrentContext (JNIEnv *env, jobject obj) { + + ALCcontext* context = alcGetCurrentContext(); + + /* get ready to create ALCcontext instance */ + jobject alcContext_object = NULL; + jclass alcContext_class = NULL; + jmethodID alcContext_method = NULL; + + /* find class and constructor */ + alcContext_class = env->FindClass("org/lwjgl/openal/ALCcontext"); + alcContext_method = env->GetMethodID(alcContext_class, "", "(I)V"); + + /* create instance */ + alcContext_object = env->NewObject(alcContext_class, alcContext_method, (int) context); + + return alcContext_object; +} + +/** + * This function retrieves the specified contexts device + * + * C Specification: + * ALCdevice* alcGetContextsDevice(ALCcontext *context); + */ +JNIEXPORT jobject JNICALL Java_org_lwjgl_openal_ALC_getContextsDevice (JNIEnv *env, jobject obj, jobject context) { + + /* get context address */ + jclass context_class = env->GetObjectClass(context); + jfieldID context_field = env->GetFieldID(context_class, "context", "I"); + jint contextaddress = env->GetIntField(obj, context_field); + + ALCdevice* device = alcGetContextsDevice((ALCcontext*) contextaddress); + + /* get ready to create ALCdevice instance */ + jobject alcDevice_object = NULL; + jclass alcDevice_class = NULL; + jmethodID alcDevice_method = NULL; + + /* find class and constructor */ + alcDevice_class = env->FindClass("org/lwjgl/openal/ALCdevice"); + alcDevice_method = env->GetMethodID(alcDevice_class, "", "(I)V"); + + /* create instance */ + alcDevice_object = env->NewObject(alcDevice_class, alcDevice_method, (int) device); + + return alcDevice_object; +} + +/** + * This function suspends processing on a specified context. + * + * C Specification: + * void alcSuspendContext(ALCcontext *context); + */ +JNIEXPORT void JNICALL Java_org_lwjgl_openal_ALC_suspendContext (JNIEnv *env, jobject obj, jobject context) { + /* get context address */ + jclass context_class = env->GetObjectClass(context); + jfieldID context_field = env->GetFieldID(context_class, "context", "I"); + jint contextaddress = env->GetIntField(obj, context_field); + + alcSuspendContext((ALCcontext*) contextaddress); +} + +/** + * This function destroys a context. + * + * C Specification: + * void alcDestroyContext(ALCcontext *context); + */ +JNIEXPORT void JNICALL Java_org_lwjgl_openal_ALC_destroyContext (JNIEnv *env, jobject obj, jobject context) { + /* get context address */ + jclass context_class = env->GetObjectClass(context); + jfieldID context_field = env->GetFieldID(context_class, "context", "I"); + jint contextaddress = env->GetIntField(obj, context_field); + + alcDestroyContext((ALCcontext*) contextaddress); +} + +/** + * This function retrieves the specified devices context error state. + * + * C Specification: + * ALCenum alcGetError(ALCdevice *device); + */ +JNIEXPORT jint JNICALL Java_org_lwjgl_openal_ALC_getError (JNIEnv *env, jobject obj, jobject device) { + /* get device address */ + jclass device_class = env->GetObjectClass(device); + jfieldID device_field = env->GetFieldID(device_class, "device", "I"); + jint deviceaddress = env->GetIntField(obj, device_field); + + return (jint) alcGetError((ALCdevice*) deviceaddress); +} + +/** + * This function queries if a specified context extension is available. + * + * C Specification: + * ALboolean alcIsExtensionPresent(ALCdevice *device, ALubyte *extName); + */ +JNIEXPORT jboolean JNICALL Java_org_lwjgl_openal_ALC_isExtensionPresent (JNIEnv *env, jobject obj, jobject device, jstring extName) { + /* get device address */ + jclass device_class = env->GetObjectClass(device); + jfieldID device_field = env->GetFieldID(device_class, "device", "I"); + jint deviceaddress = env->GetIntField(obj, device_field); + + /* get extension */ + ALubyte* functionname = (ALubyte*) (env->GetStringUTFChars(extName, 0)); + + jboolean result = (jboolean) alcIsExtensionPresent((ALCdevice*) deviceaddress, functionname); + + env->ReleaseStringUTFChars((jstring)functionname, 0); + + return result; +} + +/** + * This function retrieves the address of a specified context extension function. + * + * C Specification: + * ALvoid * alcGetProcAddress(ALCdevice *device, ALubyte *funcName); + */ +JNIEXPORT jint JNICALL Java_org_lwjgl_openal_ALC_getProcAddress (JNIEnv *env, jobject obj, jobject device, jstring funcName) { + /* get device address */ + jclass device_class = env->GetObjectClass(device); + jfieldID device_field = env->GetFieldID(device_class, "device", "I"); + jint deviceaddress = env->GetIntField(obj, device_field); + + /* get extension */ + ALubyte* functionname = (ALubyte*) (env->GetStringUTFChars(funcName, 0)); + + jint result = (jint) alcGetProcAddress((ALCdevice*) deviceaddress, functionname); + + env->ReleaseStringUTFChars((jstring)functionname, 0); + + return result; +} + +/** + * This function retrieves the enum value for a specified enumeration name. + * + * C Specification: + * ALenum alcGetEnumValue(ALCdevice *device, ALubyte *enumName); + */ +JNIEXPORT jint JNICALL Java_org_lwjgl_openal_ALC_getEnumValue (JNIEnv *env, jobject obj, jobject device, jstring enumName) { + /* get device address */ + jclass device_class = env->GetObjectClass(device); + jfieldID device_field = env->GetFieldID(device_class, "device", "I"); + jint deviceaddress = env->GetIntField(obj, device_field); + + /* get extension */ + ALubyte* enumerationname = (ALubyte*) (env->GetStringUTFChars(enumName, 0)); + + jint result = (jint) alcGetEnumValue((ALCdevice*) deviceaddress, enumerationname); + + env->ReleaseStringUTFChars((jstring)enumerationname, 0); + + return result; +} \ No newline at end of file