Changeset 4f75d8a for src


Ignore:
Timestamp:
Dec 16, 2018, 7:09:50 PM (12 months ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/timestretch, master
Children:
e4c6c76
Parents:
4eb48e6
Message:

[io] validate input in sink_sndfile_do

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/sink_sndfile.c

    r4eb48e6 r4f75d8a  
    159159
    160160void aubio_sink_sndfile_do(aubio_sink_sndfile_t *s, fvec_t * write_data, uint_t write){
    161   uint_t i, j, channels = s->channels;
    162   int nsamples = 0;
    163   smpl_t *pwrite;
     161  uint_t i, j;
    164162  sf_count_t written_frames;
    165 
    166   if (write > s->max_size) {
    167     AUBIO_WRN("sink_sndfile: trying to write %d frames, but only %d can be written at a time\n",
    168       write, s->max_size);
    169     write = s->max_size;
    170   }
    171 
    172   nsamples = channels * write;
     163  uint_t channels = s->channels;
     164  uint_t length = aubio_sink_validate_input_length("sink_sndfile", s->path,
     165      s->max_size, write_data->length, write);
     166  int nsamples = channels * length;
    173167
    174168  /* interleaving data  */
    175169  for ( i = 0; i < channels; i++) {
    176     pwrite = (smpl_t *)write_data->data;
    177     for (j = 0; j < write; j++) {
    178       s->scratch_data[channels*j+i] = pwrite[j];
     170    for (j = 0; j < length; j++) {
     171      s->scratch_data[channels*j+i] = write_data->data[j];
    179172    }
    180173  }
     
    189182
    190183void aubio_sink_sndfile_do_multi(aubio_sink_sndfile_t *s, fmat_t * write_data, uint_t write){
    191   uint_t i, j, channels = s->channels;
    192   int nsamples = 0;
    193   smpl_t *pwrite;
     184  uint_t i, j;
    194185  sf_count_t written_frames;
    195 
    196   if (write > s->max_size) {
    197     AUBIO_WRN("sink_sndfile: trying to write %d frames, but only %d can be written at a time\n",
    198       write, s->max_size);
    199     write = s->max_size;
    200   }
    201 
    202   nsamples = channels * write;
     186  uint_t channels = aubio_sink_validate_input_channels("sink_sndfile", s->path,
     187      s->channels, write_data->height);
     188  uint_t length = aubio_sink_validate_input_length("sink_sndfile", s->path,
     189      s->max_size, write_data->length, write);
     190  int nsamples = channels * length;
    203191
    204192  /* interleaving data  */
    205   for ( i = 0; i < write_data->height; i++) {
    206     pwrite = (smpl_t *)write_data->data[i];
    207     for (j = 0; j < write; j++) {
    208       s->scratch_data[channels*j+i] = pwrite[j];
     193  for ( i = 0; i < channels; i++) {
     194    for (j = 0; j < length; j++) {
     195      s->scratch_data[channels*j+i] = write_data->data[i][j];
    209196    }
    210197  }
Note: See TracChangeset for help on using the changeset viewer.