From: Marius Gavrilescu Date: Sat, 10 Dec 2016 17:17:04 +0000 (+0200) Subject: Export more functions and add corresponding tests X-Git-Tag: 0.005~3 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;ds=sidebyside;h=318673cc096ad920881afd23088a68f766902734;p=audio-opusfile.git Export more functions and add corresponding tests --- diff --git a/Opusfile.xs b/Opusfile.xs index a8bd27b..40037e1 100644 --- a/Opusfile.xs +++ b/Opusfile.xs @@ -104,8 +104,127 @@ op_bitrate(of, li = -1) Audio::Opusfile of; int li; -# op_bitrate_instant, op_raw_tell, op_pcm_tell not exported until we -# export the decoding API +long +op_bitrate_instant(of) + Audio::Opusfile of; +POSTCALL: + if(RETVAL < 0) + croak("op_bitrate_instant returned error %ld\n", RETVAL); + +long +op_raw_tell(of) + Audio::Opusfile of; +POSTCALL: + if(RETVAL < 0) + croak("op_raw_tell returned error %ld\n", RETVAL); + +long +op_pcm_tell(of) + Audio::Opusfile of; +POSTCALL: + if(RETVAL < 0) + croak("op_pcm_tell returned error %ld\n", RETVAL); + +NO_OUTPUT int +op_raw_seek(of, offset) + Audio::Opusfile of; + long offset; +POSTCALL: + if(RETVAL) + croak("op_raw_seek returned error %d\n", RETVAL); + +NO_OUTPUT int +op_pcm_seek(of, offset) + Audio::Opusfile of; + long offset; +POSTCALL: + if(RETVAL) + croak("op_pcm_seek returned error %d\n", RETVAL); + +NO_OUTPUT int +op_set_gain_offset(of, gain_type, gain_offset_q8) + Audio::Opusfile of; + int gain_type; + int gain_offset_q8; +POSTCALL: + if(RETVAL) + croak("op_set_gain_offset returned error %d\n", RETVAL); + +void +op_set_dither_enabled(of, enabled) + Audio::Opusfile of; + int enabled; + + +void +op_read(of, bufsize = 1024 * 1024) + Audio::Opusfile of; + int bufsize; +PREINIT: + opus_int16* buf; + int li, ret, chans, i; +PPCODE: + Newx(buf, bufsize, opus_int16); + ret = op_read(of, buf, bufsize, &li); + if(ret < 0) + croak("op_read returned error %d\n", ret); + chans = op_channel_count(of, li); + EXTEND(SP, chans * ret + 1); + PUSHs(sv_2mortal(newSViv(li))); + for(i = 0 ; i < chans * ret ; i++) + PUSHs(sv_2mortal(newSViv(buf[i]))); + +void +op_read_float(of, bufsize = 1024 * 1024) + Audio::Opusfile of; + int bufsize; +PREINIT: + float* buf; + int li, ret, chans, i; +PPCODE: + Newx(buf, bufsize, float); + ret = op_read_float(of, buf, bufsize, &li); + if(ret < 0) + croak("op_read_float returned error %d\n", ret); + chans = op_channel_count(of, li); + EXTEND(SP, chans * ret + 1); + PUSHs(sv_2mortal(newSViv(li))); + for(i = 0 ; i < chans * ret ; i++) + PUSHs(sv_2mortal(newSVnv(buf[i]))); + +void +op_read_stereo(of, bufsize = 1024 * 1024) + Audio::Opusfile of; + int bufsize; +PREINIT: + opus_int16* buf; + int ret, i; +PPCODE: + Newx(buf, bufsize, opus_int16); + ret = op_read_stereo(of, buf, bufsize); + if(ret < 0) + croak("op_read_stereo returned error %d\n", ret); + EXTEND(SP, 2 * ret); + for(i = 0 ; i < 2 * ret ; i++) + PUSHs(sv_2mortal(newSViv(buf[i]))); + +void +op_read_float_stereo(of, bufsize = 1024 * 1024) + Audio::Opusfile of; + int bufsize; +PREINIT: + float* buf; + int ret, i; +PPCODE: + Newx(buf, bufsize, float); + ret = op_read_float_stereo(of, buf, bufsize); + if(ret < 0) + croak("op_read_float_stereo returned error %d\n", ret); + EXTEND(SP, 2 * ret); + for(i = 0 ; i < 2 * ret ; i++) + PUSHs(sv_2mortal(newSVnv(buf[i]))); + + MODULE = Audio::Opusfile PACKAGE = Audio::Opusfile::Tags PREFIX = opus_tags_ diff --git a/t/Audio-Opusfile.t b/t/Audio-Opusfile.t index 8ef7793..8398a06 100644 --- a/t/Audio-Opusfile.t +++ b/t/Audio-Opusfile.t @@ -2,7 +2,7 @@ use strict; use warnings; -use Test::More tests => 23; +use Test::More tests => 29; BEGIN { use_ok('Audio::Opusfile') }; my $fail = 0; @@ -62,3 +62,16 @@ seek $fh, 0, 0; read $fh, $buf, 20000; $of = Audio::Opusfile->new_from_memory($buf); is $of->tags->query('TITLE'), 'Cellule', 'new_from_memory + query'; + +is $of->pcm_tell, 0, '->pcm_tell is 0 at the beginning'; + +$of->set_dither_enabled(0); +my ($li, @samples) = $of->read; +is $li, 0, '->read, correct link'; +is scalar @samples, 1208, '->read, got correct number of samples'; + +isn::t $of->pcm_tell, 0, '->pcm_tell is not 0 after read'; +$of->raw_seek(0); +is $of->pcm_tell, 0, '->pcm_tell is 0 right after raw_seek'; +my @samples = $of->read_float_stereo; +is scalar @samples, 1208, '->read_float_stereo, got correct number of samples';