Export more functions and add corresponding tests
[audio-opusfile.git] / Opusfile.xs
CommitLineData
a3f1cbda
MG
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
eed4cab1
MG
14typedef OggOpusFile* Audio__Opusfile;
15typedef const OpusHead* Audio__Opusfile__Head;
16typedef const OpusTags* Audio__Opusfile__Tags;
17typedef const OpusPictureTag* Audio__Opusfile__PictureTag;
18
a3f1cbda
MG
19MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile PREFIX = op_
20
21PROTOTYPES: ENABLE
22INCLUDE: const-xs.inc
23
eed4cab1 24Audio::Opusfile
a3f1cbda
MG
25op_open_file(path)
26 const char *path;
27PREINIT:
28 int err;
5fbea9a2
MG
29C_ARGS:
30 path, &err
31POSTCALL:
a3f1cbda
MG
32 if(err)
33 croak("op_open_file returned error %d\n", err);
5fbea9a2 34
eed4cab1 35Audio::Opusfile
5fbea9a2
MG
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;
a3f1cbda
MG
55OUTPUT:
56 RETVAL
57
5fbea9a2 58
a3f1cbda
MG
59void
60DESTROY(of)
eed4cab1 61 Audio::Opusfile of;
a3f1cbda
MG
62CODE:
63 op_free(of);
64
5fbea9a2
MG
65bool
66op_seekable(of)
eed4cab1 67 Audio::Opusfile of;
5fbea9a2
MG
68
69int
70op_link_count(of)
eed4cab1 71 Audio::Opusfile of;
5fbea9a2
MG
72
73int
74op_serialno(of, li = -1)
eed4cab1 75 Audio::Opusfile of;
5fbea9a2
MG
76 int li;
77
dc986a40
MG
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;
84
85long
86op_pcm_total(of, li = -1)
87 Audio::Opusfile of;
88 int li;
89
eed4cab1 90Audio::Opusfile::Head
a3f1cbda 91op_head(of, li = -1)
eed4cab1 92 Audio::Opusfile of;
a3f1cbda
MG
93 int li;
94
eed4cab1 95Audio::Opusfile::Tags
a3f1cbda 96op_tags(of, li = -1)
eed4cab1 97 Audio::Opusfile of;
a3f1cbda
MG
98 int li;
99
dc986a40
MG
100# op_current_link not exported until we export the decoding API
101
102int
103op_bitrate(of, li = -1)
104 Audio::Opusfile of;
105 int li;
106
318673cc
MG
107long
108op_bitrate_instant(of)
109 Audio::Opusfile of;
110POSTCALL:
111 if(RETVAL < 0)
112 croak("op_bitrate_instant returned error %ld\n", RETVAL);
113
114long
115op_raw_tell(of)
116 Audio::Opusfile of;
117POSTCALL:
118 if(RETVAL < 0)
119 croak("op_raw_tell returned error %ld\n", RETVAL);
120
121long
122op_pcm_tell(of)
123 Audio::Opusfile of;
124POSTCALL:
125 if(RETVAL < 0)
126 croak("op_pcm_tell returned error %ld\n", RETVAL);
127
128NO_OUTPUT int
129op_raw_seek(of, offset)
130 Audio::Opusfile of;
131 long offset;
132POSTCALL:
133 if(RETVAL)
134 croak("op_raw_seek returned error %d\n", RETVAL);
135
136NO_OUTPUT int
137op_pcm_seek(of, offset)
138 Audio::Opusfile of;
139 long offset;
140POSTCALL:
141 if(RETVAL)
142 croak("op_pcm_seek returned error %d\n", RETVAL);
143
144NO_OUTPUT int
145op_set_gain_offset(of, gain_type, gain_offset_q8)
146 Audio::Opusfile of;
147 int gain_type;
148 int gain_offset_q8;
149POSTCALL:
150 if(RETVAL)
151 croak("op_set_gain_offset returned error %d\n", RETVAL);
152
153void
154op_set_dither_enabled(of, enabled)
155 Audio::Opusfile of;
156 int enabled;
157
158
159void
160op_read(of, bufsize = 1024 * 1024)
161 Audio::Opusfile of;
162 int bufsize;
163PREINIT:
164 opus_int16* buf;
165 int li, ret, chans, i;
166PPCODE:
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
177void
178op_read_float(of, bufsize = 1024 * 1024)
179 Audio::Opusfile of;
180 int bufsize;
181PREINIT:
182 float* buf;
183 int li, ret, chans, i;
184PPCODE:
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
195void
196op_read_stereo(of, bufsize = 1024 * 1024)
197 Audio::Opusfile of;
198 int bufsize;
199PREINIT:
200 opus_int16* buf;
201 int ret, i;
202PPCODE:
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
211void
212op_read_float_stereo(of, bufsize = 1024 * 1024)
213 Audio::Opusfile of;
214 int bufsize;
215PREINIT:
216 float* buf;
217 int ret, i;
218PPCODE:
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
dc986a40 228
a3f1cbda
MG
229MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile::Tags PREFIX = opus_tags_
230
231int
232opus_tags_query_count(tags, tag)
eed4cab1 233 Audio::Opusfile::Tags tags;
a3f1cbda
MG
234 const char* tag;
235
236const char*
237opus_tags_query(tags, tag, count = 0)
eed4cab1 238 Audio::Opusfile::Tags tags;
a3f1cbda
MG
239 const char* tag;
240 int count;
2f4b5b1b
MG
241
242MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile::PictureTag PREFIX = opus_picture_tag_
243
eed4cab1 244Audio::Opusfile::PictureTag
2f4b5b1b
MG
245opus_picture_tag_parse(tag)
246 const char *tag;
247PREINIT:
248 OpusPictureTag *pic;
249 int err;
250CODE:
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;
255OUTPUT:
256 RETVAL
257
258void
259DESTROY(pic)
eed4cab1 260 Audio::Opusfile::PictureTag pic
2f4b5b1b
MG
261CODE:
262 Safefree(pic);
263
264int
265type(pic)
eed4cab1 266 Audio::Opusfile::PictureTag pic;
2f4b5b1b
MG
267CODE:
268 RETVAL = pic->type;
269OUTPUT:
270 RETVAL
271
272const char*
273mime_type(pic)
eed4cab1 274 Audio::Opusfile::PictureTag pic;
2f4b5b1b
MG
275CODE:
276 RETVAL = pic->mime_type;
277OUTPUT:
278 RETVAL
279
280const char*
281description(pic)
eed4cab1 282 Audio::Opusfile::PictureTag pic;
2f4b5b1b
MG
283CODE:
284 RETVAL = pic->description;
285OUTPUT:
286 RETVAL
287
288int
289width(pic)
eed4cab1 290 Audio::Opusfile::PictureTag pic;
2f4b5b1b
MG
291CODE:
292 RETVAL = pic->width;
293OUTPUT:
294 RETVAL
295
296int
297height(pic)
eed4cab1 298 Audio::Opusfile::PictureTag pic;
2f4b5b1b
MG
299CODE:
300 RETVAL = pic->height;
301OUTPUT:
302 RETVAL
303
304int
305depth(pic)
eed4cab1 306 Audio::Opusfile::PictureTag pic;
2f4b5b1b
MG
307CODE:
308 RETVAL = pic->depth;
309OUTPUT:
310 RETVAL
311
312int
313colors(pic)
eed4cab1 314 Audio::Opusfile::PictureTag pic;
2f4b5b1b
MG
315CODE:
316 RETVAL = pic->colors;
317OUTPUT:
318 RETVAL
319
320int
321data_length(pic)
eed4cab1 322 Audio::Opusfile::PictureTag pic;
2f4b5b1b
MG
323CODE:
324 RETVAL = pic->data_length;
325OUTPUT:
326 RETVAL
327
328SV*
329data(pic)
eed4cab1 330 Audio::Opusfile::PictureTag pic;
2f4b5b1b
MG
331CODE:
332 RETVAL = newSVpvn(pic->data, pic->data_length);
333OUTPUT:
334 RETVAL
335
336int
337format(pic)
eed4cab1 338 Audio::Opusfile::PictureTag pic;
2f4b5b1b
MG
339CODE:
340 RETVAL = pic->format;
341OUTPUT:
342 RETVAL
343
344MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile::Head
345
346int
347version(head)
eed4cab1 348 Audio::Opusfile::Head head;
2f4b5b1b
MG
349CODE:
350 RETVAL = head->version;
351OUTPUT:
352 RETVAL
353
354int
355channel_count(head)
eed4cab1 356 Audio::Opusfile::Head head;
2f4b5b1b
MG
357CODE:
358 RETVAL = head->channel_count;
359OUTPUT:
360 RETVAL
361
362unsigned
363pre_skip(head)
eed4cab1 364 Audio::Opusfile::Head head;
2f4b5b1b
MG
365CODE:
366 RETVAL = head->pre_skip;
367OUTPUT:
368 RETVAL
369
370unsigned
371input_sample_rate(head)
eed4cab1 372 Audio::Opusfile::Head head;
2f4b5b1b
MG
373CODE:
374 RETVAL = head->input_sample_rate;
375OUTPUT:
376 RETVAL
377
aca25728
MG
378int
379output_gain(head)
380 Audio::Opusfile::Head head;
381CODE:
382 RETVAL = head->output_gain;
383OUTPUT:
384 RETVAL
385
2f4b5b1b
MG
386int
387mapping_family(head)
eed4cab1 388 Audio::Opusfile::Head head;
2f4b5b1b
MG
389CODE:
390 RETVAL = head->mapping_family;
391OUTPUT:
392 RETVAL
393
394int
395stream_count(head)
eed4cab1 396 Audio::Opusfile::Head head;
2f4b5b1b
MG
397CODE:
398 RETVAL = head->stream_count;
399OUTPUT:
400 RETVAL
401
402int
403coupled_count(head)
eed4cab1 404 Audio::Opusfile::Head head;
2f4b5b1b
MG
405CODE:
406 RETVAL = head->coupled_count;
407OUTPUT:
408 RETVAL
409
410int
411mapping(head, k)
eed4cab1 412 Audio::Opusfile::Head head;
b6589960 413 unsigned k;
2f4b5b1b 414CODE:
b6589960
MG
415 if(k >= OPUS_CHANNEL_COUNT_MAX)
416 croak("k must be less than %d\n", (int)OPUS_CHANNEL_COUNT_MAX);
2f4b5b1b
MG
417 RETVAL = (int) head->mapping[k];
418OUTPUT:
419 RETVAL
This page took 0.034725 seconds and 4 git commands to generate.