Ignore:
Timestamp:
Dec 17, 2018, 4:42:29 PM (6 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_apple_audio.c

    r2de7cfa rd013a93  
    6262  s->async = false;
    6363
    64   if ( (uri == NULL) || (strlen(uri) < 1) ) {
     64  if ( (uri == NULL) || (strnlen(uri, PATH_MAX) < 1) ) {
    6565    AUBIO_ERROR("sink_apple_audio: Aborted opening null path\n");
    6666    goto beach;
    6767  }
    68   if (s->path != NULL) AUBIO_FREE(s->path);
     68
    6969  s->path = AUBIO_ARRAY(char_t, strnlen(uri, PATH_MAX) + 1);
    7070  strncpy(s->path, uri, strnlen(uri, PATH_MAX) + 1);
     
    9292  return s;
    9393beach:
    94   AUBIO_FREE(s);
     94  del_aubio_sink_apple_audio(s);
    9595  return NULL;
    9696}
     
    103103  s->samplerate = samplerate;
    104104  // automatically open when both samplerate and channels have been set
    105   if (s->samplerate != 0 && s->channels != 0) {
     105  if (/* s->samplerate != 0 && */ s->channels != 0) {
    106106    return aubio_sink_apple_audio_open(s);
    107107  }
     
    116116  s->channels = channels;
    117117  // automatically open when both samplerate and channels have been set
    118   if (s->samplerate != 0 && s->channels != 0) {
     118  if (s->samplerate != 0 /* && s->channels != 0 */) {
    119119    return aubio_sink_apple_audio_open(s);
    120120  }
     
    176176  UInt32 c, v;
    177177  short *data = (short*)s->bufferList.mBuffers[0].mData;
    178   if (write > s->max_frames) {
    179     AUBIO_WRN("sink_apple_audio: trying to write %d frames, max %d\n", write, s->max_frames);
    180     write = s->max_frames;
    181   }
    182   smpl_t *buf = write_data->data;
    183 
    184   if (buf) {
    185       for (c = 0; c < s->channels; c++) {
    186           for (v = 0; v < write; v++) {
    187               data[v * s->channels + c] =
    188                   FLOAT_TO_SHORT(buf[ v * s->channels + c]);
    189           }
    190       }
    191   }
    192   aubio_sink_apple_audio_write(s, write);
     178  uint_t length = aubio_sink_validate_input_length("sink_apple_audio", s->path,
     179      s->max_frames, write_data->length, write);
     180
     181  for (c = 0; c < s->channels; c++) {
     182    for (v = 0; v < length; v++) {
     183      data[v * s->channels + c] = FLOAT_TO_SHORT(write_data->data[v]);
     184    }
     185  }
     186
     187  aubio_sink_apple_audio_write(s, length);
    193188}
    194189
     
    196191  UInt32 c, v;
    197192  short *data = (short*)s->bufferList.mBuffers[0].mData;
    198   if (write > s->max_frames) {
    199     AUBIO_WRN("sink_apple_audio: trying to write %d frames, max %d\n", write, s->max_frames);
    200     write = s->max_frames;
    201   }
    202   smpl_t **buf = write_data->data;
    203 
    204   if (buf) {
    205       for (c = 0; c < s->channels; c++) {
    206           for (v = 0; v < write; v++) {
    207               data[v * s->channels + c] =
    208                   FLOAT_TO_SHORT(buf[c][v]);
    209           }
    210       }
    211   }
    212   aubio_sink_apple_audio_write(s, write);
     193  uint_t channels = aubio_sink_validate_input_channels("sink_apple_audio",
     194      s->path, s->channels, write_data->height);
     195  uint_t length = aubio_sink_validate_input_length("sink_apple_audio", s->path,
     196      s->max_frames, write_data->length, write);
     197
     198  for (c = 0; c < channels; c++) {
     199    for (v = 0; v < length; v++) {
     200      data[v * s->channels + c] = FLOAT_TO_SHORT(write_data->data[c][v]);
     201    }
     202  }
     203
     204  aubio_sink_apple_audio_write(s, length);
    213205}
    214206
     
    258250
    259251void del_aubio_sink_apple_audio(aubio_sink_apple_audio_t * s) {
    260   if (s->audioFile) aubio_sink_apple_audio_close (s);
    261   if (s->path) AUBIO_FREE(s->path);
     252  AUBIO_ASSERT(s);
     253  if (s->audioFile)
     254    aubio_sink_apple_audio_close (s);
     255  if (s->path)
     256    AUBIO_FREE(s->path);
    262257  freeAudioBufferList(&s->bufferList);
    263258  AUBIO_FREE(s);
    264   return;
    265259}
    266260
Note: See TracChangeset for help on using the changeset viewer.