ref: c6e7ba1f0cc0958fffd30e6bef57da9e238a5763
parent: b60f2977149723abeaad77309b7dc67c1e286c05
author: Paul Brossier <piem@piem.org>
date: Mon Apr 25 12:42:43 EDT 2016
src/io/source_sndfile.h: add _get_duration
--- a/src/io/source_sndfile.c
+++ b/src/io/source_sndfile.c
@@ -53,6 +53,7 @@
int input_samplerate;
int input_channels;
int input_format;
+ int duration;
// resampling stuff
smpl_t ratio;
@@ -105,6 +106,7 @@
s->input_samplerate = sfinfo.samplerate;
s->input_channels = sfinfo.channels;
s->input_format = sfinfo.format;
+ s->duration = sfinfo.frames;
if (samplerate == 0) {
s->samplerate = s->input_samplerate;
@@ -270,6 +272,13 @@
uint_t aubio_source_sndfile_get_channels(aubio_source_sndfile_t * s) {
return s->input_channels;
+}
+
+uint_t aubio_source_sndfile_get_duration (const aubio_source_sndfile_t * s) {
+ if (s && s->duration) {
+ return s->duration;
+ }
+ return 0;
}
uint_t aubio_source_sndfile_seek (aubio_source_sndfile_t * s, uint_t pos) {
--- a/src/io/source_sndfile.h
+++ b/src/io/source_sndfile.h
@@ -120,6 +120,16 @@
/**
+ get the duration of source object, in frames
+
+ \param s source object, created with ::new_aubio_source_sndfile
+ \return number of frames in file
+
+*/
+uint_t aubio_source_sndfile_get_duration (const aubio_source_sndfile_t *s);
+
+/**
+
close source
\param s source object, created with ::new_aubio_source_sndfile
--- a/tests/src/io/test-source_sndfile.c
+++ b/tests/src/io/test-source_sndfile.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_sndfile_get_duration(s);
+
samplerate = aubio_source_sndfile_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_sndfile (s);