src/io/source_sndfile.c: fix resampled position in _seek, improve test for non intege...
authorPaul Brossier <piem@piem.org>
Thu, 19 Dec 2013 22:24:01 +0000 (17:24 -0500)
committerPaul Brossier <piem@piem.org>
Thu, 19 Dec 2013 22:24:01 +0000 (17:24 -0500)
src/io/source_sndfile.c
tests/src/io/test-source_seek.c

index 359ab79..0951d5e 100644 (file)
@@ -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);
 }
 
index ad8d177..b42c86c 100644 (file)
@@ -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;
 }