Changeset a9fd272


Ignore:
Timestamp:
Jan 26, 2014, 8:16:59 PM (11 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
422452b
Parents:
082c88b
Message:

src/io/sink*: add _close function, improve error messages

Location:
src/io
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/io/sink.c

    r082c88b ra9fd272  
    3939typedef uint_t (*aubio_sink_get_channels_t)(aubio_sink_t * s);
    4040#endif
     41typedef uint_t (*aubio_sink_close_t)(aubio_sink_t * s);
    4142typedef void (*del_aubio_sink_t)(aubio_sink_t * s);
    4243
     
    4950  aubio_sink_get_channels_t s_get_channels;
    5051#endif
     52  aubio_sink_close_t s_close;
    5153  del_aubio_sink_t s_del;
    5254};
     
    5860  if (s->sink) {
    5961    s->s_do = (aubio_sink_do_t)(aubio_sink_apple_audio_do);
     62    s->s_close = (aubio_sink_close_t)(aubio_sink_apple_audio_close);
    6063    s->s_del = (del_aubio_sink_t)(del_aubio_sink_apple_audio);
    6164    return s;
     
    6669  if (s->sink) {
    6770    s->s_do = (aubio_sink_do_t)(aubio_sink_sndfile_do);
     71    s->s_close = (aubio_sink_close_t)(aubio_sink_sndfile_close);
    6872    s->s_del = (del_aubio_sink_t)(del_aubio_sink_sndfile);
    6973    return s;
     
    7478  if (s->sink) {
    7579    s->s_do = (aubio_sink_do_t)(aubio_sink_wavwrite_do);
     80    s->s_close = (aubio_sink_close_t)(aubio_sink_wavwrite_close);
    7681    s->s_del = (del_aubio_sink_t)(del_aubio_sink_wavwrite);
    7782    return s;
    7883  }
    7984#endif /* HAVE_WAVWRITE */
    80   AUBIO_ERROR("sink: failed creating aubio sink with %s\n", uri);
     85  AUBIO_ERROR("sink: failed creating %s with samplerate %dHz\n",
     86      uri, samplerate);
    8187  AUBIO_FREE(s);
    8288  return NULL;
     
    8793}
    8894
     95uint_t aubio_sink_close(aubio_sink_t *s) {
     96  return s->s_close((void *)s->sink);
     97}
     98
    8999void del_aubio_sink(aubio_sink_t * s) {
    90100  if (!s) return;
  • src/io/sink.h

    r082c88b ra9fd272  
    6464/**
    6565
     66  close sink
     67
     68  \param s sink object, created with ::new_aubio_sink
     69
     70  \return 0 on success, non-zero on failure
     71
     72*/
     73uint_t aubio_sink_close(aubio_sink_t * s);
     74
     75/**
     76
    6677  close sink and cleanup memory
    6778
    68   \param s source object, created with ::new_aubio_source
     79  \param s sink object, created with ::new_aubio_sink
    6980
    7081*/
  • src/io/sink_apple_audio.c

    r082c88b ra9fd272  
    142142}
    143143
    144 void del_aubio_sink_apple_audio(aubio_sink_apple_audio_t * s) {
     144uint_t aubio_sink_apple_audio_close(aubio_sink_apple_audio_t * s) {
    145145  OSStatus err = noErr;
    146   if (!s || !s->audioFile) {
    147     AUBIO_ERR("sink_apple_audio: failed erasing\n");
    148     return;
     146  if (!s->audioFile) {
     147    return AUBIO_FAIL;
    149148  }
    150149  err = ExtAudioFileDispose(s->audioFile);
     
    156155  }
    157156  s->audioFile = NULL;
     157  return err;
     158}
     159
     160void del_aubio_sink_apple_audio(aubio_sink_apple_audio_t * s) {
     161  if (s->audioFile) aubio_sink_apple_audio_close (s);
    158162  freeAudioBufferList(&s->bufferList);
    159163  AUBIO_FREE(s);
  • src/io/sink_apple_audio.h

    r082c88b ra9fd272  
    6969/**
    7070
     71  close sink
     72
     73  \param s sink_apple_audio object, created with ::new_aubio_sink_apple_audio
     74
     75  \return 0 on success, non-zero on failure
     76
     77*/
     78uint_t aubio_sink_apple_audio_close(aubio_sink_apple_audio_t * s);
     79
     80/**
     81
    7182  close sink and cleanup memory
    7283
  • src/io/sink_sndfile.c

    r082c88b ra9fd272  
    116116}
    117117
     118uint_t aubio_sink_sndfile_close (aubio_sink_sndfile_t *s) {
     119  if (!s->handle) {
     120    return AUBIO_FAIL;
     121  }
     122  if (sf_close(s->handle)) {
     123    AUBIO_ERR("Error closing file %s: %s", s->path, sf_strerror (NULL));
     124    return AUBIO_FAIL;
     125  }
     126  s->handle = NULL;
     127  return AUBIO_OK;
     128}
     129
    118130void del_aubio_sink_sndfile(aubio_sink_sndfile_t * s){
    119131  if (!s) return;
    120   if (sf_close(s->handle)) {
    121     AUBIO_ERR("Error closing file %s: %s", s->path, sf_strerror (NULL));
    122   }
     132  aubio_sink_sndfile_close(s);
    123133  AUBIO_FREE(s->scratch_data);
    124134  AUBIO_FREE(s);
  • src/io/sink_sndfile.h

    r082c88b ra9fd272  
    6868/**
    6969
     70  close sink
     71
     72  \param s sink_sndfile object, created with ::new_aubio_sink_sndfile
     73
     74  \return 0 on success, non-zero on failure
     75
     76*/
     77uint_t aubio_sink_sndfile_close(aubio_sink_sndfile_t * s);
     78
     79/**
     80
    7081  close sink and cleanup memory
    7182
  • src/io/sink_wavwrite.c

    r082c88b ra9fd272  
    153153
    154154beach:
    155   AUBIO_ERR("sink_wavwrite: can not write %s at samplerate %dHz\n",
    156       s->path, s->samplerate);
     155  //AUBIO_ERR("sink_wavwrite: failed creating %s with samplerate %dHz\n",
     156  //    s->path, s->samplerate);
    157157  del_aubio_sink_wavwrite(s);
    158158  return NULL;
     
    182182}
    183183
    184 void aubio_sink_wavwrite_close(aubio_sink_wavwrite_t * s) {
     184uint_t aubio_sink_wavwrite_close(aubio_sink_wavwrite_t * s) {
    185185  uint_t data_size = s->total_frames_written * s->bitspersample * s->channels / 8;
    186186  unsigned char buf[5];
    187   if (!s->fid) return;
     187  if (!s->fid) return AUBIO_FAIL;
    188188  // ChunkSize
    189189  fseek(s->fid, 4, SEEK_SET);
     
    197197  }
    198198  s->fid = NULL;
     199  return AUBIO_OK;
    199200}
    200201
  • src/io/sink_wavwrite.h

    r082c88b ra9fd272  
    6868/**
    6969
     70  close sink
     71
     72  \param s sink_wavwrite object, create with ::new_aubio_sink_wavwrite
     73
     74  \return 0 on success, non-zero on failure
     75
     76*/
     77uint_t aubio_sink_wavwrite_close(aubio_sink_wavwrite_t * s);
     78
     79/**
     80
    7081  close sink and cleanup memory
    7182
Note: See TracChangeset for help on using the changeset viewer.