PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/lwjgl/src/native/common/org_lwjgl_openal_ALC10.c

https://github.com/Arttuv/The-Last-Little-Defender
C | 322 lines | 149 code | 33 blank | 140 comment | 17 complexity | 92f358580bc461c73e3757b3b86b78d6 MD5 | raw file
  1. /*
  2. * Copyright (c) 2002-2008 LWJGL Project
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are
  7. * met:
  8. *
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * * Neither the name of 'LWJGL' nor the names of
  17. * its contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  22. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. /**
  33. * $Id: org_lwjgl_openal_ALC.c 2279 2006-02-23 19:22:00Z elias_naur $
  34. *
  35. * This is the actual JNI implementation of the OpenAL context/device library.
  36. *
  37. * @author Brian Matzon <brian@matzon.dk>
  38. * @version $Revision: 2279 $
  39. */
  40. /* OpenAL includes */
  41. #include "extal.h"
  42. //alc
  43. typedef ALCubyte* (ALCAPIENTRY *alcGetStringPROC)(ALCdevice *device,ALCenum param);
  44. typedef ALCvoid (ALCAPIENTRY *alcGetIntegervPROC)(ALCdevice *device,ALCenum param,ALCsizei size,ALCint *data);
  45. typedef ALCdevice* (ALCAPIENTRY *alcOpenDevicePROC)(ALCubyte *deviceName);
  46. typedef ALCboolean (ALCAPIENTRY *alcCloseDevicePROC)(ALCdevice *device);
  47. typedef ALCcontext* (ALCAPIENTRY *alcCreateContextPROC)(ALCdevice *device,ALCint *attrList);
  48. typedef ALCenum (ALCAPIENTRY *alcMakeContextCurrentPROC)(ALCcontext *context);
  49. typedef ALCvoid (ALCAPIENTRY *alcProcessContextPROC)(ALCcontext *context);
  50. typedef ALCdevice* (ALCAPIENTRY *alcGetContextsDevicePROC)(ALCcontext *context);
  51. typedef ALCvoid (ALCAPIENTRY *alcSuspendContextPROC)(ALCcontext *context);
  52. typedef ALCvoid (ALCAPIENTRY *alcDestroyContextPROC)(ALCcontext *context);
  53. typedef ALCenum (ALCAPIENTRY *alcGetErrorPROC)(ALCdevice *device);
  54. typedef ALCboolean (ALCAPIENTRY *alcIsExtensionPresentPROC)(ALCdevice *device,ALCubyte *extName);
  55. //typedef ALCvoid* (ALCAPIENTRY *alcGetProcAddressPROC)(ALCdevice *device,ALCubyte *funcName);
  56. typedef ALCenum (ALCAPIENTRY *alcGetEnumValuePROC)(ALCdevice *device,ALCubyte *enumName);
  57. typedef ALCcontext* (ALCAPIENTRY *alcGetCurrentContextPROC)(ALCvoid);
  58. static alcGetCurrentContextPROC alcGetCurrentContext = NULL;
  59. static alcGetStringPROC alcGetString;
  60. static alcGetIntegervPROC alcGetIntegerv;
  61. static alcOpenDevicePROC alcOpenDevice;
  62. static alcCloseDevicePROC alcCloseDevice;
  63. static alcCreateContextPROC alcCreateContext;
  64. static alcMakeContextCurrentPROC alcMakeContextCurrent;
  65. static alcProcessContextPROC alcProcessContext;
  66. static alcGetContextsDevicePROC alcGetContextsDevice;
  67. static alcSuspendContextPROC alcSuspendContext;
  68. static alcDestroyContextPROC alcDestroyContext;
  69. static alcGetErrorPROC alcGetError;
  70. static alcIsExtensionPresentPROC alcIsExtensionPresent;
  71. //static alcGetProcAddressPROC alcGetProcAddress;
  72. static alcGetEnumValuePROC alcGetEnumValue;
  73. /**
  74. * This function returns strings related to the context.
  75. *
  76. * C Specification:
  77. * ALubyte * alcGetString(ALCdevice *device, ALenum token);
  78. */
  79. static jstring JNICALL Java_org_lwjgl_openal_ALC10_nalcGetString (JNIEnv *env, jclass clazz, jlong deviceaddress, jint token) {
  80. const char* alcString = (const char*) alcGetString((ALCdevice*)((intptr_t)deviceaddress), (ALenum) token);
  81. int length;
  82. int i=1;
  83. if (alcString == NULL) {
  84. return NULL;
  85. }
  86. // Special treatment of enumeration tokens
  87. // These are encoded using \0 between elements and a finishing \0\0
  88. switch(token) {
  89. case 0x1005: // ALC_DEVICE_SPECIFIER
  90. case 0x310: // ALC_CAPTURE_DEVICE_SPECIFIER
  91. // If deviceaddress is not 0, OpenAL returns a single device terminated by a
  92. // single \0 character, if token is ALC_DEVICE_SPECIFIER or
  93. // ALC_CAPTURE_DEVICE_SPECIFIER.
  94. if (deviceaddress != 0) {
  95. length = strlen(alcString);
  96. break;
  97. }
  98. case 0x1013: // ALC_ALL_DEVICES_SPECIFIER
  99. while (alcString[i - 1] != '\0' || alcString[i] != '\0') {
  100. i++;
  101. }
  102. length = i + 1;
  103. break;
  104. default: // e.g. ALC_DEFAULT_ALL_DEVICES_SPECIFIER
  105. length = strlen(alcString);
  106. }
  107. return NewStringNativeWithLength(env, alcString, length);
  108. }
  109. /**
  110. * This function returns integers related to the context.
  111. *
  112. * C Specification:
  113. * ALvoid alcGetIntegerv(ALCdevice *device, ALenum token, ALsizei size, ALint *dest);
  114. */
  115. static void JNICALL Java_org_lwjgl_openal_ALC10_nalcGetIntegerv (JNIEnv *env, jclass clazz, jlong deviceaddress, jint token, jint size, jobject dest, jint offset) {
  116. ALint* address = NULL;
  117. if (dest != NULL) {
  118. address = offset + (ALint*) (*env)->GetDirectBufferAddress(env, dest);
  119. }
  120. alcGetIntegerv((ALCdevice*)((intptr_t)deviceaddress), (ALenum) token, (ALsizei) size, address);
  121. }
  122. /**
  123. * This function opens a device by name.
  124. *
  125. * C Specification:
  126. * ALCdevice *alcOpenDevice( const ALubyte *tokstr );
  127. */
  128. static jlong JNICALL Java_org_lwjgl_openal_ALC10_nalcOpenDevice (JNIEnv *env, jclass clazz, jstring tokstr) {
  129. char * tokenstring;
  130. ALCdevice* device;
  131. if(tokstr != NULL) {
  132. tokenstring = GetStringNativeChars(env, tokstr);
  133. } else {
  134. tokenstring = NULL;
  135. }
  136. /* get device */
  137. device = alcOpenDevice((ALubyte *) tokenstring);
  138. if(tokenstring != NULL) {
  139. free(tokenstring);
  140. }
  141. return (jlong)((intptr_t)device);
  142. }
  143. /**
  144. * This function closes a device by name.
  145. *
  146. * C Specification:
  147. * bool alcCloseDevice( ALCdevice *dev );
  148. */
  149. static jboolean JNICALL Java_org_lwjgl_openal_ALC10_nalcCloseDevice (JNIEnv *env, jclass clazz, jlong deviceaddress) {
  150. return alcCloseDevice((ALCdevice*)((intptr_t)deviceaddress));
  151. }
  152. /**
  153. * This function creates a context using a specified device.
  154. *
  155. * C Specification:
  156. * ALCcontext* alcCreateContext( ALCdevice *dev, ALint* attrlist );
  157. */
  158. static jlong JNICALL Java_org_lwjgl_openal_ALC10_nalcCreateContext (JNIEnv *env, jclass clazz, jlong deviceaddress, jobject attrlist) {
  159. ALint* address = NULL;
  160. ALCcontext* context;
  161. if (attrlist != NULL) {
  162. address = (ALint*) safeGetBufferAddress(env, attrlist);
  163. }
  164. context = alcCreateContext((ALCdevice*)((intptr_t)deviceaddress), address);
  165. return (jlong)((intptr_t)context);
  166. }
  167. /**
  168. * This function makes a specified context the current context.
  169. *
  170. * C Specification:
  171. * ALCboolean alcMakeContextCurrent(ALCcontext *context);
  172. */
  173. static jint JNICALL Java_org_lwjgl_openal_ALC10_nalcMakeContextCurrent (JNIEnv *env, jclass clazz, jlong contextaddress) {
  174. ALCcontext* context = (ALCcontext*)((intptr_t)contextaddress);
  175. return alcMakeContextCurrent(context);
  176. }
  177. /**
  178. * This function tells a context to begin processing.
  179. *
  180. * C Specification:
  181. * void alcProcessContext(ALCcontext *context);
  182. */
  183. static void JNICALL Java_org_lwjgl_openal_ALC10_nalcProcessContext (JNIEnv *env, jclass clazz, jlong contextaddress) {
  184. alcProcessContext((ALCcontext*)((intptr_t)contextaddress));
  185. }
  186. /**
  187. * This function retrieves the current context.
  188. *
  189. * C Specification:
  190. * ALCcontext* alcGetCurrentContext( ALvoid );
  191. */
  192. static jlong JNICALL Java_org_lwjgl_openal_ALC10_nalcGetCurrentContext (JNIEnv *env, jclass clazz) {
  193. ALCcontext* context = alcGetCurrentContext();
  194. return (jlong)((intptr_t)context);
  195. }
  196. /**
  197. * This function retrieves the specified contexts device
  198. *
  199. * C Specification:
  200. * ALCdevice* alcGetContextsDevice(ALCcontext *context);
  201. */
  202. static jlong JNICALL Java_org_lwjgl_openal_ALC10_nalcGetContextsDevice (JNIEnv *env, jclass clazz, jlong contextaddress) {
  203. ALCdevice* device = alcGetContextsDevice((ALCcontext*)((intptr_t)contextaddress));
  204. return (jlong)((intptr_t)device);
  205. }
  206. /**
  207. * This function suspends processing on a specified context.
  208. *
  209. * C Specification:
  210. * void alcSuspendContext(ALCcontext *context);
  211. */
  212. static void JNICALL Java_org_lwjgl_openal_ALC10_nalcSuspendContext (JNIEnv *env, jclass clazz, jlong contextaddress) {
  213. alcSuspendContext((ALCcontext*)((intptr_t)contextaddress));
  214. }
  215. /**
  216. * This function destroys a context.
  217. *
  218. * C Specification:
  219. * void alcDestroyContext(ALCcontext *context);
  220. */
  221. static void JNICALL Java_org_lwjgl_openal_ALC10_nalcDestroyContext (JNIEnv *env, jclass clazz, jlong contextaddress) {
  222. alcDestroyContext((ALCcontext*)((intptr_t)contextaddress));
  223. }
  224. /**
  225. * This function retrieves the specified devices context error state.
  226. *
  227. * C Specification:
  228. * ALCenum alcGetError(ALCdevice *device);
  229. */
  230. static jint JNICALL Java_org_lwjgl_openal_ALC10_nalcGetError (JNIEnv *env, jclass clazz, jlong deviceaddress) {
  231. return alcGetError((ALCdevice*)((intptr_t)deviceaddress));
  232. }
  233. /**
  234. * This function queries if a specified context extension is available.
  235. *
  236. * C Specification:
  237. * ALboolean alcIsExtensionPresent(ALCdevice *device, ALubyte *extName);
  238. */
  239. static jboolean JNICALL Java_org_lwjgl_openal_ALC10_nalcIsExtensionPresent (JNIEnv *env, jclass clazz, jlong deviceaddress, jstring extName) {
  240. /* get extension */
  241. ALubyte* functionname = (ALubyte*) GetStringNativeChars(env, extName);
  242. jboolean result = (jboolean) alcIsExtensionPresent((ALCdevice*)((intptr_t)deviceaddress), functionname);
  243. free(functionname);
  244. return result;
  245. }
  246. /**
  247. * This function retrieves the enum value for a specified enumeration name.
  248. *
  249. * C Specification:
  250. * ALenum alcGetEnumValue(ALCdevice *device, ALubyte *enumName);
  251. */
  252. static jint JNICALL Java_org_lwjgl_openal_ALC10_nalcGetEnumValue (JNIEnv *env, jclass clazz, jlong deviceaddress, jstring enumName) {
  253. /* get extension */
  254. ALubyte* enumerationname = (ALubyte*) GetStringNativeChars(env, enumName);
  255. jint result = (jint) alcGetEnumValue((ALCdevice*)((intptr_t)deviceaddress), enumerationname);
  256. free(enumerationname);
  257. return result;
  258. }
  259. /**
  260. * Loads the context OpenAL functions
  261. *
  262. * @return true if all methods were loaded, false if one of the methods could not be loaded
  263. */
  264. #ifdef __cplusplus
  265. extern "C" {
  266. #endif
  267. JNIEXPORT void JNICALL Java_org_lwjgl_openal_ALC10_initNativeStubs(JNIEnv *env, jclass clazz) {
  268. JavaMethodAndExtFunction functions[] = {
  269. {"nalcGetString", "(JI)Ljava/lang/String;", (void*)&Java_org_lwjgl_openal_ALC10_nalcGetString, "alcGetString", (void*)&alcGetString},
  270. {"nalcGetIntegerv", "(JIILjava/nio/Buffer;I)V", (void*)&Java_org_lwjgl_openal_ALC10_nalcGetIntegerv, "alcGetIntegerv", (void*)&alcGetIntegerv},
  271. {"nalcOpenDevice", "(Ljava/lang/String;)J", (void*)&Java_org_lwjgl_openal_ALC10_nalcOpenDevice, "alcOpenDevice", (void*)&alcOpenDevice},
  272. {"nalcCloseDevice", "(J)Z", (void*)&Java_org_lwjgl_openal_ALC10_nalcCloseDevice, "alcCloseDevice", (void*)&alcCloseDevice},
  273. {"nalcCreateContext", "(JLjava/nio/IntBuffer;)J", (void*)&Java_org_lwjgl_openal_ALC10_nalcCreateContext, "alcCreateContext", (void*)&alcCreateContext},
  274. {"nalcMakeContextCurrent", "(J)I", (void*)&Java_org_lwjgl_openal_ALC10_nalcMakeContextCurrent, "alcMakeContextCurrent", (void*)&alcMakeContextCurrent},
  275. {"nalcProcessContext", "(J)V", (void*)&Java_org_lwjgl_openal_ALC10_nalcProcessContext, "alcProcessContext", (void*)&alcProcessContext},
  276. {"nalcGetCurrentContext", "()J", (void*)&Java_org_lwjgl_openal_ALC10_nalcGetCurrentContext, "alcGetCurrentContext", (void*)&alcGetCurrentContext},
  277. {"nalcGetContextsDevice", "(J)J", (void*)&Java_org_lwjgl_openal_ALC10_nalcGetContextsDevice, "alcGetContextsDevice", (void*)&alcGetContextsDevice},
  278. {"nalcSuspendContext", "(J)V", (void*)&Java_org_lwjgl_openal_ALC10_nalcSuspendContext, "alcSuspendContext", (void*)&alcSuspendContext},
  279. {"nalcDestroyContext", "(J)V", (void*)&Java_org_lwjgl_openal_ALC10_nalcDestroyContext, "alcDestroyContext", (void*)&alcDestroyContext},
  280. {"nalcGetError", "(J)I", (void*)&Java_org_lwjgl_openal_ALC10_nalcGetError, "alcGetError", (void*)&alcGetError},
  281. {"nalcIsExtensionPresent", "(JLjava/lang/String;)Z", (void*)&Java_org_lwjgl_openal_ALC10_nalcIsExtensionPresent, "alcIsExtensionPresent", (void*)&alcIsExtensionPresent},
  282. {"nalcGetEnumValue", "(JLjava/lang/String;)I", (void*)&Java_org_lwjgl_openal_ALC10_nalcGetEnumValue, "alcGetEnumValue", (void*)&alcGetEnumValue}
  283. };
  284. int num_functions = NUMFUNCTIONS(functions);
  285. extal_InitializeClass(env, clazz, num_functions, functions);
  286. }
  287. #ifdef __cplusplus
  288. }
  289. #endif