shithub: aubio

Download patch

ref: ebfa80dfa72016ed0ed76e1a0a56c83e2c8c988c
parent: 3880830a03955a9572d52bf8f1659a1573673e24
author: Paul Brossier <piem@piem.org>
date: Thu Dec 20 16:26:32 EST 2018

[source_sndfile] fix reading sizes when resampling

--- a/src/io/source_sndfile.c
+++ b/src/io/source_sndfile.c
@@ -173,9 +173,9 @@
   uint_t length = aubio_source_validate_input_length("source_sndfile", s->path,
       s->hop_size, read_data->length);
   sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data,
-      s->input_channels * length);
+      s->scratch_size);
 
-  length = MIN(read_samples / s->input_channels, length);
+  uint_t read_length = read_samples / s->input_channels;
 
   /* where to store de-interleaved data */
   smpl_t *ptr_data;
@@ -185,11 +185,12 @@
   } else
 #endif /* HAVE_SAMPLERATE */
   {
+    read_length = MIN(length, read_length);
     ptr_data = read_data->data;
   }
 
   /* de-interleaving and down-mixing data  */
-  for (j = 0; j < length; j++) {
+  for (j = 0; j < read_length; j++) {
     ptr_data[j] = 0;
     for (i = 0; i < input_channels; i++) {
       ptr_data[j] += s->scratch_data[input_channels*j+i];
@@ -203,7 +204,7 @@
   }
 #endif /* HAVE_SAMPLERATE */
 
-  *read = (int)FLOOR(s->ratio * length + .5);
+  *read = MIN(length, (uint_t)FLOOR(s->ratio * read_length + .5));
 
   aubio_source_pad_output (read_data, *read);
 
@@ -217,9 +218,9 @@
   uint_t channels = aubio_source_validate_input_channels("source_sndfile",
       s->path, s->input_channels, read_data->height);
   sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data,
-      length * s->input_channels);
+      s->scratch_size);
 
-  length = MIN(read_samples / s->input_channels, length);
+  uint_t read_length = read_samples / s->input_channels;
 
   /* where to store de-interleaved data */
   smpl_t **ptr_data;
@@ -229,10 +230,11 @@
   } else
 #endif /* HAVE_SAMPLERATE */
   {
+    read_length = MIN(read_length, length);
     ptr_data = read_data->data;
   }
 
-  for (j = 0; j < length; j++) {
+  for (j = 0; j < read_length; j++) {
     for (i = 0; i < channels; i++) {
       ptr_data[i][j] = s->scratch_data[j * input_channels + i];
     }
@@ -251,7 +253,7 @@
   }
 #endif /* HAVE_SAMPLERATE */
 
-  *read = (int)FLOOR(s->ratio * length + .5);
+  *read = MIN(length, (uint_t)FLOOR(s->ratio * read_length + .5));
 
   aubio_source_pad_multi_output(read_data, input_channels, *read);
 }