Ignore:
Timestamp:
Apr 1, 2019, 1:30:06 AM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn, feature/crepe, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
Children:
7a02ce9
Parents:
5f57ea9 (diff), f55630c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into feature/pitchshift

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_sndfile.c

    r5f57ea9 r439ba7b  
    2727#include "fvec.h"
    2828#include "fmat.h"
     29#include "ioutils.h"
    2930#include "source_sndfile.h"
    3031
     
    170171  uint_t i,j, input_channels = s->input_channels;
    171172  /* read from file into scratch_data */
    172   sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size);
     173  uint_t length = aubio_source_validate_input_length("source_sndfile", s->path,
     174      s->hop_size, read_data->length);
     175  sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data,
     176      s->scratch_size);
     177  uint_t read_length = read_samples / s->input_channels;
    173178
    174179  /* where to store de-interleaved data */
    175180  smpl_t *ptr_data;
     181
     182  if (!s->handle) {
     183    AUBIO_ERR("source_sndfile: could not read from %s (file was closed)\n",
     184        s->path);
     185    *read = 0;
     186    return;
     187  }
     188
    176189#ifdef HAVE_SAMPLERATE
    177190  if (s->ratio != 1) {
     
    180193#endif /* HAVE_SAMPLERATE */
    181194  {
     195    read_length = MIN(length, read_length);
    182196    ptr_data = read_data->data;
    183197  }
    184198
    185199  /* de-interleaving and down-mixing data  */
    186   for (j = 0; j < read_samples / input_channels; j++) {
     200  for (j = 0; j < read_length; j++) {
    187201    ptr_data[j] = 0;
    188202    for (i = 0; i < input_channels; i++) {
     
    198212#endif /* HAVE_SAMPLERATE */
    199213
    200   *read = (int)FLOOR(s->ratio * read_samples / input_channels + .5);
    201 
    202   if (*read < s->hop_size) {
    203     for (j = *read; j < s->hop_size; j++) {
    204       read_data->data[j] = 0;
    205     }
    206   }
     214  *read = MIN(length, (uint_t)FLOOR(s->ratio * read_length + .5));
     215
     216  aubio_source_pad_output (read_data, *read);
    207217
    208218}
     
    211221  uint_t i,j, input_channels = s->input_channels;
    212222  /* do actual reading */
    213   sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size);
     223  uint_t length = aubio_source_validate_input_length("source_sndfile", s->path,
     224      s->hop_size, read_data->length);
     225  uint_t channels = aubio_source_validate_input_channels("source_sndfile",
     226      s->path, s->input_channels, read_data->height);
     227  sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data,
     228      s->scratch_size);
     229  uint_t read_length = read_samples / s->input_channels;
    214230
    215231  /* where to store de-interleaved data */
    216232  smpl_t **ptr_data;
     233
     234  if (!s->handle) {
     235    AUBIO_ERR("source_sndfile: could not read from %s (file was closed)\n",
     236        s->path);
     237    *read = 0;
     238    return;
     239  }
     240
    217241#ifdef HAVE_SAMPLERATE
    218242  if (s->ratio != 1) {
     
    221245#endif /* HAVE_SAMPLERATE */
    222246  {
     247    read_length = MIN(read_length, length);
    223248    ptr_data = read_data->data;
    224249  }
    225250
    226   if (read_data->height < input_channels) {
    227     // destination matrix has less channels than the file; copy only first
    228     // channels of the file, de-interleaving data
    229     for (j = 0; j < read_samples / input_channels; j++) {
    230       for (i = 0; i < read_data->height; i++) {
    231         ptr_data[i][j] = s->scratch_data[j * input_channels + i];
    232       }
    233     }
    234   } else {
    235     // destination matrix has as many or more channels than the file; copy each
    236     // channel from the file to the destination matrix, de-interleaving data
    237     for (j = 0; j < read_samples / input_channels; j++) {
    238       for (i = 0; i < input_channels; i++) {
    239         ptr_data[i][j] = s->scratch_data[j * input_channels + i];
    240       }
    241     }
    242   }
    243 
    244   if (read_data->height > input_channels) {
    245     // destination matrix has more channels than the file; copy last channel
    246     // of the file to each additional channels, de-interleaving data
    247     for (j = 0; j < read_samples / input_channels; j++) {
    248       for (i = input_channels; i < read_data->height; i++) {
    249         ptr_data[i][j] = s->scratch_data[j * input_channels + (input_channels - 1)];
    250       }
     251  for (j = 0; j < read_length; j++) {
     252    for (i = 0; i < channels; i++) {
     253      ptr_data[i][j] = s->scratch_data[j * input_channels + i];
    251254    }
    252255  }
     
    265268#endif /* HAVE_SAMPLERATE */
    266269
    267   *read = (int)FLOOR(s->ratio * read_samples / input_channels + .5);
    268 
    269   if (*read < s->hop_size) {
    270     for (i = 0; i < read_data->height; i++) {
    271       for (j = *read; j < s->hop_size; j++) {
    272         read_data->data[i][j] = 0.;
    273       }
    274     }
    275   }
    276 
     270  *read = MIN(length, (uint_t)FLOOR(s->ratio * read_length + .5));
     271
     272  aubio_source_pad_multi_output(read_data, input_channels, *read);
    277273}
    278274
Note: See TracChangeset for help on using the changeset viewer.