PageRenderTime 27ms CodeModel.GetById 18ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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