dynamic_mp3.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 MP3_MUSIC
  19. #include "SDL_loadso.h"
  20. #include "SDL_mixer.h"
  21. #include "dynamic_mp3.h"
  22. smpeg_loader smpeg = {
  23. 0, NULL
  24. };
  25. #ifdef MP3_DYNAMIC
  26. int Mix_InitMP3()
  27. {
  28. if ( smpeg.loaded == 0 ) {
  29. smpeg.handle = SDL_LoadObject(MP3_DYNAMIC);
  30. if ( smpeg.handle == NULL ) {
  31. return -1;
  32. }
  33. smpeg.SMPEG_actualSpec =
  34. (void (*)( SMPEG *, SDL_AudioSpec * ))
  35. SDL_LoadFunction(smpeg.handle, "SMPEG_actualSpec");
  36. if ( smpeg.SMPEG_actualSpec == NULL ) {
  37. SDL_UnloadObject(smpeg.handle);
  38. return -1;
  39. }
  40. smpeg.SMPEG_delete =
  41. (void (*)( SMPEG* ))
  42. SDL_LoadFunction(smpeg.handle, "SMPEG_delete");
  43. if ( smpeg.SMPEG_delete == NULL ) {
  44. SDL_UnloadObject(smpeg.handle);
  45. return -1;
  46. }
  47. smpeg.SMPEG_enableaudio =
  48. (void (*)( SMPEG*, int ))
  49. SDL_LoadFunction(smpeg.handle, "SMPEG_enableaudio");
  50. if ( smpeg.SMPEG_enableaudio == NULL ) {
  51. SDL_UnloadObject(smpeg.handle);
  52. return -1;
  53. }
  54. smpeg.SMPEG_enablevideo =
  55. (void (*)( SMPEG*, int ))
  56. SDL_LoadFunction(smpeg.handle, "SMPEG_enablevideo");
  57. if ( smpeg.SMPEG_enablevideo == NULL ) {
  58. SDL_UnloadObject(smpeg.handle);
  59. return -1;
  60. }
  61. smpeg.SMPEG_new_rwops =
  62. (SMPEG* (*)(SDL_RWops *, SMPEG_Info*, int, int))
  63. SDL_LoadFunction(smpeg.handle, "SMPEG_new_rwops");
  64. if ( smpeg.SMPEG_new_rwops == NULL ) {
  65. SDL_UnloadObject(smpeg.handle);
  66. return -1;
  67. }
  68. smpeg.SMPEG_play =
  69. (void (*)( SMPEG* ))
  70. SDL_LoadFunction(smpeg.handle, "SMPEG_play");
  71. if ( smpeg.SMPEG_play == NULL ) {
  72. SDL_UnloadObject(smpeg.handle);
  73. return -1;
  74. }
  75. smpeg.SMPEG_playAudio =
  76. (int (*)( SMPEG *, Uint8 *, int ))
  77. SDL_LoadFunction(smpeg.handle, "SMPEG_playAudio");
  78. if ( smpeg.SMPEG_playAudio == NULL ) {
  79. SDL_UnloadObject(smpeg.handle);
  80. return -1;
  81. }
  82. smpeg.SMPEG_rewind =
  83. (void (*)( SMPEG* ))
  84. SDL_LoadFunction(smpeg.handle, "SMPEG_rewind");
  85. if ( smpeg.SMPEG_rewind == NULL ) {
  86. SDL_UnloadObject(smpeg.handle);
  87. return -1;
  88. }
  89. smpeg.SMPEG_setvolume =
  90. (void (*)( SMPEG*, int ))
  91. SDL_LoadFunction(smpeg.handle, "SMPEG_setvolume");
  92. if ( smpeg.SMPEG_setvolume == NULL ) {
  93. SDL_UnloadObject(smpeg.handle);
  94. return -1;
  95. }
  96. smpeg.SMPEG_skip =
  97. (void (*)( SMPEG*, float ))
  98. SDL_LoadFunction(smpeg.handle, "SMPEG_skip");
  99. if ( smpeg.SMPEG_skip == NULL ) {
  100. SDL_UnloadObject(smpeg.handle);
  101. return -1;
  102. }
  103. smpeg.SMPEG_status =
  104. (SMPEGstatus (*)( SMPEG* ))
  105. SDL_LoadFunction(smpeg.handle, "SMPEG_status");
  106. if ( smpeg.SMPEG_status == NULL ) {
  107. SDL_UnloadObject(smpeg.handle);
  108. return -1;
  109. }
  110. smpeg.SMPEG_stop =
  111. (void (*)( SMPEG* ))
  112. SDL_LoadFunction(smpeg.handle, "SMPEG_stop");
  113. if ( smpeg.SMPEG_stop == NULL ) {
  114. SDL_UnloadObject(smpeg.handle);
  115. return -1;
  116. }
  117. }
  118. ++smpeg.loaded;
  119. return 0;
  120. }
  121. void Mix_QuitMP3()
  122. {
  123. if ( smpeg.loaded == 0 ) {
  124. return;
  125. }
  126. if ( smpeg.loaded == 1 ) {
  127. SDL_UnloadObject(smpeg.handle);
  128. }
  129. --smpeg.loaded;
  130. }
  131. #else
  132. int Mix_InitMP3()
  133. {
  134. if ( smpeg.loaded == 0 ) {
  135. #ifdef __MACOSX__
  136. extern SMPEG* SMPEG_new_rwops(SDL_RWops*, SMPEG_Info*, int, int) __attribute__((weak_import));
  137. if ( SMPEG_new_rwops == NULL )
  138. {
  139. /* Missing weakly linked framework */
  140. Mix_SetError("Missing smpeg2.framework");
  141. return -1;
  142. }
  143. #endif // __MACOSX__
  144. smpeg.SMPEG_actualSpec = SMPEG_actualSpec;
  145. smpeg.SMPEG_delete = SMPEG_delete;
  146. smpeg.SMPEG_enableaudio = SMPEG_enableaudio;
  147. smpeg.SMPEG_enablevideo = SMPEG_enablevideo;
  148. smpeg.SMPEG_new_rwops = SMPEG_new_rwops;
  149. smpeg.SMPEG_play = SMPEG_play;
  150. smpeg.SMPEG_playAudio = SMPEG_playAudio;
  151. smpeg.SMPEG_rewind = SMPEG_rewind;
  152. smpeg.SMPEG_setvolume = SMPEG_setvolume;
  153. smpeg.SMPEG_skip = SMPEG_skip;
  154. smpeg.SMPEG_status = SMPEG_status;
  155. smpeg.SMPEG_stop = SMPEG_stop;
  156. }
  157. ++smpeg.loaded;
  158. return 0;
  159. }
  160. void Mix_QuitMP3()
  161. {
  162. if ( smpeg.loaded == 0 ) {
  163. return;
  164. }
  165. if ( smpeg.loaded == 1 ) {
  166. }
  167. --smpeg.loaded;
  168. }
  169. #endif /* MP3_DYNAMIC */
  170. #endif /* MP3_MUSIC */