]> iEval git - audio-opusfile.git/blame_incremental - Opusfile.xs
Export more functions and add corresponding tests
[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;
84
85long
86op_pcm_total(of, li = -1)
87 Audio::Opusfile of;
88 int li;
89
90Audio::Opusfile::Head
91op_head(of, li = -1)
92 Audio::Opusfile of;
93 int li;
94
95Audio::Opusfile::Tags
96op_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
102int
103op_bitrate(of, li = -1)
104 Audio::Opusfile of;
105 int li;
106
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
228
229MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile::Tags PREFIX = opus_tags_
230
231int
232opus_tags_query_count(tags, tag)
233 Audio::Opusfile::Tags tags;
234 const char* tag;
235
236const char*
237opus_tags_query(tags, tag, count = 0)
238 Audio::Opusfile::Tags tags;
239 const char* tag;
240 int count;
241
242MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile::PictureTag PREFIX = opus_picture_tag_
243
244Audio::Opusfile::PictureTag
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)
260 Audio::Opusfile::PictureTag pic
261CODE:
262 Safefree(pic);
263
264int
265type(pic)
266 Audio::Opusfile::PictureTag pic;
267CODE:
268 RETVAL = pic->type;
269OUTPUT:
270 RETVAL
271
272const char*
273mime_type(pic)
274 Audio::Opusfile::PictureTag pic;
275CODE:
276 RETVAL = pic->mime_type;
277OUTPUT:
278 RETVAL
279
280const char*
281description(pic)
282 Audio::Opusfile::PictureTag pic;
283CODE:
284 RETVAL = pic->description;
285OUTPUT:
286 RETVAL
287
288int
289width(pic)
290 Audio::Opusfile::PictureTag pic;
291CODE:
292 RETVAL = pic->width;
293OUTPUT:
294 RETVAL
295
296int
297height(pic)
298 Audio::Opusfile::PictureTag pic;
299CODE:
300 RETVAL = pic->height;
301OUTPUT:
302 RETVAL
303
304int
305depth(pic)
306 Audio::Opusfile::PictureTag pic;
307CODE:
308 RETVAL = pic->depth;
309OUTPUT:
310 RETVAL
311
312int
313colors(pic)
314 Audio::Opusfile::PictureTag pic;
315CODE:
316 RETVAL = pic->colors;
317OUTPUT:
318 RETVAL
319
320int
321data_length(pic)
322 Audio::Opusfile::PictureTag pic;
323CODE:
324 RETVAL = pic->data_length;
325OUTPUT:
326 RETVAL
327
328SV*
329data(pic)
330 Audio::Opusfile::PictureTag pic;
331CODE:
332 RETVAL = newSVpvn(pic->data, pic->data_length);
333OUTPUT:
334 RETVAL
335
336int
337format(pic)
338 Audio::Opusfile::PictureTag pic;
339CODE:
340 RETVAL = pic->format;
341OUTPUT:
342 RETVAL
343
344MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile::Head
345
346int
347version(head)
348 Audio::Opusfile::Head head;
349CODE:
350 RETVAL = head->version;
351OUTPUT:
352 RETVAL
353
354int
355channel_count(head)
356 Audio::Opusfile::Head head;
357CODE:
358 RETVAL = head->channel_count;
359OUTPUT:
360 RETVAL
361
362unsigned
363pre_skip(head)
364 Audio::Opusfile::Head head;
365CODE:
366 RETVAL = head->pre_skip;
367OUTPUT:
368 RETVAL
369
370unsigned
371input_sample_rate(head)
372 Audio::Opusfile::Head head;
373CODE:
374 RETVAL = head->input_sample_rate;
375OUTPUT:
376 RETVAL
377
378int
379output_gain(head)
380 Audio::Opusfile::Head head;
381CODE:
382 RETVAL = head->output_gain;
383OUTPUT:
384 RETVAL
385
386int
387mapping_family(head)
388 Audio::Opusfile::Head head;
389CODE:
390 RETVAL = head->mapping_family;
391OUTPUT:
392 RETVAL
393
394int
395stream_count(head)
396 Audio::Opusfile::Head head;
397CODE:
398 RETVAL = head->stream_count;
399OUTPUT:
400 RETVAL
401
402int
403coupled_count(head)
404 Audio::Opusfile::Head head;
405CODE:
406 RETVAL = head->coupled_count;
407OUTPUT:
408 RETVAL
409
410int
411mapping(head, k)
412 Audio::Opusfile::Head head;
413 unsigned k;
414CODE:
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];
418OUTPUT:
419 RETVAL
This page took 0.01943 seconds and 4 git commands to generate.