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);
+ if (!s->handle) {
+ AUBIO_ERR("source_sndfile: could not read from %s (file was closed)\n",
+ s->path);
+ *read = 0;
+ return;
+ }
- 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;
} 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];
}
#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);
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);
+ if (!s->handle) {
+ AUBIO_ERR("source_sndfile: could not read from %s (file was closed)\n",
+ s->path);
+ *read = 0;
+ return;
+ }
- 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;
} 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];
}
}
#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);
}