alExtension.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /**
  2. * OpenAL cross platform audio library
  3. * Copyright (C) 1999-2007 by authors.
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public
  15. * License along with this library; if not, write to the
  16. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17. * Boston, MA 02111-1307, USA.
  18. * Or go to http://www.gnu.org/copyleft/lgpl.html
  19. */
  20. #include "config.h"
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <ctype.h>
  24. #include "alError.h"
  25. #include "alMain.h"
  26. #include "alFilter.h"
  27. #include "alEffect.h"
  28. #include "alAuxEffectSlot.h"
  29. #include "alDatabuffer.h"
  30. #include "alSource.h"
  31. #include "alBuffer.h"
  32. #include "AL/al.h"
  33. #include "AL/alc.h"
  34. typedef struct ALenums {
  35. const ALchar *enumName;
  36. ALenum value;
  37. } ALenums;
  38. static const ALenums enumeration[] = {
  39. // Types
  40. { "AL_INVALID", AL_INVALID },
  41. { "AL_NONE", AL_NONE },
  42. { "AL_FALSE", AL_FALSE },
  43. { "AL_TRUE", AL_TRUE },
  44. // Source and Listener Properties
  45. { "AL_SOURCE_RELATIVE", AL_SOURCE_RELATIVE },
  46. { "AL_CONE_INNER_ANGLE", AL_CONE_INNER_ANGLE },
  47. { "AL_CONE_OUTER_ANGLE", AL_CONE_OUTER_ANGLE },
  48. { "AL_PITCH", AL_PITCH },
  49. { "AL_POSITION", AL_POSITION },
  50. { "AL_DIRECTION", AL_DIRECTION },
  51. { "AL_VELOCITY", AL_VELOCITY },
  52. { "AL_LOOPING", AL_LOOPING },
  53. { "AL_BUFFER", AL_BUFFER },
  54. { "AL_GAIN", AL_GAIN },
  55. { "AL_MIN_GAIN", AL_MIN_GAIN },
  56. { "AL_MAX_GAIN", AL_MAX_GAIN },
  57. { "AL_ORIENTATION", AL_ORIENTATION },
  58. { "AL_REFERENCE_DISTANCE", AL_REFERENCE_DISTANCE },
  59. { "AL_ROLLOFF_FACTOR", AL_ROLLOFF_FACTOR },
  60. { "AL_CONE_OUTER_GAIN", AL_CONE_OUTER_GAIN },
  61. { "AL_MAX_DISTANCE", AL_MAX_DISTANCE },
  62. { "AL_SEC_OFFSET", AL_SEC_OFFSET },
  63. { "AL_SAMPLE_OFFSET", AL_SAMPLE_OFFSET },
  64. { "AL_BYTE_OFFSET", AL_BYTE_OFFSET },
  65. { "AL_SOURCE_TYPE", AL_SOURCE_TYPE },
  66. { "AL_STATIC", AL_STATIC },
  67. { "AL_STREAMING", AL_STREAMING },
  68. { "AL_UNDETERMINED", AL_UNDETERMINED },
  69. { "AL_METERS_PER_UNIT", AL_METERS_PER_UNIT },
  70. // Source EFX Properties
  71. { "AL_DIRECT_FILTER", AL_DIRECT_FILTER },
  72. { "AL_AUXILIARY_SEND_FILTER", AL_AUXILIARY_SEND_FILTER },
  73. { "AL_AIR_ABSORPTION_FACTOR", AL_AIR_ABSORPTION_FACTOR },
  74. { "AL_ROOM_ROLLOFF_FACTOR", AL_ROOM_ROLLOFF_FACTOR },
  75. { "AL_CONE_OUTER_GAINHF", AL_CONE_OUTER_GAINHF },
  76. { "AL_DIRECT_FILTER_GAINHF_AUTO", AL_DIRECT_FILTER_GAINHF_AUTO },
  77. { "AL_AUXILIARY_SEND_FILTER_GAIN_AUTO", AL_AUXILIARY_SEND_FILTER_GAIN_AUTO },
  78. { "AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO", AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO},
  79. // Source State information
  80. { "AL_SOURCE_STATE", AL_SOURCE_STATE },
  81. { "AL_INITIAL", AL_INITIAL },
  82. { "AL_PLAYING", AL_PLAYING },
  83. { "AL_PAUSED", AL_PAUSED },
  84. { "AL_STOPPED", AL_STOPPED },
  85. // Queue information
  86. { "AL_BUFFERS_QUEUED", AL_BUFFERS_QUEUED },
  87. { "AL_BUFFERS_PROCESSED", AL_BUFFERS_PROCESSED },
  88. // Buffer Formats
  89. { "AL_FORMAT_MONO8", AL_FORMAT_MONO8 },
  90. { "AL_FORMAT_MONO16", AL_FORMAT_MONO16 },
  91. { "AL_FORMAT_MONO_FLOAT32", AL_FORMAT_MONO_FLOAT32 },
  92. { "AL_FORMAT_MONO_DOUBLE_EXT", AL_FORMAT_MONO_DOUBLE_EXT },
  93. { "AL_FORMAT_STEREO8", AL_FORMAT_STEREO8 },
  94. { "AL_FORMAT_STEREO16", AL_FORMAT_STEREO16 },
  95. { "AL_FORMAT_STEREO_FLOAT32", AL_FORMAT_STEREO_FLOAT32 },
  96. { "AL_FORMAT_STEREO_DOUBLE_EXT", AL_FORMAT_STEREO_DOUBLE_EXT },
  97. { "AL_FORMAT_MONO_IMA4", AL_FORMAT_MONO_IMA4 },
  98. { "AL_FORMAT_STEREO_IMA4", AL_FORMAT_STEREO_IMA4 },
  99. { "AL_FORMAT_QUAD8_LOKI", AL_FORMAT_QUAD8_LOKI },
  100. { "AL_FORMAT_QUAD16_LOKI", AL_FORMAT_QUAD16_LOKI },
  101. { "AL_FORMAT_QUAD8", AL_FORMAT_QUAD8 },
  102. { "AL_FORMAT_QUAD16", AL_FORMAT_QUAD16 },
  103. { "AL_FORMAT_QUAD32", AL_FORMAT_QUAD32 },
  104. { "AL_FORMAT_51CHN8", AL_FORMAT_51CHN8 },
  105. { "AL_FORMAT_51CHN16", AL_FORMAT_51CHN16 },
  106. { "AL_FORMAT_51CHN32", AL_FORMAT_51CHN32 },
  107. { "AL_FORMAT_61CHN8", AL_FORMAT_61CHN8 },
  108. { "AL_FORMAT_61CHN16", AL_FORMAT_61CHN16 },
  109. { "AL_FORMAT_61CHN32", AL_FORMAT_61CHN32 },
  110. { "AL_FORMAT_71CHN8", AL_FORMAT_71CHN8 },
  111. { "AL_FORMAT_71CHN16", AL_FORMAT_71CHN16 },
  112. { "AL_FORMAT_71CHN32", AL_FORMAT_71CHN32 },
  113. { "AL_FORMAT_REAR8", AL_FORMAT_REAR8 },
  114. { "AL_FORMAT_REAR16", AL_FORMAT_REAR16 },
  115. { "AL_FORMAT_REAR32", AL_FORMAT_REAR32 },
  116. { "AL_FORMAT_MONO_MULAW", AL_FORMAT_MONO_MULAW },
  117. { "AL_FORMAT_MONO_MULAW_EXT", AL_FORMAT_MONO_MULAW },
  118. { "AL_FORMAT_STEREO_MULAW", AL_FORMAT_STEREO_MULAW },
  119. { "AL_FORMAT_STEREO_MULAW_EXT", AL_FORMAT_STEREO_MULAW },
  120. { "AL_FORMAT_QUAD_MULAW", AL_FORMAT_QUAD_MULAW },
  121. { "AL_FORMAT_51CHN_MULAW", AL_FORMAT_51CHN_MULAW },
  122. { "AL_FORMAT_61CHN_MULAW", AL_FORMAT_61CHN_MULAW },
  123. { "AL_FORMAT_71CHN_MULAW", AL_FORMAT_71CHN_MULAW },
  124. { "AL_FORMAT_REAR_MULAW", AL_FORMAT_REAR_MULAW },
  125. // Buffer attributes
  126. { "AL_FREQUENCY", AL_FREQUENCY },
  127. { "AL_BITS", AL_BITS },
  128. { "AL_CHANNELS", AL_CHANNELS },
  129. { "AL_SIZE", AL_SIZE },
  130. // Buffer States (not supported yet)
  131. { "AL_UNUSED", AL_UNUSED },
  132. { "AL_PENDING", AL_PENDING },
  133. { "AL_PROCESSED", AL_PROCESSED },
  134. // AL Error Messages
  135. { "AL_NO_ERROR", AL_NO_ERROR },
  136. { "AL_INVALID_NAME", AL_INVALID_NAME },
  137. { "AL_INVALID_ENUM", AL_INVALID_ENUM },
  138. { "AL_INVALID_VALUE", AL_INVALID_VALUE },
  139. { "AL_INVALID_OPERATION", AL_INVALID_OPERATION },
  140. { "AL_OUT_OF_MEMORY", AL_OUT_OF_MEMORY },
  141. // Context strings
  142. { "AL_VENDOR", AL_VENDOR },
  143. { "AL_VERSION", AL_VERSION },
  144. { "AL_RENDERER", AL_RENDERER },
  145. { "AL_EXTENSIONS", AL_EXTENSIONS },
  146. // Global states
  147. { "AL_DOPPLER_FACTOR", AL_DOPPLER_FACTOR },
  148. { "AL_DOPPLER_VELOCITY", AL_DOPPLER_VELOCITY },
  149. { "AL_DISTANCE_MODEL", AL_DISTANCE_MODEL },
  150. { "AL_SPEED_OF_SOUND", AL_SPEED_OF_SOUND },
  151. { "AL_SOURCE_DISTANCE_MODEL", AL_SOURCE_DISTANCE_MODEL },
  152. // Distance Models
  153. { "AL_INVERSE_DISTANCE", AL_INVERSE_DISTANCE },
  154. { "AL_INVERSE_DISTANCE_CLAMPED", AL_INVERSE_DISTANCE_CLAMPED },
  155. { "AL_LINEAR_DISTANCE", AL_LINEAR_DISTANCE },
  156. { "AL_LINEAR_DISTANCE_CLAMPED", AL_LINEAR_DISTANCE_CLAMPED },
  157. { "AL_EXPONENT_DISTANCE", AL_EXPONENT_DISTANCE },
  158. { "AL_EXPONENT_DISTANCE_CLAMPED", AL_EXPONENT_DISTANCE_CLAMPED },
  159. // Filter types
  160. { "AL_FILTER_TYPE", AL_FILTER_TYPE },
  161. { "AL_FILTER_NULL", AL_FILTER_NULL },
  162. { "AL_FILTER_LOWPASS", AL_FILTER_LOWPASS },
  163. #if 0
  164. { "AL_FILTER_HIGHPASS", AL_FILTER_HIGHPASS },
  165. { "AL_FILTER_BANDPASS", AL_FILTER_BANDPASS },
  166. #endif
  167. // Filter params
  168. { "AL_LOWPASS_GAIN", AL_LOWPASS_GAIN },
  169. { "AL_LOWPASS_GAINHF", AL_LOWPASS_GAINHF },
  170. // Effect types
  171. { "AL_EFFECT_TYPE", AL_EFFECT_TYPE },
  172. { "AL_EFFECT_NULL", AL_EFFECT_NULL },
  173. { "AL_EFFECT_REVERB", AL_EFFECT_REVERB },
  174. { "AL_EFFECT_EAXREVERB", AL_EFFECT_EAXREVERB },
  175. #if 0
  176. { "AL_EFFECT_CHORUS", AL_EFFECT_CHORUS },
  177. { "AL_EFFECT_DISTORTION", AL_EFFECT_DISTORTION },
  178. #endif
  179. { "AL_EFFECT_ECHO", AL_EFFECT_ECHO },
  180. #if 0
  181. { "AL_EFFECT_FLANGER", AL_EFFECT_FLANGER },
  182. { "AL_EFFECT_FREQUENCY_SHIFTER", AL_EFFECT_FREQUENCY_SHIFTER },
  183. { "AL_EFFECT_VOCAL_MORPHER", AL_EFFECT_VOCAL_MORPHER },
  184. { "AL_EFFECT_PITCH_SHIFTER", AL_EFFECT_PITCH_SHIFTER },
  185. #endif
  186. { "AL_EFFECT_RING_MODULATOR", AL_EFFECT_RING_MODULATOR },
  187. #if 0
  188. { "AL_EFFECT_AUTOWAH", AL_EFFECT_AUTOWAH },
  189. { "AL_EFFECT_COMPRESSOR", AL_EFFECT_COMPRESSOR },
  190. { "AL_EFFECT_EQUALIZER", AL_EFFECT_EQUALIZER },
  191. #endif
  192. // Reverb params
  193. { "AL_REVERB_DENSITY", AL_REVERB_DENSITY },
  194. { "AL_REVERB_DIFFUSION", AL_REVERB_DIFFUSION },
  195. { "AL_REVERB_GAIN", AL_REVERB_GAIN },
  196. { "AL_REVERB_GAINHF", AL_REVERB_GAINHF },
  197. { "AL_REVERB_DECAY_TIME", AL_REVERB_DECAY_TIME },
  198. { "AL_REVERB_DECAY_HFRATIO", AL_REVERB_DECAY_HFRATIO },
  199. { "AL_REVERB_REFLECTIONS_GAIN", AL_REVERB_REFLECTIONS_GAIN },
  200. { "AL_REVERB_REFLECTIONS_DELAY", AL_REVERB_REFLECTIONS_DELAY },
  201. { "AL_REVERB_LATE_REVERB_GAIN", AL_REVERB_LATE_REVERB_GAIN },
  202. { "AL_REVERB_LATE_REVERB_DELAY", AL_REVERB_LATE_REVERB_DELAY },
  203. { "AL_REVERB_AIR_ABSORPTION_GAINHF", AL_REVERB_AIR_ABSORPTION_GAINHF },
  204. { "AL_REVERB_ROOM_ROLLOFF_FACTOR", AL_REVERB_ROOM_ROLLOFF_FACTOR },
  205. { "AL_REVERB_DECAY_HFLIMIT", AL_REVERB_DECAY_HFLIMIT },
  206. // EAX Reverb params
  207. { "AL_EAXREVERB_DENSITY", AL_EAXREVERB_DENSITY },
  208. { "AL_EAXREVERB_DIFFUSION", AL_EAXREVERB_DIFFUSION },
  209. { "AL_EAXREVERB_GAIN", AL_EAXREVERB_GAIN },
  210. { "AL_EAXREVERB_GAINHF", AL_EAXREVERB_GAINHF },
  211. { "AL_EAXREVERB_GAINLF", AL_EAXREVERB_GAINLF },
  212. { "AL_EAXREVERB_DECAY_TIME", AL_EAXREVERB_DECAY_TIME },
  213. { "AL_EAXREVERB_DECAY_HFRATIO", AL_EAXREVERB_DECAY_HFRATIO },
  214. { "AL_EAXREVERB_DECAY_LFRATIO", AL_EAXREVERB_DECAY_LFRATIO },
  215. { "AL_EAXREVERB_REFLECTIONS_GAIN", AL_EAXREVERB_REFLECTIONS_GAIN },
  216. { "AL_EAXREVERB_REFLECTIONS_DELAY", AL_EAXREVERB_REFLECTIONS_DELAY },
  217. { "AL_EAXREVERB_REFLECTIONS_PAN", AL_EAXREVERB_REFLECTIONS_PAN },
  218. { "AL_EAXREVERB_LATE_REVERB_GAIN", AL_EAXREVERB_LATE_REVERB_GAIN },
  219. { "AL_EAXREVERB_LATE_REVERB_DELAY", AL_EAXREVERB_LATE_REVERB_DELAY },
  220. { "AL_EAXREVERB_LATE_REVERB_PAN", AL_EAXREVERB_LATE_REVERB_PAN },
  221. { "AL_EAXREVERB_ECHO_TIME", AL_EAXREVERB_ECHO_TIME },
  222. { "AL_EAXREVERB_ECHO_DEPTH", AL_EAXREVERB_ECHO_DEPTH },
  223. { "AL_EAXREVERB_MODULATION_TIME", AL_EAXREVERB_MODULATION_TIME },
  224. { "AL_EAXREVERB_MODULATION_DEPTH", AL_EAXREVERB_MODULATION_DEPTH },
  225. { "AL_EAXREVERB_AIR_ABSORPTION_GAINHF", AL_EAXREVERB_AIR_ABSORPTION_GAINHF },
  226. { "AL_EAXREVERB_HFREFERENCE", AL_EAXREVERB_HFREFERENCE },
  227. { "AL_EAXREVERB_LFREFERENCE", AL_EAXREVERB_LFREFERENCE },
  228. { "AL_EAXREVERB_ROOM_ROLLOFF_FACTOR", AL_EAXREVERB_ROOM_ROLLOFF_FACTOR },
  229. { "AL_EAXREVERB_DECAY_HFLIMIT", AL_EAXREVERB_DECAY_HFLIMIT },
  230. // Echo params
  231. { "AL_ECHO_DELAY", AL_ECHO_DELAY },
  232. { "AL_ECHO_LRDELAY", AL_ECHO_LRDELAY },
  233. { "AL_ECHO_DAMPING", AL_ECHO_DAMPING },
  234. { "AL_ECHO_FEEDBACK", AL_ECHO_FEEDBACK },
  235. { "AL_ECHO_SPREAD", AL_ECHO_SPREAD },
  236. // Ring Modulator params
  237. { "AL_RING_MODULATOR_FREQUENCY", AL_RING_MODULATOR_FREQUENCY },
  238. { "AL_RING_MODULATOR_HIGHPASS_CUTOFF", AL_RING_MODULATOR_HIGHPASS_CUTOFF },
  239. { "AL_RING_MODULATOR_WAVEFORM", AL_RING_MODULATOR_WAVEFORM },
  240. // Default
  241. { NULL, (ALenum)0 }
  242. };
  243. AL_API ALboolean AL_APIENTRY alIsExtensionPresent(const ALchar *extName)
  244. {
  245. ALboolean bIsSupported = AL_FALSE;
  246. ALCcontext *pContext;
  247. const char *ptr;
  248. size_t len;
  249. pContext = GetContextSuspended();
  250. if(!pContext) return AL_FALSE;
  251. if(!extName)
  252. {
  253. alSetError(pContext, AL_INVALID_VALUE);
  254. ProcessContext(pContext);
  255. return AL_FALSE;
  256. }
  257. len = strlen(extName);
  258. ptr = pContext->ExtensionList;
  259. while(ptr && *ptr)
  260. {
  261. if(strncasecmp(ptr, extName, len) == 0 &&
  262. (ptr[len] == '\0' || isspace(ptr[len])))
  263. {
  264. bIsSupported = AL_TRUE;
  265. break;
  266. }
  267. if((ptr=strchr(ptr, ' ')) != NULL)
  268. {
  269. do {
  270. ++ptr;
  271. } while(isspace(*ptr));
  272. }
  273. }
  274. ProcessContext(pContext);
  275. return bIsSupported;
  276. }
  277. AL_API ALvoid* AL_APIENTRY alGetProcAddress(const ALchar *funcName)
  278. {
  279. if(!funcName)
  280. return NULL;
  281. return alcGetProcAddress(NULL, funcName);
  282. }
  283. AL_API ALenum AL_APIENTRY alGetEnumValue(const ALchar *enumName)
  284. {
  285. ALsizei i = 0;
  286. while(enumeration[i].enumName &&
  287. strcmp(enumeration[i].enumName, enumName) != 0)
  288. i++;
  289. return enumeration[i].value;
  290. }