ref: 7bb5cefadf43c3695fbecfe6d1b03c48af9be132
parent: 6465d7f1b9176f86e7ad2fc73d6373d7338d1456
author: Paul Brossier <[email protected]>
date: Thu Dec 19 12:24:01 EST 2013
src/io/source_sndfile.c: fix resampled position in _seek, improve test for non integer ratios
--- a/src/io/source_sndfile.c
+++ b/src/io/source_sndfile.c
@@ -263,7 +263,7 @@
}
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);
}
--- a/tests/src/io/test-source_seek.c
+++ b/tests/src/io/test-source_seek.c
@@ -84,7 +84,9 @@
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;
}