Ignore:
Timestamp:
Dec 19, 2018, 7:31:27 PM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn, feature/crepe, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
Children:
0770148, cb0d7d0
Parents:
34d4232 (diff), 0045668 (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/sink_wavwrite.c

    r34d4232 rd0f19a7  
    8888    goto beach;
    8989  }
    90   if ((sint_t)samplerate < 0) {
    91     AUBIO_ERR("sink_wavwrite: Can not create %s with samplerate %d\n", path, samplerate);
    92     goto beach;
    93   }
    94 
    95   if (s->path) AUBIO_FREE(s->path);
     90
    9691  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    9792  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    136131  s->samplerate = samplerate;
    137132  // automatically open when both samplerate and channels have been set
    138   if (s->samplerate != 0 && s->channels != 0) {
     133  if (/* s->samplerate != 0 && */ s->channels != 0) {
    139134    return aubio_sink_wavwrite_open(s);
    140135  }
     
    149144  s->channels = channels;
    150145  // automatically open when both samplerate and channels have been set
    151   if (s->samplerate != 0 && s->channels != 0) {
     146  if (s->samplerate != 0 /* && s->channels != 0 */) {
    152147    return aubio_sink_wavwrite_open(s);
    153148  }
     
    234229
    235230void aubio_sink_wavwrite_do(aubio_sink_wavwrite_t *s, fvec_t * write_data, uint_t write){
    236   uint_t i = 0, written_frames = 0;
    237 
    238   if (write > s->max_size) {
    239     AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, "
    240         "but only %d can be written at a time\n", write, s->path, s->max_size);
    241     write = s->max_size;
    242   }
    243 
    244   for (i = 0; i < write; i++) {
    245     s->scratch_data[i] = HTOLES(FLOAT_TO_SHORT(write_data->data[i]));
    246   }
    247   written_frames = fwrite(s->scratch_data, 2, write, s->fid);
     231  uint_t c = 0, i = 0, written_frames = 0;
     232  uint_t length = aubio_sink_validate_input_length("sink_wavwrite", s->path,
     233      s->max_size, write_data->length, write);
     234
     235  for (c = 0; c < s->channels; c++) {
     236    for (i = 0; i < length; i++) {
     237      s->scratch_data[i * s->channels + c] = HTOLES(FLOAT_TO_SHORT(write_data->data[i]));
     238    }
     239  }
     240  written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid);
    248241
    249242  if (written_frames != write) {
     
    258251  uint_t c = 0, i = 0, written_frames = 0;
    259252
    260   if (write > s->max_size) {
    261     AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, "
    262         "but only %d can be written at a time\n", write, s->path, s->max_size);
    263     write = s->max_size;
    264   }
    265 
    266   for (c = 0; c < s->channels; c++) {
    267     for (i = 0; i < write; i++) {
     253  uint_t channels = aubio_sink_validate_input_channels("sink_wavwrite", s->path,
     254      s->channels, write_data->height);
     255  uint_t length = aubio_sink_validate_input_length("sink_wavwrite", s->path,
     256      s->max_size, write_data->length, write);
     257
     258  for (c = 0; c < channels; c++) {
     259    for (i = 0; i < length; i++) {
    268260      s->scratch_data[i * s->channels + c] = HTOLES(FLOAT_TO_SHORT(write_data->data[c][i]));
    269261    }
    270262  }
    271   written_frames = fwrite(s->scratch_data, 2, write * s->channels, s->fid);
     263  written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid);
    272264
    273265  if (written_frames != write * s->channels) {
     
    298290
    299291void del_aubio_sink_wavwrite(aubio_sink_wavwrite_t * s){
    300   if (!s) return;
    301   aubio_sink_wavwrite_close(s);
    302   if (s->path) AUBIO_FREE(s->path);
    303   AUBIO_FREE(s->scratch_data);
     292  AUBIO_ASSERT(s);
     293  if (s->fid)
     294    aubio_sink_wavwrite_close(s);
     295  if (s->path)
     296    AUBIO_FREE(s->path);
     297  if (s->scratch_data)
     298    AUBIO_FREE(s->scratch_data);
    304299  AUBIO_FREE(s);
    305300}
Note: See TracChangeset for help on using the changeset viewer.