dynamic_modplug.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. SDL_mixer: An audio mixer library based on the SDL library
  3. Copyright (C) 1997-2013 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #ifdef MODPLUG_MUSIC
  19. #include "SDL_loadso.h"
  20. #include "SDL_mixer.h"
  21. #include "dynamic_modplug.h"
  22. modplug_loader modplug = {
  23. 0, NULL
  24. };
  25. #ifdef MODPLUG_DYNAMIC
  26. int Mix_InitModPlug()
  27. {
  28. if ( modplug.loaded == 0 ) {
  29. modplug.handle = SDL_LoadObject(MODPLUG_DYNAMIC);
  30. if ( modplug.handle == NULL ) {
  31. return -1;
  32. }
  33. modplug.ModPlug_Load =
  34. (ModPlugFile* (*)(const void* data, int size))
  35. SDL_LoadFunction(modplug.handle, "ModPlug_Load");
  36. modplug.ModPlug_Unload =
  37. (void (*)(ModPlugFile* file))
  38. SDL_LoadFunction(modplug.handle, "ModPlug_Unload");
  39. modplug.ModPlug_Read =
  40. (int (*)(ModPlugFile* file, void* buffer, int size))
  41. SDL_LoadFunction(modplug.handle, "ModPlug_Read");
  42. modplug.ModPlug_Seek =
  43. (void (*)(ModPlugFile* file, int millisecond))
  44. SDL_LoadFunction(modplug.handle, "ModPlug_Seek");
  45. modplug.ModPlug_GetSettings =
  46. (void (*)(ModPlug_Settings* settings))
  47. SDL_LoadFunction(modplug.handle, "ModPlug_GetSettings");
  48. modplug.ModPlug_SetSettings =
  49. (void (*)(const ModPlug_Settings* settings))
  50. SDL_LoadFunction(modplug.handle, "ModPlug_SetSettings");
  51. modplug.ModPlug_SetMasterVolume =
  52. (void (*)(ModPlugFile* file,unsigned int cvol))
  53. SDL_LoadFunction(modplug.handle, "ModPlug_SetMasterVolume");
  54. }
  55. ++modplug.loaded;
  56. return 0;
  57. }
  58. void Mix_QuitModPlug()
  59. {
  60. if ( modplug.loaded == 0 ) {
  61. return;
  62. }
  63. if ( modplug.loaded == 1 ) {
  64. SDL_UnloadObject(modplug.handle);
  65. }
  66. --modplug.loaded;
  67. }
  68. #else
  69. int Mix_InitModPlug()
  70. {
  71. if ( modplug.loaded == 0 ) {
  72. #ifdef __MACOSX__
  73. extern ModPlugFile* ModPlug_Load(const void* data, int size) __attribute__((weak_import));
  74. if ( ModPlug_Load == NULL )
  75. {
  76. /* Missing weakly linked framework */
  77. Mix_SetError("Missing modplug.framework");
  78. return -1;
  79. }
  80. #endif // __MACOSX__
  81. modplug.ModPlug_Load = ModPlug_Load;
  82. modplug.ModPlug_Unload = ModPlug_Unload;
  83. modplug.ModPlug_Read = ModPlug_Read;
  84. modplug.ModPlug_Seek = ModPlug_Seek;
  85. modplug.ModPlug_GetSettings = ModPlug_GetSettings;
  86. modplug.ModPlug_SetSettings = ModPlug_SetSettings;
  87. modplug.ModPlug_SetMasterVolume = ModPlug_SetMasterVolume;
  88. }
  89. ++modplug.loaded;
  90. return 0;
  91. }
  92. void Mix_QuitModPlug()
  93. {
  94. if ( modplug.loaded == 0 ) {
  95. return;
  96. }
  97. if ( modplug.loaded == 1 ) {
  98. }
  99. --modplug.loaded;
  100. }
  101. #endif /* MODPLUG_DYNAMIC */
  102. #endif /* MODPLUG_MUSIC */