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