1 #define PERL_NO_GET_CONTEXT
8 /* op_free is both Perl_op_free and a function in opusfile */
10 #include <opus/opusfile.h>
12 #include "const-c.inc"
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;
19 MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile PREFIX = op_
33 croak("op_open_file returned error %d\n", err);
36 op_open_memory(const char *data, size_t length(data))
40 data, XSauto_length_of_data, &err
43 croak("op_open_memory returned error %d\n", err);
46 op_test(const char *data, size_t length(data))
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);
74 op_serialno(of, li = -1)
78 # op_channel_count is not exported; it can be obtained via op_head
81 op_raw_total(of, li = -1)
86 op_pcm_total(of, li = -1)
100 # op_current_link not exported until we export the decoding API
103 op_bitrate(of, li = -1)
108 op_bitrate_instant(of)
112 croak("op_bitrate_instant returned error %ld\n", RETVAL);
119 croak("op_raw_tell returned error %ld\n", RETVAL);
126 croak("op_pcm_tell returned error %ld\n", RETVAL);
129 op_raw_seek(of, offset)
134 croak("op_raw_seek returned error %d\n", RETVAL);
137 op_pcm_seek(of, offset)
142 croak("op_pcm_seek returned error %d\n", RETVAL);
145 op_set_gain_offset(of, gain_type, gain_offset_q8)
151 croak("op_set_gain_offset returned error %d\n", RETVAL);
154 op_set_dither_enabled(of, enabled)
160 op_read(of, bufsize = 1024 * 1024)
165 int li, ret, chans, i;
167 Newx(buf, bufsize, opus_int16);
168 ret = op_read(of, buf, bufsize, &li);
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])));
178 op_read_float(of, bufsize = 1024 * 1024)
183 int li, ret, chans, i;
185 Newx(buf, bufsize, float);
186 ret = op_read_float(of, buf, bufsize, &li);
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])));
196 op_read_stereo(of, bufsize = 1024 * 1024)
203 Newx(buf, bufsize, opus_int16);
204 ret = op_read_stereo(of, buf, bufsize);
206 croak("op_read_stereo returned error %d\n", ret);
208 for(i = 0 ; i < 2 * ret ; i++)
209 PUSHs(sv_2mortal(newSViv(buf[i])));
212 op_read_float_stereo(of, bufsize = 1024 * 1024)
219 Newx(buf, bufsize, float);
220 ret = op_read_float_stereo(of, buf, bufsize);
222 croak("op_read_float_stereo returned error %d\n", ret);
224 for(i = 0 ; i < 2 * ret ; i++)
225 PUSHs(sv_2mortal(newSVnv(buf[i])));
229 MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile::Tags PREFIX = opus_tags_
232 opus_tags_query_count(tags, tag)
233 Audio::Opusfile::Tags tags;
237 opus_tags_query(tags, tag, count = 0)
238 Audio::Opusfile::Tags tags;
242 MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile::PictureTag PREFIX = opus_picture_tag_
244 Audio::Opusfile::PictureTag
245 opus_picture_tag_parse(tag)
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);
260 Audio::Opusfile::PictureTag pic
266 Audio::Opusfile::PictureTag pic;
274 Audio::Opusfile::PictureTag pic;
276 RETVAL = pic->mime_type;
282 Audio::Opusfile::PictureTag pic;
284 RETVAL = pic->description;
290 Audio::Opusfile::PictureTag pic;
298 Audio::Opusfile::PictureTag pic;
300 RETVAL = pic->height;
306 Audio::Opusfile::PictureTag pic;
314 Audio::Opusfile::PictureTag pic;
316 RETVAL = pic->colors;
322 Audio::Opusfile::PictureTag pic;
324 RETVAL = pic->data_length;
330 Audio::Opusfile::PictureTag pic;
332 RETVAL = newSVpvn(pic->data, pic->data_length);
338 Audio::Opusfile::PictureTag pic;
340 RETVAL = pic->format;
344 MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile::Head
348 Audio::Opusfile::Head head;
350 RETVAL = head->version;
356 Audio::Opusfile::Head head;
358 RETVAL = head->channel_count;
364 Audio::Opusfile::Head head;
366 RETVAL = head->pre_skip;
371 input_sample_rate(head)
372 Audio::Opusfile::Head head;
374 RETVAL = head->input_sample_rate;
380 Audio::Opusfile::Head head;
382 RETVAL = head->output_gain;
388 Audio::Opusfile::Head head;
390 RETVAL = head->mapping_family;
396 Audio::Opusfile::Head head;
398 RETVAL = head->stream_count;
404 Audio::Opusfile::Head head;
406 RETVAL = head->coupled_count;
412 Audio::Opusfile::Head head;
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];