/src/Mixer/Channels.xs

http://github.com/PerlGameDev/SDL · Unknown · 233 lines · 192 code · 41 blank · 0 comment · 0 complexity · 92a0aae59396f699957dea9d0afa282d MD5 · raw file

  1. #include "EXTERN.h"
  2. #include "perl.h"
  3. #include "XSUB.h"
  4. #define NEED_sv_2pv_flag
  5. #include "ppport.h"
  6. #include "defines.h"
  7. #include "helper.h"
  8. #ifndef aTHX_
  9. #define aTHX_
  10. #endif
  11. #include <SDL.h>
  12. #ifdef HAVE_SDL_MIXER
  13. #include <SDL_mixer.h>
  14. #endif
  15. #ifdef HAVE_SMPEG
  16. #include <smpeg/smpeg.h>
  17. #ifdef HAVE_SDL_MIXER
  18. static int sdl_perl_use_smpeg_audio = 0;
  19. #endif
  20. #endif
  21. #ifdef USE_THREADS
  22. static SV * cb = (SV*)NULL;
  23. void callback(int channel)
  24. {
  25. PERL_SET_CONTEXT(parent_perl);
  26. dSP;
  27. ENTER;
  28. SAVETMPS;
  29. PUSHMARK(SP);
  30. XPUSHs(sv_2mortal(newSViv(channel)));
  31. PUTBACK;
  32. if(cb)
  33. call_sv(cb, G_VOID);
  34. FREETMPS;
  35. LEAVE;
  36. }
  37. #endif
  38. MODULE = SDL::Mixer::Channels PACKAGE = SDL::Mixer::Channels PREFIX = mixchan_
  39. =for documentation
  40. SDL_mixer bindings
  41. See: http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html
  42. =cut
  43. #ifdef HAVE_SDL_MIXER
  44. int
  45. mixchan_allocate_channels ( number )
  46. int number
  47. CODE:
  48. RETVAL = Mix_AllocateChannels(number);
  49. OUTPUT:
  50. RETVAL
  51. int
  52. mixchan_volume ( channel, volume )
  53. int channel
  54. int volume
  55. CODE:
  56. RETVAL = Mix_Volume(channel,volume);
  57. OUTPUT:
  58. RETVAL
  59. int
  60. mixchan_play_channel ( channel, chunk, loops )
  61. int channel
  62. Mix_Chunk *chunk
  63. int loops
  64. CODE:
  65. RETVAL = Mix_PlayChannel(channel,chunk,loops);
  66. OUTPUT:
  67. RETVAL
  68. int
  69. mixchan_play_channel_timed ( channel, chunk, loops, ticks )
  70. int channel
  71. Mix_Chunk *chunk
  72. int loops
  73. int ticks
  74. CODE:
  75. RETVAL = Mix_PlayChannelTimed(channel,chunk,loops,ticks);
  76. OUTPUT:
  77. RETVAL
  78. int
  79. mixchan_fade_in_channel ( channel, chunk, loops, ms )
  80. int channel
  81. Mix_Chunk *chunk
  82. int loops
  83. int ms
  84. CODE:
  85. RETVAL = Mix_FadeInChannel(channel,chunk,loops,ms);
  86. OUTPUT:
  87. RETVAL
  88. int
  89. mixchan_fade_in_channel_timed ( channel, chunk, loops, ms, ticks )
  90. int channel
  91. Mix_Chunk *chunk
  92. int loops
  93. int ticks
  94. int ms
  95. CODE:
  96. RETVAL = Mix_FadeInChannelTimed(channel,chunk,loops,ms,ticks);
  97. OUTPUT:
  98. RETVAL
  99. void
  100. mixchan_pause ( channel )
  101. int channel
  102. CODE:
  103. Mix_Pause(channel);
  104. void
  105. mixchan_resume ( channel )
  106. int channel
  107. CODE:
  108. Mix_Resume(channel);
  109. int
  110. mixchan_halt_channel ( channel )
  111. int channel
  112. CODE:
  113. RETVAL = Mix_HaltChannel(channel);
  114. OUTPUT:
  115. RETVAL
  116. int
  117. mixchan_expire_channel ( channel, ticks )
  118. int channel
  119. int ticks
  120. CODE:
  121. RETVAL = Mix_ExpireChannel ( channel,ticks);
  122. OUTPUT:
  123. RETVAL
  124. int
  125. mixchan_fade_out_channel ( which, ms )
  126. int which
  127. int ms
  128. CODE:
  129. RETVAL = Mix_FadeOutChannel(which,ms);
  130. OUTPUT:
  131. RETVAL
  132. #ifdef USE_THREADS
  133. void
  134. mixchan_channel_finished( fn )
  135. SV* fn
  136. CODE:
  137. if (cb == (SV*)NULL)
  138. cb = newSVsv(fn);
  139. else
  140. SvSetSV(cb, fn);
  141. GET_TLS_CONTEXT;
  142. Mix_ChannelFinished(&callback);
  143. #else
  144. void
  145. mixchan_channel_finished( fn )
  146. SV* fn
  147. CODE:
  148. warn("Perl need to be compiled with 'useithreads' for SDL::Mixer::Channels::channel_finished( cb )");
  149. #endif
  150. int
  151. mixchan_playing( channel )
  152. int channel
  153. CODE:
  154. RETVAL = Mix_Playing(channel);
  155. OUTPUT:
  156. RETVAL
  157. int
  158. mixchan_paused ( channel )
  159. int channel
  160. CODE:
  161. RETVAL = Mix_Paused(channel);
  162. OUTPUT:
  163. RETVAL
  164. Mix_Fading
  165. mixchan_fading_channel( which )
  166. int which
  167. CODE:
  168. RETVAL = Mix_FadingChannel(which);
  169. OUTPUT:
  170. RETVAL
  171. Mix_Chunk *
  172. mixchan_get_chunk(chan)
  173. int chan
  174. PREINIT:
  175. char* CLASS = "SDL::Mixer::MixChunk";
  176. CODE:
  177. Mix_Chunk *chunk = Mix_GetChunk(chan);
  178. #ifdef _WIN32
  179. Mix_Chunk *copy = msvcrt_malloc(sizeof(Mix_Chunk));
  180. copy->abuf = msvcrt_malloc( chunk->alen );
  181. #else
  182. Mix_Chunk *copy = malloc(sizeof(Mix_Chunk));
  183. copy->abuf = malloc( chunk->alen );
  184. #endif
  185. memcpy( copy->abuf, chunk->abuf, chunk->alen );
  186. copy->alen = chunk->alen;
  187. copy->volume = chunk->volume;
  188. copy->allocated = 1;
  189. RETVAL = copy;
  190. OUTPUT:
  191. RETVAL
  192. #endif