From 7bb5cefadf43c3695fbecfe6d1b03c48af9be132 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Thu, 19 Dec 2013 17:24:01 -0500 Subject: [PATCH] src/io/source_sndfile.c: fix resampled position in _seek, improve test for non integer ratios --- src/io/source_sndfile.c | 2 +- tests/src/io/test-source_seek.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/io/source_sndfile.c b/src/io/source_sndfile.c index 359ab794..0951d5e4 100644 --- a/src/io/source_sndfile.c +++ b/src/io/source_sndfile.c @@ -263,7 +263,7 @@ uint_t aubio_source_sndfile_get_channels(aubio_source_sndfile_t * s) { } uint_t aubio_source_sndfile_seek (aubio_source_sndfile_t * s, uint_t pos) { - uint_t resampled_pos = (uint_t)ROUND(pos * s->ratio); + uint_t resampled_pos = (uint_t)ROUND(pos / s->ratio); return sf_seek (s->handle, resampled_pos, SEEK_SET); } diff --git a/tests/src/io/test-source_seek.c b/tests/src/io/test-source_seek.c index ad8d1772..b42c86c5 100644 --- a/tests/src/io/test-source_seek.c +++ b/tests/src/io/test-source_seek.c @@ -84,7 +84,9 @@ int main (int argc, char **argv) beach: del_fvec (vec); + // check that we got exactly the same number of frames assert ( old_n_frames_2 == old_n_frames_1 ); - assert ( old_n_frames_3 == (uint_t)floor(old_n_frames_1 / 2. + .5) ); + // check that we got about half the frames, with 3 decimals + assert ( roundf(1.e3 * old_n_frames_1 / old_n_frames_3) / 1.e3 == 2.); return err; } -- 2.11.0