Changeset 422452b for src


Ignore:
Timestamp:
Jan 26, 2014, 8:19:31 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:
3cc3fd8
Parents:
a9fd272
Message:

src/io/source*: add _close function

Location:
src/io
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/io/source.c

    ra9fd272 r422452b  
    4242typedef uint_t (*aubio_source_get_channels_t)(aubio_source_t * s);
    4343typedef uint_t (*aubio_source_seek_t)(aubio_source_t * s, uint_t seek);
     44typedef uint_t (*aubio_source_close_t)(aubio_source_t * s);
    4445typedef void (*del_aubio_source_t)(aubio_source_t * s);
    4546
     
    5152  aubio_source_get_channels_t s_get_channels;
    5253  aubio_source_seek_t s_seek;
     54  aubio_source_close_t s_close;
    5355  del_aubio_source_t s_del;
    5456};
     
    6466    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_avcodec_get_samplerate);
    6567    s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek);
     68    s->s_close = (aubio_source_close_t)(aubio_source_avcodec_close);
    6669    s->s_del = (del_aubio_source_t)(del_aubio_source_avcodec);
    6770    return s;
     
    7679    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_apple_audio_get_samplerate);
    7780    s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek);
     81    s->s_close = (aubio_source_close_t)(aubio_source_apple_audio_close);
    7882    s->s_del = (del_aubio_source_t)(del_aubio_source_apple_audio);
    7983    return s;
     
    8892    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_sndfile_get_samplerate);
    8993    s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek);
     94    s->s_close = (aubio_source_close_t)(aubio_source_sndfile_close);
    9095    s->s_del = (del_aubio_source_t)(del_aubio_source_sndfile);
    9196    return s;
     
    100105    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_wavread_get_samplerate);
    101106    s->s_seek = (aubio_source_seek_t)(aubio_source_wavread_seek);
     107    s->s_close = (aubio_source_close_t)(aubio_source_wavread_close);
    102108    s->s_del = (del_aubio_source_t)(del_aubio_source_wavread);
    103109    return s;
     
    116122void aubio_source_do_multi(aubio_source_t * s, fmat_t * data, uint_t * read) {
    117123  s->s_do_multi((void *)s->source, data, read);
     124}
     125
     126uint_t aubio_source_close(aubio_source_t * s) {
     127  return s->s_close((void *)s->source);
    118128}
    119129
  • src/io/source.h

    ra9fd272 r422452b  
    142142/**
    143143
     144  close source object
     145
     146  \param s source object, created with ::new_aubio_source
     147
     148  \return 0 if sucessful, non-zero on failure
     149
     150 */
     151uint_t aubio_source_close (aubio_source_t *s);
     152
     153/**
     154
    144155  close source and cleanup memory
    145156
  • src/io/source_apple_audio.c

    ra9fd272 r422452b  
    258258{
    259259  OSStatus err = noErr;
    260   if (!s || !s->audioFile) { return AUBIO_FAIL; }
     260  if (!s->audioFile) { return AUBIO_FAIL; }
    261261  err = ExtAudioFileDispose(s->audioFile);
    262262  s->audioFile = NULL;
  • src/io/source_apple_audio.h

    ra9fd272 r422452b  
    122122/**
    123123
     124  close source
     125
     126  \param s source object, created with ::new_aubio_source_apple_audio
     127
     128  \return 0 if sucessful, non-zero on failure
     129
     130*/
     131uint_t aubio_source_apple_audio_close(aubio_source_apple_audio_t * s);
     132
     133/**
     134
    124135  close source and cleanup memory
    125136
  • src/io/source_avcodec.c

    ra9fd272 r422452b  
    391391}
    392392
    393 void del_aubio_source_avcodec(aubio_source_avcodec_t * s){
    394   if (!s) return;
    395   if (s->output != NULL) {
    396     av_free(s->output);
    397   }
     393uint_t aubio_source_avcodec_close(aubio_source_avcodec_t * s) {
    398394  if (s->avr != NULL) {
    399395    avresample_close( s->avr );
     
    401397  }
    402398  s->avr = NULL;
    403   if (s->avFrame != NULL) {
    404     avcodec_free_frame( &(s->avFrame) );
    405   }
    406   s->avFrame = NULL;
    407399  if (s->avCodecCtx != NULL) {
    408400    avcodec_close ( s->avCodecCtx );
     
    412404    avformat_close_input ( &(s->avFormatCtx) );
    413405  }
     406  s->avFormatCtx = NULL;
     407  return AUBIO_OK;
     408}
     409
     410void del_aubio_source_avcodec(aubio_source_avcodec_t * s){
     411  if (!s) return;
     412  aubio_source_avcodec_close(s);
     413  if (s->output != NULL) {
     414    av_free(s->output);
     415  }
     416  s->output = NULL;
     417  if (s->avFrame != NULL) {
     418    avcodec_free_frame( &(s->avFrame) );
     419  }
    414420  s->avFrame = NULL;
    415   s->avFormatCtx = NULL;
    416421  AUBIO_FREE(s);
    417422}
  • src/io/source_avcodec.h

    ra9fd272 r422452b  
    121121/**
    122122
     123  close source
     124
     125  \param s source object, created with ::new_aubio_source_avcodec
     126
     127  \return 0 if sucessful, non-zero on failure
     128
     129*/
     130uint_t aubio_source_avcodec_close (aubio_source_avcodec_t *s);
     131
     132/**
     133
    123134  close source and cleanup memory
    124135
  • src/io/source_sndfile.c

    ra9fd272 r422452b  
    268268}
    269269
     270uint_t aubio_source_sndfile_close (aubio_source_sndfile_t *s) {
     271  if (!s->handle) {
     272    return AUBIO_FAIL;
     273  if(sf_close(s->handle)) {
     274    AUBIO_ERR("Error closing file %s: %s", s->path, sf_strerror (NULL));
     275    return AUBIO_FAIL;
     276  }
     277  return AUBIO_OK;
     278}
     279
    270280void del_aubio_source_sndfile(aubio_source_sndfile_t * s){
    271281  if (!s) return;
    272   if (sf_close(s->handle)) {
    273     AUBIO_ERR("Error closing file %s: %s", s->path, sf_strerror (NULL));
    274   }
     282  aubio_source_sndfile_close(s):
    275283#ifdef HAVE_SAMPLERATE
    276284  if (s->resampler != NULL) {
  • src/io/source_sndfile.h

    ra9fd272 r422452b  
    121121/**
    122122
     123  close source
     124
     125  \param s source object, created with ::new_aubio_source_sndfile
     126
     127  \return 0 if sucessful, non-zero on failure
     128
     129*/
     130uint_t aubio_source_sndfile_close (aubio_source_sndfile_t *s);
     131
     132/**
     133
    123134  close source and cleanup memory
    124135
  • src/io/source_wavread.c

    ra9fd272 r422452b  
    347347}
    348348
     349uint_t aubio_source_wavread_close (aubio_source_wavread_t * s) {
     350  if (!s->fid || fclose(s->fid)) {
     351    return AUBIO_FAIL;
     352  }
     353  return AUBIO_OK;
     354}
     355
    349356void del_aubio_source_wavread(aubio_source_wavread_t * s) {
    350357  if (!s) return;
    351   if (s->fid) fclose(s->fid);
     358  aubio_source_wavread_close(s);
    352359  if (s->short_output) AUBIO_FREE(s->short_output);
    353360  if (s->output) del_fmat(s->output);
  • src/io/source_wavread.h

    ra9fd272 r422452b  
    126126/**
    127127
     128  close source
     129
     130  \param s source object, created with ::new_aubio_source_wavread
     131
     132  \return 0 if sucessful, non-zero on failure
     133
     134*/
     135uint_t aubio_source_wavread_close (aubio_source_wavread_t *s);
     136
     137/**
     138
    128139  close source and cleanup memory
    129140
Note: See TracChangeset for help on using the changeset viewer.