From: Paul Brossier Date: Thu, 19 Dec 2013 22:24:01 +0000 (-0500) Subject: src/io/source_sndfile.c: fix resampled position in _seek, improve test for non intege... X-Git-Tag: 0.4.1~108 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=7bb5cefadf43c3695fbecfe6d1b03c48af9be132;p=aubio.git src/io/source_sndfile.c: fix resampled position in _seek, improve test for non integer ratios --- 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; }