openal_binding.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*
  2. Copyright (C) 2004 Michael Liebscher
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. /*
  16. * openal_binding.c: Interface to OpenAL library.
  17. *
  18. * Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
  19. * Date: 2004
  20. *
  21. */
  22. #include "../wolfiphone.h"
  23. #ifdef _WIN32
  24. HINSTANCE hinstOpenAL;
  25. #elif __unix__
  26. void *OpenALLib;
  27. #elif IPHONE
  28. void *OpenALLib;
  29. // from here on in this file, behave like unix
  30. #define __unix__ 1
  31. #else
  32. #error "Please define interface to OpenAL library!"
  33. #endif
  34. /*
  35. -----------------------------------------------------------------------------
  36. Function: OpenAL_Shutdown -Shutdown interface to OpenAL.
  37. Parameters: Nothing.
  38. Returns: Nothing.
  39. Notes:
  40. Unloads the specified Dynamic Link Library then NULLs out all the
  41. proc pointers.
  42. -----------------------------------------------------------------------------
  43. */
  44. PUBLIC void OpenAL_Shutdown( void )
  45. {
  46. #ifdef _WIN32
  47. if( hinstOpenAL )
  48. {
  49. FreeLibrary( hinstOpenAL );
  50. hinstOpenAL = NULL;
  51. }
  52. hinstOpenAL = NULL;
  53. #elif __unix__
  54. if( OpenALLib )
  55. {
  56. dlclose( OpenALLib );
  57. OpenALLib = NULL;
  58. }
  59. OpenALLib = NULL;
  60. #else
  61. #error "Please define interface to OpenAL library!"
  62. #endif
  63. pfalcCloseDevice = NULL;
  64. pfalcCreateContext = NULL;
  65. pfalcDestroyContext = NULL;
  66. pfalcGetContextsDevice = NULL;
  67. pfalcGetCurrentContext = NULL;
  68. pfalcGetEnumValue = NULL;
  69. pfalcGetError = NULL;
  70. pfalcGetIntegerv = NULL;
  71. pfalcGetProcAddress = NULL;
  72. pfalcGetString = NULL;
  73. pfalcIsExtensionPresent = NULL;
  74. pfalcMakeContextCurrent = NULL;
  75. pfalcOpenDevice = NULL;
  76. pfalcProcessContext = NULL;
  77. pfalcSuspendContext = NULL;
  78. pfalGenBuffers = NULL;
  79. pfalDeleteBuffers = NULL;
  80. pfalIsBuffer = NULL;
  81. pfalBufferData = NULL;
  82. pfalGetBufferf = NULL;
  83. pfalGetBufferi = NULL;
  84. pfalEnable = NULL;
  85. pfalDisable = NULL;
  86. pfalDopplerFactor = NULL;
  87. pfalDopplerVelocity = NULL;
  88. pfalDistanceModel = NULL;
  89. pfalGetBoolean = NULL;
  90. pfalGetBooleanv = NULL;
  91. pfalGetDouble = NULL;
  92. pfalGetDoublev = NULL;
  93. pfalGetFloat = NULL;
  94. pfalGetFloatv = NULL;
  95. pfalGetInteger = NULL;
  96. pfalGetIntegerv = NULL;
  97. pfalGetEnumValue = NULL;
  98. pfalGetError = NULL;
  99. pfalGetProcAddress = NULL;
  100. pfalGetString = NULL;
  101. pfalIsExtensionPresent = NULL;
  102. pfalIsEnabled = NULL;
  103. pfalListenerf = NULL;
  104. pfalListener3f = NULL;
  105. pfalListenerfv = NULL;
  106. pfalListeneri = NULL;
  107. pfalGetListenerf = NULL;
  108. pfalGetListener3f = NULL;
  109. pfalGetListenerfv = NULL;
  110. pfalGetListeneri = NULL;
  111. pfalGenSources = NULL;
  112. pfalDeleteSources = NULL;
  113. pfalIsSource = NULL;
  114. pfalSourcef = NULL;
  115. pfalSourcefv = NULL;
  116. pfalSource3f = NULL;
  117. pfalSourcei = NULL;
  118. pfalGetSourcef = NULL;
  119. pfalGetSource3f = NULL;
  120. pfalGetSourcefv = NULL;
  121. pfalGetSourcei = NULL;
  122. pfalSourcePlay = NULL;
  123. pfalSourcePlayv = NULL;
  124. pfalSourcePause = NULL;
  125. pfalSourcePausev = NULL;
  126. pfalSourceStop = NULL;
  127. pfalSourceStopv = NULL;
  128. pfalSourceRewind = NULL;
  129. pfalSourceRewindv = NULL;
  130. pfalSourceQueueBuffers = NULL;
  131. pfalSourceUnqueueBuffers = NULL;
  132. }
  133. #ifdef _WIN32
  134. #define GPA( a ) GetProcAddress( hinstOpenAL, a )
  135. #elif __unix__
  136. #define GPA( a ) dlsym( OpenALLib, a )
  137. #else
  138. #error "Please define interface to OpenAL library!"
  139. #endif
  140. /*
  141. -----------------------------------------------------------------------------
  142. Function: OpenAL_Init -Setup interface to OpenAL.
  143. Parameters: dllname -[in] Name of the OpenAL dynamic link library.
  144. Returns: true on success, otherwise false.
  145. Notes:
  146. This is responsible for binding our al function pointers to
  147. the appropriate OpenAL stuff. In Windows this means doing a
  148. LoadLibrary and a bunch of calls to GetProcAddress. On other
  149. operating systems we need to do the right thing, whatever that
  150. might be.
  151. -----------------------------------------------------------------------------
  152. */
  153. PUBLIC _boolean OpenAL_Init( const char *dllname )
  154. {
  155. #ifdef _WIN32
  156. char buffer[ 1024 ], *ptr;
  157. SearchPath( NULL, dllname, NULL, sizeof( buffer ) - 1, buffer, &ptr );
  158. Com_Printf( "...calling LoadLibrary( %s ): ", buffer );
  159. if( ( hinstOpenAL = LoadLibrary( dllname ) ) == 0 )
  160. {
  161. char *buf = NULL;
  162. Com_Printf( "failed\n" );
  163. FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  164. NULL, GetLastError(),
  165. MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
  166. (LPTSTR) &buf, 0, NULL );
  167. Com_Printf( "%s\n", buf );
  168. return false;
  169. }
  170. #elif __unix__
  171. Com_Printf( "...calling dlopen( %s ): ", dllname );
  172. if( ( OpenALLib = dlopen( dllname, RTLD_LAZY | RTLD_GLOBAL ) ) == 0 )
  173. {
  174. Com_Printf( "failed\n" );
  175. Com_Printf( "%s\n", dlerror() );
  176. return false;
  177. }
  178. #else
  179. #error "Please define interface to OpenAL library!"
  180. #endif
  181. Com_Printf( "succeeded\n" );
  182. if( ! (pfalcCloseDevice = (ALCCLOSEDEVICE)GPA( "alcCloseDevice" )) ) return false;
  183. if( ! (pfalcCreateContext = (ALCCREATECONTEXT)GPA( "alcCreateContext" )) ) return false;
  184. if( ! (pfalcDestroyContext = (ALCDESTROYCONTEXT)GPA( "alcDestroyContext" )) ) return false;
  185. if( ! (pfalcGetContextsDevice = (ALCGETCONTEXTSDEVICE)GPA( "alcGetContextsDevice" )) ) return false;
  186. if( ! (pfalcGetCurrentContext = (ALCGETCURRENTCONTEXT)GPA( "alcGetCurrentContext" )) ) return false;
  187. if( ! (pfalcGetEnumValue = (ALCGETENUMVALUE)GPA( "alcGetEnumValue" )) ) return false;
  188. if( ! (pfalcGetError = (ALCGETERROR)GPA( "alcGetError" )) ) return false;
  189. if( ! (pfalcGetIntegerv = (ALCGETINTEGERV)GPA( "alcGetIntegerv" )) ) return false;
  190. if( ! (pfalcGetProcAddress = (ALCGETPROCADDRESS)GPA( "alcGetProcAddress" )) ) return false;
  191. if( ! (pfalcGetString = (ALCGETSTRING)GPA( "alcGetString" )) ) return false;
  192. if( ! (pfalcIsExtensionPresent = (ALCISEXTENSIONPRESENT)GPA( "alcIsExtensionPresent" )) ) return false;
  193. if( ! (pfalcMakeContextCurrent = (ALCMAKECONTEXTCURRENT)GPA( "alcMakeContextCurrent" )) ) return false;
  194. if( ! (pfalcOpenDevice = (ALCOPENDEVICE)GPA( "alcOpenDevice" )) ) return false;
  195. if( ! (pfalcProcessContext = (ALCPROCESSCONTEXT)GPA( "alcProcessContext" )) ) return false;
  196. if( ! (pfalcSuspendContext = (ALCSUSPENDCONTEXT)GPA( "alcSuspendContext" )) ) return false;
  197. if( ! (pfalGenBuffers = (ALGENBUFFERS)GPA("alGenBuffers")) ) return false;
  198. if( ! (pfalDeleteBuffers = (ALDELETEBUFFERS)GPA("alDeleteBuffers")) ) return false;
  199. if( ! (pfalIsBuffer = (ALISBUFFER)GPA("alIsBuffer")) ) return false;
  200. if( ! (pfalBufferData = (ALBUFFERDATA)GPA("alBufferData")) ) return false;
  201. if( ! (pfalGetBufferf = (ALGETBUFFERF)GPA("alGetBufferf")) ) return false;
  202. if( ! (pfalGetBufferi = (ALGETBUFFERI)GPA("alGetBufferi")) ) return false;
  203. if( ! (pfalEnable = (ALENABLE)GPA("alEnable")) ) return false;
  204. if( ! (pfalDisable = (ALDISABLE)GPA("alDisable")) ) return false;
  205. if( ! (pfalDopplerFactor = (ALDOPPLERFACTOR)GPA("alDopplerFactor")) ) return false;
  206. if( ! (pfalDopplerVelocity = (ALDOPPLERVELOCITY)GPA("alDopplerVelocity")) ) return false;
  207. if( ! (pfalDistanceModel = (ALDISTANCEMODEL)GPA("alDistanceModel")) ) return false;
  208. if( ! (pfalGetBoolean = (ALGETBOOLEAN)GPA("alGetBoolean")) ) return false;
  209. if( ! (pfalGetBooleanv = (ALGETBOOLEANV)GPA("alGetBooleanv")) ) return false;
  210. if( ! (pfalGetDouble = (ALGETDOUBLE)GPA("alGetDouble")) ) return false;
  211. if( ! (pfalGetDoublev = (ALGETDOUBLEV)GPA("alGetDoublev")) ) return false;
  212. if( ! (pfalGetFloat = (ALGETFLOAT)GPA("alGetFloat")) ) return false;
  213. if( ! (pfalGetFloatv = (ALGETFLOATV)GPA("alGetFloatv")) ) return false;
  214. if( ! (pfalGetInteger = (ALGETINTEGER)GPA("alGetInteger")) ) return false;
  215. if( ! (pfalGetIntegerv = (ALGETINTEGERV)GPA("alGetIntegerv")) ) return false;
  216. if( ! (pfalGetEnumValue = (ALGETENUMVALUE)GPA("alGetEnumValue")) ) return false;
  217. if( ! (pfalGetError = (ALGETERROR)GPA("alGetError")) ) return false;
  218. if( ! (pfalGetProcAddress = (ALGETPROCADDRESS)GPA("alGetProcAddress")) ) return false;
  219. if( ! (pfalGetString = (ALGETSTRING)GPA("alGetString")) ) return false;
  220. if( ! (pfalIsExtensionPresent = (ALISEXTENSIONPRESENT)GPA("alIsExtensionPresent")) ) return false;
  221. if( ! (pfalIsEnabled = (ALISENABLED)GPA("alIsEnabled")) ) return false;
  222. if( ! (pfalListenerf = (ALLISTENERF)GPA("alListenerf")) ) return false;
  223. if( ! (pfalListener3f = (ALLISTENER3F)GPA("alListener3f")) ) return false;
  224. if( ! (pfalListenerfv = (ALLISTENERFV)GPA("alListenerfv")) ) return false;
  225. if( ! (pfalListeneri = (ALLISTENERI)GPA("alListeneri")) ) return false;
  226. if( ! (pfalGetListenerf = (ALGETLISTENERF)GPA("alGetListenerf")) ) return false;
  227. if( ! (pfalGetListener3f = (ALGETLISTENER3F)GPA("alGetListener3f")) ) return false;
  228. if( ! (pfalGetListenerfv = (ALGETLISTENERFV)GPA("alGetListenerfv")) ) return false;
  229. if( ! (pfalGetListeneri = (ALGETLISTENERI)GPA("alGetListeneri")) ) return false;
  230. if( ! (pfalGenSources = (ALGENSOURCES)GPA("alGenSources")) ) return false;
  231. if( ! (pfalDeleteSources = (ALDELETESOURCES)GPA("alDeleteSources")) ) return false;
  232. if( ! (pfalIsSource = (ALISSOURCE)GPA("alIsSource")) ) return false;
  233. if( ! (pfalSourcef = (ALSOURCEF)GPA("alSourcef")) ) return false;
  234. if( ! (pfalSourcefv = (ALSOURCEFV)GPA("alSourcefv")) ) return false;
  235. if( ! (pfalSource3f = (ALSOURCE3F)GPA("alSource3f")) ) return false;
  236. if( ! (pfalSourcei = (ALSOURCEI)GPA("alSourcei")) ) return false;
  237. if( ! (pfalGetSourcef = (ALGETSOURCEF)GPA("alGetSourcef")) ) return false;
  238. if( ! (pfalGetSource3f = (ALGETSOURCE3F)GPA("alGetSource3f")) ) return false;
  239. if( ! (pfalGetSourcefv = (ALGETSOURCEFV)GPA("alGetSourcefv")) ) return false;
  240. if( ! (pfalGetSourcei = (ALGETSOURCEI)GPA("alGetSourcei")) ) return false;
  241. if( ! (pfalSourcePlay = (ALSOURCEPLAY)GPA("alSourcePlay")) ) return false;
  242. if( ! (pfalSourcePlayv = (ALSOURCEPLAYV)GPA("alSourcePlayv")) ) return false;
  243. if( ! (pfalSourcePause = (ALSOURCEPAUSE)GPA("alSourcePause")) ) return false;
  244. if( ! (pfalSourcePausev = (ALSOURCEPAUSEV)GPA("alSourcePausev")) ) return false;
  245. if( ! (pfalSourceStop = (ALSOURCESTOP)GPA("alSourceStop")) ) return false;
  246. if( ! (pfalSourceStopv = (ALSOURCESTOPV)GPA("alSourceStopv")) ) return false;
  247. if( ! (pfalSourceRewind = (ALSOURCEREWIND)GPA("alSourceRewind")) ) return false;
  248. if( ! (pfalSourceRewindv = (ALSOURCEREWINDV)GPA("alSourceRewindv")) ) return false;
  249. if( ! (pfalSourceQueueBuffers = (ALSOURCEQUEUEBUFFERS)GPA("alSourceQueueBuffers")) ) return false;
  250. if( ! (pfalSourceUnqueueBuffers = (ALSOURCEUNQUEUEBUFFERS)GPA("alSourceUnqueueBuffers")) ) return false;
  251. return true;
  252. }