Export more functions and add corresponding tests
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 10 Dec 2016 17:17:04 +0000 (19:17 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 10 Dec 2016 17:17:04 +0000 (19:17 +0200)
Opusfile.xs
t/Audio-Opusfile.t

index a8bd27b585c8107bb1868060b79a011b641af42b..40037e1bb73ec46b5875b767941047041d0456cc 100644 (file)
@@ -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_
 
index 8ef7793f4a08c3f770f84ebc5257684fdeee0ebd..8398a06f4028f7531b4065ebbd8c1d62bd1b3330 100644 (file)
@@ -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';
This page took 0.01378 seconds and 4 git commands to generate.