From: Paul Brossier Date: Mon, 25 Apr 2016 14:42:43 +0000 (+0200) Subject: src/io/source_sndfile.h: add _get_duration X-Git-Tag: 0.4.4~300^2~212 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=c6e7ba1f0cc0958fffd30e6bef57da9e238a5763;p=aubio.git src/io/source_sndfile.h: add _get_duration --- diff --git a/src/io/source_sndfile.c b/src/io/source_sndfile.c index 7f88e718..00ea42ad 100644 --- a/src/io/source_sndfile.c +++ b/src/io/source_sndfile.c @@ -53,6 +53,7 @@ struct _aubio_source_sndfile_t { int input_samplerate; int input_channels; int input_format; + int duration; // resampling stuff smpl_t ratio; @@ -105,6 +106,7 @@ aubio_source_sndfile_t * new_aubio_source_sndfile(const char_t * path, uint_t sa 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; @@ -272,6 +274,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) { uint_t resampled_pos = (uint_t)ROUND(pos / s->ratio); sf_count_t sf_ret = sf_seek (s->handle, resampled_pos, SEEK_SET); diff --git a/src/io/source_sndfile.h b/src/io/source_sndfile.h index e382c3b2..210a40d2 100644 --- a/src/io/source_sndfile.h +++ b/src/io/source_sndfile.h @@ -120,6 +120,16 @@ uint_t aubio_source_sndfile_seek (aubio_source_sndfile_t *s, uint_t pos); /** + 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 diff --git a/tests/src/io/test-source_sndfile.c b/tests/src/io/test-source_sndfile.c index ed227fd8..6dfff59d 100644 --- a/tests/src/io/test-source_sndfile.c +++ b/tests/src/io/test-source_sndfile.c @@ -38,6 +38,8 @@ int main (int argc, char **argv) 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 @@ int main (int argc, char **argv) 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);