shithub: aubio

Download patch

ref: 2d071ad1c546923854587280a312f23872905ee2
parent: b1d2be840ce684fd4639267ad966e75ea65445e7
author: Paul Brossier <piem@piem.org>
date: Mon Apr 25 12:38:14 EDT 2016

src/io/source_avcodec.h: add _get_duration

--- a/src/io/source_avcodec.c
+++ b/src/io/source_avcodec.c
@@ -400,6 +400,14 @@
   return ret;
 }
 
+uint_t aubio_source_avcodec_get_duration (aubio_source_avcodec_t * s) {
+  if (s && &(s->avFormatCtx) != NULL) {
+    int64_t duration = s->avFormatCtx->duration;
+    return s->samplerate * ((uint_t)duration / 1e6 );
+  }
+  return 0;
+}
+
 uint_t aubio_source_avcodec_close(aubio_source_avcodec_t * s) {
   if (s->avr != NULL) {
     avresample_close( s->avr );
--- a/src/io/source_avcodec.h
+++ b/src/io/source_avcodec.h
@@ -118,6 +118,8 @@
 */
 uint_t aubio_source_avcodec_seek (aubio_source_avcodec_t *s, uint_t pos);
 
+uint_t aubio_source_avcodec_get_duration (aubio_source_avcodec_t * s);
+
 /**
 
   close source
--- a/tests/src/io/test-source_avcodec.c
+++ b/tests/src/io/test-source_avcodec.c
@@ -38,6 +38,8 @@
   if (!s) { err = 1; goto beach; }
   fvec_t *vec = new_fvec(hop_size);
 
+  uint_t n_frames_expected = aubio_source_avcodec_get_duration(s);
+
   samplerate = aubio_source_avcodec_get_samplerate(s);
 
   do {
@@ -46,8 +48,9 @@
     n_frames += read;
   } while ( read == hop_size );
 
-  PRINT_MSG("read %d frames at %dHz (%d blocks) from %s\n", n_frames, samplerate,
-    n_frames / hop_size, source_path);
+  PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
+            n_frames, n_frames_expected, samplerate, n_frames / hop_size,
+            source_path);
 
   del_fvec (vec);
   del_aubio_source_avcodec (s);