Ignore:
Timestamp:
Dec 17, 2018, 4:42:29 PM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/crepe, fix/ffmpeg5, master
Children:
d286fe4
Parents:
2de7cfa (diff), 09b4be9 (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 'feature/sink_flac' into feature/autosink

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/io/sink_sndfile.c

    r2de7cfa rd013a93  
    5959  if (path == NULL) {
    6060    AUBIO_ERR("sink_sndfile: Aborted opening null path\n");
    61     return NULL;
    62   }
    63 
    64   if (s->path) AUBIO_FREE(s->path);
     61    goto beach;
     62  }
     63
    6564  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    6665  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    9897  s->samplerate = samplerate;
    9998  // automatically open when both samplerate and channels have been set
    100   if (s->samplerate != 0 && s->channels != 0) {
     99  if (/* s->samplerate != 0 && */ s->channels != 0) {
    101100    return aubio_sink_sndfile_open(s);
    102101  }
     
    111110  s->channels = channels;
    112111  // automatically open when both samplerate and channels have been set
    113   if (s->samplerate != 0 && s->channels != 0) {
     112  if (s->samplerate != 0 /* && s->channels != 0 */) {
    114113    return aubio_sink_sndfile_open(s);
    115114  }
     
    148147  /* allocate data for de/interleaving reallocated when needed. */
    149148  if (s->scratch_size >= MAX_SIZE * AUBIO_MAX_CHANNELS) {
    150     abort();
    151     AUBIO_ERR("sink_sndfile: %d x %d exceeds maximum aubio_sink_sndfile buffer size %d\n",
     149    AUBIO_ERR("sink_sndfile: %d x %d exceeds maximum buffer size %d\n",
    152150        s->max_size, s->channels, MAX_SIZE * AUBIO_MAX_CHANNELS);
    153151    return AUBIO_FAIL;
     
    159157
    160158void 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;
     159  uint_t i, j;
    164160  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;
     161  uint_t channels = s->channels;
     162  uint_t length = aubio_sink_validate_input_length("sink_sndfile", s->path,
     163      s->max_size, write_data->length, write);
     164  int nsamples = channels * length;
    173165
    174166  /* interleaving data  */
    175167  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];
     168    for (j = 0; j < length; j++) {
     169      s->scratch_data[channels*j+i] = write_data->data[j];
    179170    }
    180171  }
     
    189180
    190181void 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;
     182  uint_t i, j;
    194183  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;
     184  uint_t channels = aubio_sink_validate_input_channels("sink_sndfile", s->path,
     185      s->channels, write_data->height);
     186  uint_t length = aubio_sink_validate_input_length("sink_sndfile", s->path,
     187      s->max_size, write_data->length, write);
     188  int nsamples = channels * length;
    203189
    204190  /* 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];
     191  for ( i = 0; i < channels; i++) {
     192    for (j = 0; j < length; j++) {
     193      s->scratch_data[channels*j+i] = write_data->data[i][j];
    209194    }
    210195  }
     
    231216
    232217void del_aubio_sink_sndfile(aubio_sink_sndfile_t * s){
    233   if (!s) return;
    234   if (s->path) AUBIO_FREE(s->path);
    235   aubio_sink_sndfile_close(s);
    236   AUBIO_FREE(s->scratch_data);
     218  AUBIO_ASSERT(s);
     219  if (s->handle)
     220    aubio_sink_sndfile_close(s);
     221  if (s->path)
     222    AUBIO_FREE(s->path);
     223  if (s->scratch_data)
     224    AUBIO_FREE(s->scratch_data);
    237225  AUBIO_FREE(s);
    238226}
Note: See TracChangeset for help on using the changeset viewer.