]> iEval git - audio-opusfile.git/blob - Opusfile.xs
40037e1bb73ec46b5875b767941047041d0456cc
[audio-opusfile.git] / Opusfile.xs
1 #define PERL_NO_GET_CONTEXT
2 #include "EXTERN.h"
3 #include "perl.h"
4 #include "XSUB.h"
5
6 #include "ppport.h"
7
8 /* op_free is both Perl_op_free and a function in opusfile */
9 #undef op_free
10 #include <opus/opusfile.h>
11
12 #include "const-c.inc"
13
14 typedef OggOpusFile* Audio__Opusfile;
15 typedef const OpusHead* Audio__Opusfile__Head;
16 typedef const OpusTags* Audio__Opusfile__Tags;
17 typedef const OpusPictureTag* Audio__Opusfile__PictureTag;
18
19 MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile PREFIX = op_
20
21 PROTOTYPES: ENABLE
22 INCLUDE: const-xs.inc
23
24 Audio::Opusfile
25 op_open_file(path)
26 const char *path;
27 PREINIT:
28 int err;
29 C_ARGS:
30 path, &err
31 POSTCALL:
32 if(err)
33 croak("op_open_file returned error %d\n", err);
34
35 Audio::Opusfile
36 op_open_memory(const char *data, size_t length(data))
37 PREINIT:
38 int err;
39 C_ARGS:
40 data, XSauto_length_of_data, &err
41 POSTCALL:
42 if(err)
43 croak("op_open_memory returned error %d\n", err);
44
45 bool
46 op_test(const char *data, size_t length(data))
47 PROTOTYPE: $
48 PREINIT:
49 int ret;
50 CODE:
51 ret = op_test (NULL, data, XSauto_length_of_data);
52 if(ret < 0 && ret != OP_ENOTFORMAT && ret != OP_EBADHEADER)
53 croak("op_test returned error %d\n", RETVAL);
54 RETVAL = !ret;
55 OUTPUT:
56 RETVAL
57
58
59 void
60 DESTROY(of)
61 Audio::Opusfile of;
62 CODE:
63 op_free(of);
64
65 bool
66 op_seekable(of)
67 Audio::Opusfile of;
68
69 int
70 op_link_count(of)
71 Audio::Opusfile of;
72
73 int
74 op_serialno(of, li = -1)
75 Audio::Opusfile of;
76 int li;
77
78 # op_channel_count is not exported; it can be obtained via op_head
79
80 long
81 op_raw_total(of, li = -1)
82 Audio::Opusfile of;
83 int li;
84
85 long
86 op_pcm_total(of, li = -1)
87 Audio::Opusfile of;
88 int li;
89
90 Audio::Opusfile::Head
91 op_head(of, li = -1)
92 Audio::Opusfile of;
93 int li;
94
95 Audio::Opusfile::Tags
96 op_tags(of, li = -1)
97 Audio::Opusfile of;
98 int li;
99
100 # op_current_link not exported until we export the decoding API
101
102 int
103 op_bitrate(of, li = -1)
104 Audio::Opusfile of;
105 int li;
106
107 long
108 op_bitrate_instant(of)
109 Audio::Opusfile of;
110 POSTCALL:
111 if(RETVAL < 0)
112 croak("op_bitrate_instant returned error %ld\n", RETVAL);
113
114 long
115 op_raw_tell(of)
116 Audio::Opusfile of;
117 POSTCALL:
118 if(RETVAL < 0)
119 croak("op_raw_tell returned error %ld\n", RETVAL);
120
121 long
122 op_pcm_tell(of)
123 Audio::Opusfile of;
124 POSTCALL:
125 if(RETVAL < 0)
126 croak("op_pcm_tell returned error %ld\n", RETVAL);
127
128 NO_OUTPUT int
129 op_raw_seek(of, offset)
130 Audio::Opusfile of;
131 long offset;
132 POSTCALL:
133 if(RETVAL)
134 croak("op_raw_seek returned error %d\n", RETVAL);
135
136 NO_OUTPUT int
137 op_pcm_seek(of, offset)
138 Audio::Opusfile of;
139 long offset;
140 POSTCALL:
141 if(RETVAL)
142 croak("op_pcm_seek returned error %d\n", RETVAL);
143
144 NO_OUTPUT int
145 op_set_gain_offset(of, gain_type, gain_offset_q8)
146 Audio::Opusfile of;
147 int gain_type;
148 int gain_offset_q8;
149 POSTCALL:
150 if(RETVAL)
151 croak("op_set_gain_offset returned error %d\n", RETVAL);
152
153 void
154 op_set_dither_enabled(of, enabled)
155 Audio::Opusfile of;
156 int enabled;
157
158
159 void
160 op_read(of, bufsize = 1024 * 1024)
161 Audio::Opusfile of;
162 int bufsize;
163 PREINIT:
164 opus_int16* buf;
165 int li, ret, chans, i;
166 PPCODE:
167 Newx(buf, bufsize, opus_int16);
168 ret = op_read(of, buf, bufsize, &li);
169 if(ret < 0)
170 croak("op_read returned error %d\n", ret);
171 chans = op_channel_count(of, li);
172 EXTEND(SP, chans * ret + 1);
173 PUSHs(sv_2mortal(newSViv(li)));
174 for(i = 0 ; i < chans * ret ; i++)
175 PUSHs(sv_2mortal(newSViv(buf[i])));
176
177 void
178 op_read_float(of, bufsize = 1024 * 1024)
179 Audio::Opusfile of;
180 int bufsize;
181 PREINIT:
182 float* buf;
183 int li, ret, chans, i;
184 PPCODE:
185 Newx(buf, bufsize, float);
186 ret = op_read_float(of, buf, bufsize, &li);
187 if(ret < 0)
188 croak("op_read_float returned error %d\n", ret);
189 chans = op_channel_count(of, li);
190 EXTEND(SP, chans * ret + 1);
191 PUSHs(sv_2mortal(newSViv(li)));
192 for(i = 0 ; i < chans * ret ; i++)
193 PUSHs(sv_2mortal(newSVnv(buf[i])));
194
195 void
196 op_read_stereo(of, bufsize = 1024 * 1024)
197 Audio::Opusfile of;
198 int bufsize;
199 PREINIT:
200 opus_int16* buf;
201 int ret, i;
202 PPCODE:
203 Newx(buf, bufsize, opus_int16);
204 ret = op_read_stereo(of, buf, bufsize);
205 if(ret < 0)
206 croak("op_read_stereo returned error %d\n", ret);
207 EXTEND(SP, 2 * ret);
208 for(i = 0 ; i < 2 * ret ; i++)
209 PUSHs(sv_2mortal(newSViv(buf[i])));
210
211 void
212 op_read_float_stereo(of, bufsize = 1024 * 1024)
213 Audio::Opusfile of;
214 int bufsize;
215 PREINIT:
216 float* buf;
217 int ret, i;
218 PPCODE:
219 Newx(buf, bufsize, float);
220 ret = op_read_float_stereo(of, buf, bufsize);
221 if(ret < 0)
222 croak("op_read_float_stereo returned error %d\n", ret);
223 EXTEND(SP, 2 * ret);
224 for(i = 0 ; i < 2 * ret ; i++)
225 PUSHs(sv_2mortal(newSVnv(buf[i])));
226
227
228
229 MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile::Tags PREFIX = opus_tags_
230
231 int
232 opus_tags_query_count(tags, tag)
233 Audio::Opusfile::Tags tags;
234 const char* tag;
235
236 const char*
237 opus_tags_query(tags, tag, count = 0)
238 Audio::Opusfile::Tags tags;
239 const char* tag;
240 int count;
241
242 MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile::PictureTag PREFIX = opus_picture_tag_
243
244 Audio::Opusfile::PictureTag
245 opus_picture_tag_parse(tag)
246 const char *tag;
247 PREINIT:
248 OpusPictureTag *pic;
249 int err;
250 CODE:
251 Newx(pic, 1, OpusPictureTag);
252 if(err = opus_picture_tag_parse(pic, tag))
253 croak("opus_picture_tag_parse returned error %d\n", err);
254 RETVAL = pic;
255 OUTPUT:
256 RETVAL
257
258 void
259 DESTROY(pic)
260 Audio::Opusfile::PictureTag pic
261 CODE:
262 Safefree(pic);
263
264 int
265 type(pic)
266 Audio::Opusfile::PictureTag pic;
267 CODE:
268 RETVAL = pic->type;
269 OUTPUT:
270 RETVAL
271
272 const char*
273 mime_type(pic)
274 Audio::Opusfile::PictureTag pic;
275 CODE:
276 RETVAL = pic->mime_type;
277 OUTPUT:
278 RETVAL
279
280 const char*
281 description(pic)
282 Audio::Opusfile::PictureTag pic;
283 CODE:
284 RETVAL = pic->description;
285 OUTPUT:
286 RETVAL
287
288 int
289 width(pic)
290 Audio::Opusfile::PictureTag pic;
291 CODE:
292 RETVAL = pic->width;
293 OUTPUT:
294 RETVAL
295
296 int
297 height(pic)
298 Audio::Opusfile::PictureTag pic;
299 CODE:
300 RETVAL = pic->height;
301 OUTPUT:
302 RETVAL
303
304 int
305 depth(pic)
306 Audio::Opusfile::PictureTag pic;
307 CODE:
308 RETVAL = pic->depth;
309 OUTPUT:
310 RETVAL
311
312 int
313 colors(pic)
314 Audio::Opusfile::PictureTag pic;
315 CODE:
316 RETVAL = pic->colors;
317 OUTPUT:
318 RETVAL
319
320 int
321 data_length(pic)
322 Audio::Opusfile::PictureTag pic;
323 CODE:
324 RETVAL = pic->data_length;
325 OUTPUT:
326 RETVAL
327
328 SV*
329 data(pic)
330 Audio::Opusfile::PictureTag pic;
331 CODE:
332 RETVAL = newSVpvn(pic->data, pic->data_length);
333 OUTPUT:
334 RETVAL
335
336 int
337 format(pic)
338 Audio::Opusfile::PictureTag pic;
339 CODE:
340 RETVAL = pic->format;
341 OUTPUT:
342 RETVAL
343
344 MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile::Head
345
346 int
347 version(head)
348 Audio::Opusfile::Head head;
349 CODE:
350 RETVAL = head->version;
351 OUTPUT:
352 RETVAL
353
354 int
355 channel_count(head)
356 Audio::Opusfile::Head head;
357 CODE:
358 RETVAL = head->channel_count;
359 OUTPUT:
360 RETVAL
361
362 unsigned
363 pre_skip(head)
364 Audio::Opusfile::Head head;
365 CODE:
366 RETVAL = head->pre_skip;
367 OUTPUT:
368 RETVAL
369
370 unsigned
371 input_sample_rate(head)
372 Audio::Opusfile::Head head;
373 CODE:
374 RETVAL = head->input_sample_rate;
375 OUTPUT:
376 RETVAL
377
378 int
379 output_gain(head)
380 Audio::Opusfile::Head head;
381 CODE:
382 RETVAL = head->output_gain;
383 OUTPUT:
384 RETVAL
385
386 int
387 mapping_family(head)
388 Audio::Opusfile::Head head;
389 CODE:
390 RETVAL = head->mapping_family;
391 OUTPUT:
392 RETVAL
393
394 int
395 stream_count(head)
396 Audio::Opusfile::Head head;
397 CODE:
398 RETVAL = head->stream_count;
399 OUTPUT:
400 RETVAL
401
402 int
403 coupled_count(head)
404 Audio::Opusfile::Head head;
405 CODE:
406 RETVAL = head->coupled_count;
407 OUTPUT:
408 RETVAL
409
410 int
411 mapping(head, k)
412 Audio::Opusfile::Head head;
413 unsigned k;
414 CODE:
415 if(k >= OPUS_CHANNEL_COUNT_MAX)
416 croak("k must be less than %d\n", (int)OPUS_CHANNEL_COUNT_MAX);
417 RETVAL = (int) head->mapping[k];
418 OUTPUT:
419 RETVAL
This page took 0.059073 seconds and 4 git commands to generate.