openal.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #if _WIN32
  2. #include <windows.h>
  3. static HMODULE openAL;
  4. int LoadOpenAL(){
  5. openAL=LoadLibrary( "OpenAL32.dll" );
  6. return openAL!=0;
  7. }
  8. void *GetOpenALFunction( const char *fname ){
  9. if( !openAL ) return 0;
  10. return GetProcAddress( openAL,fname );
  11. }
  12. #endif
  13. #if __APPLE__
  14. #import <CoreFoundation/CoreFoundation.h>
  15. static CFBundleRef openAL;
  16. static CFBundleRef OpenBundle( const char *path ){
  17. CFURLRef url;
  18. CFStringRef str;
  19. CFBundleRef bundle;
  20. str=CFStringCreateWithCString( kCFAllocatorDefault,path,kCFStringEncodingASCII );
  21. url=CFURLCreateWithFileSystemPath( kCFAllocatorDefault,str,kCFURLPOSIXPathStyle,true );
  22. bundle=CFBundleCreate( kCFAllocatorDefault,url );
  23. CFRelease( url );
  24. CFRelease( str );
  25. return bundle;
  26. }
  27. int LoadOpenAL(){
  28. openAL=OpenBundle( "/System/Library/Frameworks/OpenAL.framework" );
  29. if( !openAL ) openAL=OpenBundle( "/Library/Frameworks/OpenAL.framework" );
  30. return openAL!=0;
  31. }
  32. void *GetOpenALFunction( const char *fname ){
  33. void *p;
  34. CFStringRef str;
  35. if( !openAL ) return 0;
  36. str=CFStringCreateWithCString( kCFAllocatorDefault,fname,kCFStringEncodingASCII );
  37. p=CFBundleGetFunctionPointerForName( openAL,str );
  38. CFRelease( str );
  39. return p;
  40. }
  41. #endif
  42. #if __linux__
  43. #include <dlfcn.h>
  44. static void *openAL;
  45. int LoadOpenAL(){
  46. openAL=dlopen( "libopenal.so",RTLD_NOW );
  47. if( !openAL ) openAL=dlopen( "libopenal.so.0",RTLD_NOW );
  48. if( !openAL ) openAL=dlopen( "libopenal.so.0.0.8",RTLD_NOW );
  49. return openAL!=0;
  50. }
  51. void *GetOpenALFunction( const char *fname ){
  52. if( !openAL ) return 0;
  53. return dlsym( openAL,fname );
  54. }
  55. #endif