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
22 static int sdl_perl_use_smpeg_audio = 0;
23 #endif
24 #endif
25
26 #ifdef USE_THREADS
27 static SV * cb = (SV*)NULL;
28
callback(int channel)29 void 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
48 MODULE = SDL::Mixer::Channels PACKAGE = SDL::Mixer::Channels PREFIX = mixchan_
49
50 =for documentation
51
52 SDL_mixer bindings
53
54 See: http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer.html
55
56 =cut
57
58 #ifdef HAVE_SDL_MIXER
59
60 int
61 mixchan_allocate_channels ( number )
62 int number
63 CODE:
64 RETVAL = Mix_AllocateChannels(number);
65 OUTPUT:
66 RETVAL
67
68
69 int
70 mixchan_volume ( channel, volume )
71 int channel
72 int volume
73 CODE:
74 RETVAL = Mix_Volume(channel,volume);
75 OUTPUT:
76 RETVAL
77
78 int
79 mixchan_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
88 int
89 mixchan_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
100 int
101 mixchan_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
111 int
112 mixchan_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
123 void
124 mixchan_pause ( channel )
125 int channel
126 CODE:
127 Mix_Pause(channel);
128
129 void
130 mixchan_resume ( channel )
131 int channel
132 CODE:
133 Mix_Resume(channel);
134
135 int
136 mixchan_halt_channel ( channel )
137 int channel
138 CODE:
139 RETVAL = Mix_HaltChannel(channel);
140 OUTPUT:
141 RETVAL
142
143 int
144 mixchan_expire_channel ( channel, ticks )
145 int channel
146 int ticks
147 CODE:
148 RETVAL = Mix_ExpireChannel ( channel,ticks);
149 OUTPUT:
150 RETVAL
151
152 int
153 mixchan_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
163 void
164 mixchan_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
177 void
178 mixchan_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
185 int
186 mixchan_playing( channel )
187 int channel
188 CODE:
189 RETVAL = Mix_Playing(channel);
190 OUTPUT:
191 RETVAL
192
193 int
194 mixchan_paused ( channel )
195 int channel
196 CODE:
197 RETVAL = Mix_Paused(channel);
198 OUTPUT:
199 RETVAL
200
201 Mix_Fading
202 mixchan_fading_channel( which )
203 int which
204 CODE:
205 RETVAL = Mix_FadingChannel(which);
206 OUTPUT:
207 RETVAL
208
209
210 Mix_Chunk *
211 mixchan_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
234