Ignore:
Timestamp:
Dec 20, 2018, 8:30:18 PM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/crepe, fix/ffmpeg5, master
Children:
b8fa393, e2f1e6d
Parents:
5e9bdca (diff), 49ac58e0 (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/sink_vorbis

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_sndfile.c

    r5e9bdca ra2019c4  
    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->input_channels * length);
     177
     178  length = MIN(read_samples / s->input_channels, length);
    173179
    174180  /* where to store de-interleaved data */
     
    184190
    185191  /* de-interleaving and down-mixing data  */
    186   for (j = 0; j < read_samples / input_channels; j++) {
     192  for (j = 0; j < length; j++) {
    187193    ptr_data[j] = 0;
    188194    for (i = 0; i < input_channels; i++) {
     
    198204#endif /* HAVE_SAMPLERATE */
    199205
    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   }
     206  *read = (int)FLOOR(s->ratio * length + .5);
     207
     208  aubio_source_pad_output (read_data, *read);
    207209
    208210}
     
    211213  uint_t i,j, input_channels = s->input_channels;
    212214  /* do actual reading */
    213   sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size);
     215  uint_t length = aubio_source_validate_input_length("source_sndfile", s->path,
     216      s->hop_size, read_data->length);
     217  uint_t channels = aubio_source_validate_input_channels("source_sndfile",
     218      s->path, s->input_channels, read_data->height);
     219  sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data,
     220      length * s->input_channels);
     221
     222  length = MIN(read_samples / s->input_channels, length);
    214223
    215224  /* where to store de-interleaved data */
     
    224233  }
    225234
    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       }
     235  for (j = 0; j < length; j++) {
     236    for (i = 0; i < channels; i++) {
     237      ptr_data[i][j] = s->scratch_data[j * input_channels + i];
    251238    }
    252239  }
     
    265252#endif /* HAVE_SAMPLERATE */
    266253
    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 
     254  *read = (int)FLOOR(s->ratio * length + .5);
     255
     256  aubio_source_pad_multi_output(read_data, input_channels, *read);
    277257}
    278258
Note: See TracChangeset for help on using the changeset viewer.