Changeset f264b17 for src/io


Ignore:
Timestamp:
Jun 22, 2016, 1:00:10 PM (9 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:
4b9443c4
Parents:
60fc05b (diff), 6769586 (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 notes

Location:
src/io
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/io/audio_unit.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_AUDIO_UNIT_H
    22 #define _AUBIO_AUDIO_UNIT_H
     21#ifndef AUBIO_AUDIO_UNIT_H
     22#define AUBIO_AUDIO_UNIT_H
    2323
    2424/** \file
     
    5959#endif
    6060
    61 #endif /* _AUBIO_AUDIO_UNIT_H */
     61#endif /* AUBIO_AUDIO_UNIT_H */
  • TabularUnified src/io/sink.c

    r60fc05b rf264b17  
    5555};
    5656
    57 aubio_sink_t * new_aubio_sink(char_t * uri, uint_t samplerate) {
     57aubio_sink_t * new_aubio_sink(const char_t * uri, uint_t samplerate) {
    5858  aubio_sink_t * s = AUBIO_NEW(aubio_sink_t);
    5959#ifdef HAVE_SINK_APPLE_AUDIO
     
    7171  }
    7272#endif /* HAVE_SINK_APPLE_AUDIO */
    73 #if HAVE_SNDFILE
     73#ifdef HAVE_SNDFILE
    7474  s->sink = (void *)new_aubio_sink_sndfile(uri, samplerate);
    7575  if (s->sink) {
     
    8585  }
    8686#endif /* HAVE_SNDFILE */
    87 #if HAVE_WAVWRITE
     87#ifdef HAVE_WAVWRITE
    8888  s->sink = (void *)new_aubio_sink_wavwrite(uri, samplerate);
    8989  if (s->sink) {
     
    121121}
    122122
    123 uint_t aubio_sink_get_samplerate(aubio_sink_t * s) {
     123uint_t aubio_sink_get_samplerate(const aubio_sink_t * s) {
    124124  return s->s_get_samplerate((void *)s->sink);
    125125}
    126126
    127 uint_t aubio_sink_get_channels(aubio_sink_t * s) {
     127uint_t aubio_sink_get_channels(const aubio_sink_t * s) {
    128128  return s->s_get_channels((void *)s->sink);
    129129}
  • TabularUnified src/io/sink.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_SINK_H
    22 #define _AUBIO_SINK_H
     21#ifndef AUBIO_SINK_H
     22#define AUBIO_SINK_H
    2323
    2424/** \file
     
    7777
    7878*/
    79 aubio_sink_t * new_aubio_sink(char_t * uri, uint_t samplerate);
     79aubio_sink_t * new_aubio_sink(const char_t * uri, uint_t samplerate);
    8080
    8181/**
     
    121121
    122122*/
    123 uint_t aubio_sink_get_samplerate(aubio_sink_t *s);
     123uint_t aubio_sink_get_samplerate(const aubio_sink_t *s);
    124124
    125125/**
     
    131131
    132132*/
    133 uint_t aubio_sink_get_channels(aubio_sink_t *s);
     133uint_t aubio_sink_get_channels(const aubio_sink_t *s);
    134134
    135135/**
     
    179179#endif
    180180
    181 #endif /* _AUBIO_SINK_H */
     181#endif /* AUBIO_SINK_H */
  • TabularUnified src/io/sink_apple_audio.c

    r60fc05b rf264b17  
    3737extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
    3838extern void freeAudioBufferList(AudioBufferList *bufferList);
    39 extern CFURLRef getURLFromPath(const char * path);
     39extern CFURLRef createURLFromPath(const char * path);
    4040char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
    4141
     
    4343
    4444#define MAX_SIZE 4096 // the maximum number of frames that can be written at a time
     45
     46void aubio_sink_apple_audio_write(aubio_sink_apple_audio_t *s, uint_t write);
    4547
    4648struct _aubio_sink_apple_audio_t {
     
    5658};
    5759
    58 aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(char_t * uri, uint_t samplerate) {
     60aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(const char_t * uri, uint_t samplerate) {
    5961  aubio_sink_apple_audio_t * s = AUBIO_NEW(aubio_sink_apple_audio_t);
    60   s->path = uri;
    6162  s->max_frames = MAX_SIZE;
    62   s->async = true;
     63  s->async = false;
    6364
    6465  if (uri == NULL) {
     
    6667    goto beach;
    6768  }
     69  if (s->path != NULL) AUBIO_FREE(s->path);
     70  s->path = AUBIO_ARRAY(char_t, strnlen(uri, PATH_MAX) + 1);
     71  strncpy(s->path, uri, strnlen(uri, PATH_MAX) + 1);
    6872
    6973  s->samplerate = 0;
     
    111115}
    112116
    113 uint_t aubio_sink_apple_audio_get_samplerate(aubio_sink_apple_audio_t *s)
     117uint_t aubio_sink_apple_audio_get_samplerate(const aubio_sink_apple_audio_t *s)
    114118{
    115119  return s->samplerate;
    116120}
    117121
    118 uint_t aubio_sink_apple_audio_get_channels(aubio_sink_apple_audio_t *s)
     122uint_t aubio_sink_apple_audio_get_channels(const aubio_sink_apple_audio_t *s)
    119123{
    120124  return s->channels;
     
    138142
    139143  AudioFileTypeID fileType = kAudioFileWAVEType;
    140   CFURLRef fileURL = getURLFromPath(s->path);
     144  CFURLRef fileURL = createURLFromPath(s->path);
    141145  bool overwrite = true;
    142146  OSStatus err = noErr;
    143147  err = ExtAudioFileCreateWithURL(fileURL, fileType, &clientFormat, NULL,
    144148     overwrite ? kAudioFileFlags_EraseFile : 0, &s->audioFile);
     149  CFRelease(fileURL);
    145150  if (err) {
    146151    char_t errorstr[20];
     
    162167
    163168void aubio_sink_apple_audio_do(aubio_sink_apple_audio_t * s, fvec_t * write_data, uint_t write) {
    164   OSStatus err = noErr;
    165169  UInt32 c, v;
    166170  short *data = (short*)s->bufferList.mBuffers[0].mData;
     
    179183      }
    180184  }
    181   if (s->async) {
    182     err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList);
    183 
    184     if (err) {
    185       char_t errorstr[20];
    186       AUBIO_ERROR("sink_apple_audio: error while writing %s "
    187           "in ExtAudioFileWriteAsync (%s), switching to sync\n", s->path,
    188           getPrintableOSStatusError(errorstr, err));
    189       s->async = false;
    190     } else {
    191       return;
    192     }
    193 
    194   } else {
    195     err = ExtAudioFileWrite(s->audioFile, write, &s->bufferList);
    196 
    197     if (err) {
    198       char_t errorstr[20];
    199       AUBIO_ERROR("sink_apple_audio: error while writing %s "
    200           "in ExtAudioFileWrite (%s)\n", s->path,
    201           getPrintableOSStatusError(errorstr, err));
    202     }
    203   }
    204   return;
     185  aubio_sink_apple_audio_write(s, write);
    205186}
    206187
    207188void aubio_sink_apple_audio_do_multi(aubio_sink_apple_audio_t * s, fmat_t * write_data, uint_t write) {
    208   OSStatus err = noErr;
    209189  UInt32 c, v;
    210190  short *data = (short*)s->bufferList.mBuffers[0].mData;
     
    223203      }
    224204  }
     205  aubio_sink_apple_audio_write(s, write);
     206}
     207
     208void aubio_sink_apple_audio_write(aubio_sink_apple_audio_t *s, uint_t write) {
     209  OSStatus err = noErr;
    225210  if (s->async) {
    226211    err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList);
    227 
    228212    if (err) {
    229213      char_t errorstr[20];
     214      if (err == kExtAudioFileError_AsyncWriteBufferOverflow) {
     215        sprintf(errorstr,"buffer overflow");
     216      } else if (err == kExtAudioFileError_AsyncWriteTooLarge) {
     217        sprintf(errorstr,"write too large");
     218      } else {
     219        // unknown error
     220        getPrintableOSStatusError(errorstr, err);
     221      }
    230222      AUBIO_ERROR("sink_apple_audio: error while writing %s "
    231           "in ExtAudioFileWriteAsync (%s), switching to sync\n", s->path,
    232           getPrintableOSStatusError(errorstr, err));
    233       s->async = false;
    234     } else {
    235       return;
     223                  "in ExtAudioFileWriteAsync (%s)\n", s->path, errorstr);
    236224    }
    237 
    238225  } else {
    239226    err = ExtAudioFileWrite(s->audioFile, write, &s->bufferList);
    240 
    241227    if (err) {
    242228      char_t errorstr[20];
     
    246232    }
    247233  }
    248   return;
    249234}
    250235
     
    267252void del_aubio_sink_apple_audio(aubio_sink_apple_audio_t * s) {
    268253  if (s->audioFile) aubio_sink_apple_audio_close (s);
     254  if (s->path) AUBIO_FREE(s->path);
    269255  freeAudioBufferList(&s->bufferList);
    270256  AUBIO_FREE(s);
  • TabularUnified src/io/sink_apple_audio.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_SINK_APPLE_AUDIO_H
    22 #define _AUBIO_SINK_APPLE_AUDIO_H
     21#ifndef AUBIO_SINK_APPLE_AUDIO_H
     22#define AUBIO_SINK_APPLE_AUDIO_H
    2323
    2424/** \file
     
    5959
    6060*/
    61 aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(char_t * uri, uint_t samplerate);
     61aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(const char_t * uri, uint_t samplerate);
    6262
    6363/**
     
    103103
    104104*/
    105 uint_t aubio_sink_apple_audio_get_samplerate(aubio_sink_apple_audio_t *s);
     105uint_t aubio_sink_apple_audio_get_samplerate(const aubio_sink_apple_audio_t *s);
    106106
    107107/**
     
    113113
    114114*/
    115 uint_t aubio_sink_apple_audio_get_channels(aubio_sink_apple_audio_t *s);
     115uint_t aubio_sink_apple_audio_get_channels(const aubio_sink_apple_audio_t *s);
    116116
    117117/**
     
    161161#endif
    162162
    163 #endif /* _AUBIO_SINK_APPLE_AUDIO_H */
     163#endif /* AUBIO_SINK_APPLE_AUDIO_H */
  • TabularUnified src/io/sink_sndfile.c

    r60fc05b rf264b17  
    5454uint_t aubio_sink_sndfile_open(aubio_sink_sndfile_t *s);
    5555
    56 aubio_sink_sndfile_t * new_aubio_sink_sndfile(char_t * path, uint_t samplerate) {
     56aubio_sink_sndfile_t * new_aubio_sink_sndfile(const char_t * path, uint_t samplerate) {
    5757  aubio_sink_sndfile_t * s = AUBIO_NEW(aubio_sink_sndfile_t);
    5858  s->max_size = MAX_SIZE;
    59   s->path = path;
    6059
    6160  if (path == NULL) {
     
    6362    return NULL;
    6463  }
     64
     65  if (s->path) AUBIO_FREE(s->path);
     66  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
     67  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
    6568
    6669  s->samplerate = 0;
     
    107110}
    108111
    109 uint_t aubio_sink_sndfile_get_samplerate(aubio_sink_sndfile_t *s)
     112uint_t aubio_sink_sndfile_get_samplerate(const aubio_sink_sndfile_t *s)
    110113{
    111114  return s->samplerate;
    112115}
    113116
    114 uint_t aubio_sink_sndfile_get_channels(aubio_sink_sndfile_t *s)
     117uint_t aubio_sink_sndfile_get_channels(const aubio_sink_sndfile_t *s)
    115118{
    116119  return s->channels;
     
    220223void del_aubio_sink_sndfile(aubio_sink_sndfile_t * s){
    221224  if (!s) return;
     225  if (s->path) AUBIO_FREE(s->path);
    222226  aubio_sink_sndfile_close(s);
    223227  AUBIO_FREE(s->scratch_data);
  • TabularUnified src/io/sink_sndfile.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_SINK_SNDFILE_H
    22 #define _AUBIO_SINK_SNDFILE_H
     21#ifndef AUBIO_SINK_SNDFILE_H
     22#define AUBIO_SINK_SNDFILE_H
    2323
    2424/** \file
     
    5858
    5959*/
    60 aubio_sink_sndfile_t * new_aubio_sink_sndfile(char_t * uri, uint_t samplerate);
     60aubio_sink_sndfile_t * new_aubio_sink_sndfile(const char_t * uri, uint_t samplerate);
    6161
    6262/**
     
    102102
    103103*/
    104 uint_t aubio_sink_sndfile_get_samplerate(aubio_sink_sndfile_t *s);
     104uint_t aubio_sink_sndfile_get_samplerate(const aubio_sink_sndfile_t *s);
    105105
    106106/**
     
    112112
    113113*/
    114 uint_t aubio_sink_sndfile_get_channels(aubio_sink_sndfile_t *s);
     114uint_t aubio_sink_sndfile_get_channels(const aubio_sink_sndfile_t *s);
    115115
    116116/**
     
    160160#endif
    161161
    162 #endif /* _AUBIO_SINK_SNDFILE_H */
     162#endif /* AUBIO_SINK_SNDFILE_H */
  • TabularUnified src/io/sink_wavwrite.c

    r60fc05b rf264b17  
    7878}
    7979
    80 aubio_sink_wavwrite_t * new_aubio_sink_wavwrite(char_t * path, uint_t samplerate) {
     80aubio_sink_wavwrite_t * new_aubio_sink_wavwrite(const char_t * path, uint_t samplerate) {
    8181  aubio_sink_wavwrite_t * s = AUBIO_NEW(aubio_sink_wavwrite_t);
    8282
     
    9090  }
    9191
    92   s->path = path;
     92  if (s->path) AUBIO_FREE(s->path);
     93  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
     94  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     95
    9396  s->max_size = MAX_SIZE;
    9497  s->bitspersample = 16;
     
    143146}
    144147
    145 uint_t aubio_sink_wavwrite_get_samplerate(aubio_sink_wavwrite_t *s)
     148uint_t aubio_sink_wavwrite_get_samplerate(const aubio_sink_wavwrite_t *s)
    146149{
    147150  return s->samplerate;
    148151}
    149152
    150 uint_t aubio_sink_wavwrite_get_channels(aubio_sink_wavwrite_t *s)
     153uint_t aubio_sink_wavwrite_get_channels(const aubio_sink_wavwrite_t *s)
    151154{
    152155  return s->channels;
     
    288291  if (!s) return;
    289292  aubio_sink_wavwrite_close(s);
     293  if (s->path) AUBIO_FREE(s->path);
    290294  AUBIO_FREE(s->scratch_data);
    291295  AUBIO_FREE(s);
  • TabularUnified src/io/sink_wavwrite.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_SINK_WAVWRITE_H
    22 #define _AUBIO_SINK_WAVWRITE_H
     21#ifndef AUBIO_SINK_WAVWRITE_H
     22#define AUBIO_SINK_WAVWRITE_H
    2323
    2424/** \file
     
    5858
    5959*/
    60 aubio_sink_wavwrite_t * new_aubio_sink_wavwrite(char_t * uri, uint_t samplerate);
     60aubio_sink_wavwrite_t * new_aubio_sink_wavwrite(const char_t * uri, uint_t samplerate);
    6161
    6262/**
     
    102102
    103103*/
    104 uint_t aubio_sink_wavwrite_get_samplerate(aubio_sink_wavwrite_t *s);
     104uint_t aubio_sink_wavwrite_get_samplerate(const aubio_sink_wavwrite_t *s);
    105105
    106106/**
     
    112112
    113113*/
    114 uint_t aubio_sink_wavwrite_get_channels(aubio_sink_wavwrite_t *s);
     114uint_t aubio_sink_wavwrite_get_channels(const aubio_sink_wavwrite_t *s);
    115115
    116116/**
     
    160160#endif
    161161
    162 #endif /* _AUBIO_SINK_WAVWRITE_H */
     162#endif /* AUBIO_SINK_WAVWRITE_H */
  • TabularUnified src/io/source.c

    r60fc05b rf264b17  
    4141typedef uint_t (*aubio_source_get_samplerate_t)(aubio_source_t * s);
    4242typedef uint_t (*aubio_source_get_channels_t)(aubio_source_t * s);
     43typedef uint_t (*aubio_source_get_duration_t)(aubio_source_t * s);
    4344typedef uint_t (*aubio_source_seek_t)(aubio_source_t * s, uint_t seek);
    4445typedef uint_t (*aubio_source_close_t)(aubio_source_t * s);
     
    5152  aubio_source_get_samplerate_t s_get_samplerate;
    5253  aubio_source_get_channels_t s_get_channels;
     54  aubio_source_get_duration_t s_get_duration;
    5355  aubio_source_seek_t s_seek;
    5456  aubio_source_close_t s_close;
     
    5658};
    5759
    58 aubio_source_t * new_aubio_source(char_t * uri, uint_t samplerate, uint_t hop_size) {
     60aubio_source_t * new_aubio_source(const char_t * uri, uint_t samplerate, uint_t hop_size) {
    5961  aubio_source_t * s = AUBIO_NEW(aubio_source_t);
    60 #if HAVE_LIBAV
     62#ifdef HAVE_LIBAV
    6163  s->source = (void *)new_aubio_source_avcodec(uri, samplerate, hop_size);
    6264  if (s->source) {
     
    6567    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_avcodec_get_channels);
    6668    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_avcodec_get_samplerate);
     69    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_avcodec_get_duration);
    6770    s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek);
    6871    s->s_close = (aubio_source_close_t)(aubio_source_avcodec_close);
     
    7881    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_apple_audio_get_channels);
    7982    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_apple_audio_get_samplerate);
     83    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_apple_audio_get_duration);
    8084    s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek);
    8185    s->s_close = (aubio_source_close_t)(aubio_source_apple_audio_close);
     
    8488  }
    8589#endif /* HAVE_SOURCE_APPLE_AUDIO */
    86 #if HAVE_SNDFILE
     90#ifdef HAVE_SNDFILE
    8791  s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size);
    8892  if (s->source) {
     
    9195    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_sndfile_get_channels);
    9296    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_sndfile_get_samplerate);
     97    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_sndfile_get_duration);
    9398    s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek);
    9499    s->s_close = (aubio_source_close_t)(aubio_source_sndfile_close);
     
    97102  }
    98103#endif /* HAVE_SNDFILE */
    99 #if HAVE_WAVREAD
     104#ifdef HAVE_WAVREAD
    100105  s->source = (void *)new_aubio_source_wavread(uri, samplerate, hop_size);
    101106  if (s->source) {
     
    104109    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_wavread_get_channels);
    105110    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_wavread_get_samplerate);
     111    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_wavread_get_duration);
    106112    s->s_seek = (aubio_source_seek_t)(aubio_source_wavread_seek);
    107113    s->s_close = (aubio_source_close_t)(aubio_source_wavread_close);
     
    142148}
    143149
     150uint_t aubio_source_get_duration(aubio_source_t *s) {
     151  return s->s_get_duration((void *)s->source);
     152}
     153
    144154uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) {
    145155  return s->s_seek((void *)s->source, seek);
  • TabularUnified src/io/source.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_SOURCE_H
    22 #define _AUBIO_SOURCE_H
     21#ifndef AUBIO_SOURCE_H
     22#define AUBIO_SOURCE_H
    2323
    2424/** \file
     
    8686
    8787*/
    88 aubio_source_t * new_aubio_source(char_t * uri, uint_t samplerate, uint_t hop_size);
     88aubio_source_t * new_aubio_source(const char_t * uri, uint_t samplerate, uint_t hop_size);
    8989
    9090/**
     
    150150/**
    151151
     152  get the duration of source object, in frames
     153
     154  \param s source object, created with ::new_aubio_source
     155  \return number of frames in file
     156
     157*/
     158uint_t aubio_source_get_duration (aubio_source_t * s);
     159
     160/**
     161
    152162  close source object
    153163
     
    172182#endif
    173183
    174 #endif /* _AUBIO_SOURCE_H */
     184#endif /* AUBIO_SOURCE_H */
  • TabularUnified src/io/source_apple_audio.c

    r60fc05b rf264b17  
    5252extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);
    5353extern void freeAudioBufferList(AudioBufferList *bufferList);
    54 extern CFURLRef getURLFromPath(const char * path);
     54extern CFURLRef createURLFromPath(const char * path);
    5555char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
    5656
    57 uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, char_t * path);
    58 
    59 aubio_source_apple_audio_t * new_aubio_source_apple_audio(char_t * path, uint_t samplerate, uint_t block_size)
     57uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, const char_t * path);
     58
     59aubio_source_apple_audio_t * new_aubio_source_apple_audio(const char_t * path, uint_t samplerate, uint_t block_size)
    6060{
    6161  aubio_source_apple_audio_t * s = AUBIO_NEW(aubio_source_apple_audio_t);
     
    8080  s->block_size = block_size;
    8181  s->samplerate = samplerate;
    82   s->path = path;
    8382
    8483  if ( aubio_source_apple_audio_open ( s, path ) ) {
     
    9291}
    9392
    94 uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, char_t * path)
     93uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, const char_t * path)
    9594{
    9695  OSStatus err = noErr;
    9796  UInt32 propSize;
    98   s->path = path;
     97
     98  if (s->path) AUBIO_FREE(s->path);
     99  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
     100  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
    99101
    100102  // open the resource url
    101   CFURLRef fileURL = getURLFromPath(path);
     103  CFURLRef fileURL = createURLFromPath(s->path);
    102104  err = ExtAudioFileOpenURL(fileURL, &s->audioFile);
     105  CFRelease(fileURL);
    103106  if (err == -43) {
    104107    AUBIO_ERR("source_apple_audio: Failed opening %s, "
     
    293296void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s){
    294297  aubio_source_apple_audio_close (s);
     298  if (s->path) AUBIO_FREE(s->path);
    295299  freeAudioBufferList(&s->bufferList);
    296300  AUBIO_FREE(s);
     
    308312  }
    309313  // check if we are not seeking out of the file
    310   SInt64 fileLengthFrames = 0;
    311   UInt32 propSize = sizeof(fileLengthFrames);
    312   ExtAudioFileGetProperty(s->audioFile,
    313       kExtAudioFileProperty_FileLengthFrames, &propSize, &fileLengthFrames);
     314  uint_t fileLengthFrames = aubio_source_apple_audio_get_duration(s);
    314315  // compute position in the source file, before resampling
    315316  smpl_t ratio = s->source_samplerate * 1. / s->samplerate;
     
    352353}
    353354
    354 uint_t aubio_source_apple_audio_get_samplerate(aubio_source_apple_audio_t * s) {
     355uint_t aubio_source_apple_audio_get_samplerate(const aubio_source_apple_audio_t * s) {
    355356  return s->samplerate;
    356357}
    357358
    358 uint_t aubio_source_apple_audio_get_channels(aubio_source_apple_audio_t * s) {
     359uint_t aubio_source_apple_audio_get_channels(const aubio_source_apple_audio_t * s) {
    359360  return s->channels;
    360361}
    361362
     363uint_t aubio_source_apple_audio_get_duration(const aubio_source_apple_audio_t * s) {
     364  SInt64 fileLengthFrames = 0;
     365  UInt32 propSize = sizeof(fileLengthFrames);
     366  OSStatus err = ExtAudioFileGetProperty(s->audioFile,
     367      kExtAudioFileProperty_FileLengthFrames, &propSize, &fileLengthFrames);
     368  if (err) {
     369    char_t errorstr[20];
     370    AUBIO_ERROR("source_apple_audio: Failed getting %s duration, "
     371        "error in ExtAudioFileGetProperty (%s)\n", s->path,
     372        getPrintableOSStatusError(errorstr, err));
     373    return err;
     374  }
     375  return (uint_t)fileLengthFrames;
     376}
     377
    362378#endif /* HAVE_SOURCE_APPLE_AUDIO */
  • TabularUnified src/io/source_apple_audio.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_SOURCE_APPLE_AUDIO_H
    22 #define _AUBIO_SOURCE_APPLE_AUDIO_H
     21#ifndef AUBIO_SOURCE_APPLE_AUDIO_H
     22#define AUBIO_SOURCE_APPLE_AUDIO_H
    2323
    2424/** \file
     
    5858
    5959*/
    60 aubio_source_apple_audio_t * new_aubio_source_apple_audio(char_t * uri, uint_t samplerate, uint_t hop_size);
     60aubio_source_apple_audio_t * new_aubio_source_apple_audio(const char_t * uri, uint_t samplerate, uint_t hop_size);
    6161
    6262/**
     
    9696
    9797*/
    98 uint_t aubio_source_apple_audio_get_samplerate(aubio_source_apple_audio_t * s);
     98uint_t aubio_source_apple_audio_get_samplerate(const aubio_source_apple_audio_t * s);
    9999
    100100/**
     
    106106
    107107*/
    108 uint_t aubio_source_apple_audio_get_channels(aubio_source_apple_audio_t * s);
     108uint_t aubio_source_apple_audio_get_channels(const aubio_source_apple_audio_t * s);
     109
     110/**
     111
     112  get the duration of source object, in frames
     113
     114  \param s source object, created with ::new_aubio_source_apple_audio
     115  \return number of frames in file
     116
     117*/
     118uint_t aubio_source_apple_audio_get_duration(const aubio_source_apple_audio_t * s);
    109119
    110120/**
     
    144154#endif
    145155
    146 #endif /* _AUBIO_SOURCE_APPLE_AUDIO_H */
     156#endif /* AUBIO_SOURCE_APPLE_AUDIO_H */
  • TabularUnified src/io/source_avcodec.c

    r60fc05b rf264b17  
    2424#ifdef HAVE_LIBAV
    2525
    26 // determine whether we use libavformat from ffmpe or libav
    27 #define FFMPEG_LIBAVFORMAT (LIBAVFORMAT_VERSION_MICRO > 99)
     26// determine whether we use libavformat from ffmpeg or from libav
     27#define FFMPEG_LIBAVFORMAT (LIBAVFORMAT_VERSION_MICRO > 99 )
     28// max_analyze_duration2 was used from ffmpeg libavformat 55.43.100 through 57.2.100
     29#define FFMPEG_LIBAVFORMAT_MAX_DUR2 FFMPEG_LIBAVFORMAT && ( \
     30      (LIBAVFORMAT_VERSION_MAJOR == 55 && LIBAVFORMAT_VERSION_MINOR >= 43) \
     31      || (LIBAVFORMAT_VERSION_MAJOR == 56) \
     32      || (LIBAVFORMAT_VERSION_MAJOR == 57 && LIBAVFORMAT_VERSION_MINOR < 2) \
     33      )
    2834
    2935#include <libavcodec/avcodec.h>
     
    6773void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, uint_t * read_samples);
    6874
    69 aubio_source_avcodec_t * new_aubio_source_avcodec(char_t * path, uint_t samplerate, uint_t hop_size) {
     75uint_t aubio_source_avcodec_has_network_url(aubio_source_avcodec_t *s);
     76
     77uint_t aubio_source_avcodec_has_network_url(aubio_source_avcodec_t *s) {
     78  char proto[20], authorization[256], hostname[128], uripath[256];
     79  int proto_size = 20, authorization_size = 256, hostname_size = 128,
     80      *port_ptr = 0, path_size = 256;
     81  av_url_split(proto, proto_size, authorization, authorization_size, hostname,
     82      hostname_size, port_ptr, uripath, path_size, s->path);
     83  if (strlen(proto)) {
     84    return 1;
     85  }
     86  return 0;
     87}
     88
     89
     90aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, uint_t samplerate, uint_t hop_size) {
    7091  aubio_source_avcodec_t * s = AUBIO_NEW(aubio_source_avcodec_t);
    7192  int err;
     
    85106  s->hop_size = hop_size;
    86107  s->channels = 1;
    87   s->path = path;
     108
     109  if (s->path) AUBIO_FREE(s->path);
     110  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
     111  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
    88112
    89113  // register all formats and codecs
    90114  av_register_all();
    91115
    92   // if path[0] != '/'
    93   //avformat_network_init();
     116  if (aubio_source_avcodec_has_network_url(s)) {
     117    avformat_network_init();
     118  }
    94119
    95120  // try opening the file and get some info about it
     
    104129
    105130  // try to make sure max_analyze_duration is big enough for most songs
    106 #if FFMPEG_LIBAVFORMAT
     131#if FFMPEG_LIBAVFORMAT_MAX_DUR2
    107132  avFormatCtx->max_analyze_duration2 *= 100;
    108133#else
     
    164189
    165190  if (samplerate == 0) {
    166     samplerate = s->input_samplerate;
    167     //AUBIO_DBG("sampling rate set to 0, automagically adjusting to %d\n", samplerate);
    168   }
    169   s->samplerate = samplerate;
     191    s->samplerate = s->input_samplerate;
     192  } else {
     193    s->samplerate = samplerate;
     194  }
    170195
    171196  if (s->samplerate >  s->input_samplerate) {
     
    300325  s->output = output;
    301326
    302   av_free_packet(&avPacket);
     327  av_packet_unref(&avPacket);
    303328}
    304329
     
    370395}
    371396
    372 uint_t aubio_source_avcodec_get_samplerate(aubio_source_avcodec_t * s) {
     397uint_t aubio_source_avcodec_get_samplerate(const aubio_source_avcodec_t * s) {
    373398  return s->samplerate;
    374399}
    375400
    376 uint_t aubio_source_avcodec_get_channels(aubio_source_avcodec_t * s) {
     401uint_t aubio_source_avcodec_get_channels(const aubio_source_avcodec_t * s) {
    377402  return s->input_channels;
    378403}
     
    398423}
    399424
     425uint_t aubio_source_avcodec_get_duration (aubio_source_avcodec_t * s) {
     426  if (s && &(s->avFormatCtx) != NULL) {
     427    int64_t duration = s->avFormatCtx->duration;
     428    return s->samplerate * ((uint_t)duration / 1e6 );
     429  }
     430  return 0;
     431}
     432
    400433uint_t aubio_source_avcodec_close(aubio_source_avcodec_t * s) {
    401434  if (s->avr != NULL) {
     
    425458    av_frame_free( &(s->avFrame) );
    426459  }
     460  if (s->path) AUBIO_FREE(s->path);
    427461  s->avFrame = NULL;
    428462  AUBIO_FREE(s);
  • TabularUnified src/io/source_avcodec.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_SOURCE_AVCODEC_H
    22 #define _AUBIO_SOURCE_AVCODEC_H
     21#ifndef AUBIO_SOURCE_AVCODEC_H
     22#define AUBIO_SOURCE_AVCODEC_H
    2323
    2424/** \file
     
    5757
    5858*/
    59 aubio_source_avcodec_t * new_aubio_source_avcodec(char_t * uri, uint_t samplerate, uint_t hop_size);
     59aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * uri, uint_t samplerate, uint_t hop_size);
    6060
    6161/**
     
    9595
    9696*/
    97 uint_t aubio_source_avcodec_get_samplerate(aubio_source_avcodec_t * s);
     97uint_t aubio_source_avcodec_get_samplerate(const aubio_source_avcodec_t * s);
    9898
    9999/**
     
    105105
    106106*/
    107 uint_t aubio_source_avcodec_get_channels (aubio_source_avcodec_t * s);
     107uint_t aubio_source_avcodec_get_channels (const aubio_source_avcodec_t * s);
    108108
    109109/**
     
    118118*/
    119119uint_t aubio_source_avcodec_seek (aubio_source_avcodec_t *s, uint_t pos);
     120
     121/**
     122
     123  get the duration of source object, in frames
     124
     125  \param s source object, created with ::new_aubio_source_avcodec
     126  \return number of frames in file
     127
     128*/
     129uint_t aubio_source_avcodec_get_duration (aubio_source_avcodec_t * s);
    120130
    121131/**
     
    143153#endif
    144154
    145 #endif /* _AUBIO_SOURCE_AVCODEC_H */
     155#endif /* AUBIO_SOURCE_AVCODEC_H */
  • TabularUnified src/io/source_sndfile.c

    r60fc05b rf264b17  
    3636#define MAX_SIZE 4096
    3737#define MAX_SAMPLES MAX_CHANNELS * MAX_SIZE
     38
     39#if !HAVE_AUBIO_DOUBLE
     40#define aubio_sf_read_smpl sf_read_float
     41#else /* HAVE_AUBIO_DOUBLE */
     42#define aubio_sf_read_smpl sf_read_double
     43#endif /* HAVE_AUBIO_DOUBLE */
    3844
    3945struct _aubio_source_sndfile_t {
     
    4854  int input_channels;
    4955  int input_format;
     56  int duration;
    5057
    5158  // resampling stuff
     
    5966  // some temporary memory for sndfile to write at
    6067  uint_t scratch_size;
    61   float *scratch_data;
     68  smpl_t *scratch_data;
    6269};
    6370
    64 aubio_source_sndfile_t * new_aubio_source_sndfile(char_t * path, uint_t samplerate, uint_t hop_size) {
     71aubio_source_sndfile_t * new_aubio_source_sndfile(const char_t * path, uint_t samplerate, uint_t hop_size) {
    6572  aubio_source_sndfile_t * s = AUBIO_NEW(aubio_source_sndfile_t);
    6673  SF_INFO sfinfo;
     
    8188  s->hop_size = hop_size;
    8289  s->channels = 1;
    83   s->path = path;
     90
     91  if (s->path) AUBIO_FREE(s->path);
     92  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
     93  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
    8494
    8595  // try opening the file, getting the info in sfinfo
     
    97107  s->input_channels   = sfinfo.channels;
    98108  s->input_format     = sfinfo.format;
     109  s->duration         = sfinfo.frames;
    99110
    100111  if (samplerate == 0) {
    101     samplerate = s->input_samplerate;
     112    s->samplerate = s->input_samplerate;
    102113    //AUBIO_DBG("sampling rate set to 0, automagically adjusting to %d\n", samplerate);
    103   }
    104   s->samplerate = samplerate;
     114  } else {
     115    s->samplerate = samplerate;
     116  }
    105117  /* compute input block size required before resampling */
    106   s->ratio = s->samplerate/(float)s->input_samplerate;
     118  s->ratio = s->samplerate/(smpl_t)s->input_samplerate;
    107119  s->input_hop_size = (uint_t)FLOOR(s->hop_size / s->ratio + .5);
    108120
     
    129141          s->input_samplerate, s->samplerate);
    130142    }
     143    s->duration = (uint_t)FLOOR(s->duration * s->ratio);
    131144  }
    132145#else
     
    139152  /* allocate data for de/interleaving reallocated when needed. */
    140153  s->scratch_size = s->input_hop_size * s->input_channels;
    141   s->scratch_data = AUBIO_ARRAY(float,s->scratch_size);
     154  s->scratch_data = AUBIO_ARRAY(smpl_t, s->scratch_size);
    142155
    143156  return s;
     
    153166  uint_t i,j, input_channels = s->input_channels;
    154167  /* read from file into scratch_data */
    155   sf_count_t read_samples = sf_read_float (s->handle, s->scratch_data, s->scratch_size);
     168  sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size);
    156169
    157170  /* where to store de-interleaved data */
     
    194207  uint_t i,j, input_channels = s->input_channels;
    195208  /* do actual reading */
    196   sf_count_t read_samples = sf_read_float (s->handle, s->scratch_data, s->scratch_size);
     209  sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size);
    197210
    198211  /* where to store de-interleaved data */
     
    214227    for (j = 0; j < read_samples / input_channels; j++) {
    215228      for (i = 0; i < read_data->height; i++) {
    216         ptr_data[i][j] = (smpl_t)s->scratch_data[j * input_channels + i];
     229        ptr_data[i][j] = s->scratch_data[j * input_channels + i];
    217230      }
    218231    }
     
    222235    for (j = 0; j < read_samples / input_channels; j++) {
    223236      for (i = 0; i < input_channels; i++) {
    224         ptr_data[i][j] = (smpl_t)s->scratch_data[j * input_channels + i];
     237        ptr_data[i][j] = s->scratch_data[j * input_channels + i];
    225238      }
    226239    }
     
    232245    for (j = 0; j < read_samples / input_channels; j++) {
    233246      for (i = input_channels; i < read_data->height; i++) {
    234         ptr_data[i][j] = (smpl_t)s->scratch_data[j * input_channels + (input_channels - 1)];
     247        ptr_data[i][j] = s->scratch_data[j * input_channels + (input_channels - 1)];
    235248      }
    236249    }
     
    261274uint_t aubio_source_sndfile_get_channels(aubio_source_sndfile_t * s) {
    262275  return s->input_channels;
     276}
     277
     278uint_t aubio_source_sndfile_get_duration (const aubio_source_sndfile_t * s) {
     279  if (s && s->duration) {
     280    return s->duration;
     281  }
     282  return 0;
    263283}
    264284
     
    300320  }
    301321#endif /* HAVE_SAMPLERATE */
     322  if (s->path) AUBIO_FREE(s->path);
    302323  AUBIO_FREE(s->scratch_data);
    303324  AUBIO_FREE(s);
  • TabularUnified src/io/source_sndfile.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_SOURCE_SNDFILE_H
    22 #define _AUBIO_SOURCE_SNDFILE_H
     21#ifndef AUBIO_SOURCE_SNDFILE_H
     22#define AUBIO_SOURCE_SNDFILE_H
    2323
    2424/** \file
     
    5757
    5858*/
    59 aubio_source_sndfile_t * new_aubio_source_sndfile(char_t * uri, uint_t samplerate, uint_t hop_size);
     59aubio_source_sndfile_t * new_aubio_source_sndfile(const char_t * uri, uint_t samplerate, uint_t hop_size);
    6060
    6161/**
     
    121121/**
    122122
     123  get the duration of source object, in frames
     124
     125  \param s source object, created with ::new_aubio_source_sndfile
     126  \return number of frames in file
     127
     128*/
     129uint_t aubio_source_sndfile_get_duration (const aubio_source_sndfile_t *s);
     130
     131/**
     132
    123133  close source
    124134
     
    143153#endif
    144154
    145 #endif /* _AUBIO_SOURCE_SNDFILE_H */
     155#endif /* AUBIO_SOURCE_SNDFILE_H */
  • TabularUnified src/io/source_wavread.c

    r60fc05b rf264b17  
    5353  uint_t eof;
    5454
     55  uint_t duration;
     56
    5557  size_t seek_start;
    5658
     
    6870}
    6971
    70 aubio_source_wavread_t * new_aubio_source_wavread(char_t * path, uint_t samplerate, uint_t hop_size) {
     72aubio_source_wavread_t * new_aubio_source_wavread(const char_t * path, uint_t samplerate, uint_t hop_size) {
    7173  aubio_source_wavread_t * s = AUBIO_NEW(aubio_source_wavread_t);
    7274  size_t bytes_read = 0, bytes_expected = 44;
    7375  unsigned char buf[5];
    74   unsigned int format, channels, sr, byterate, blockalign, bitspersample;//, data_size;
     76  unsigned int format, channels, sr, byterate, blockalign, duration, bitspersample;//, data_size;
    7577
    7678  if (path == NULL) {
     
    8789  }
    8890
    89   s->path = path;
     91  if (s->path) AUBIO_FREE(s->path);
     92  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
     93  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     94
    9095  s->samplerate = samplerate;
    9196  s->hop_size = hop_size;
     
    213218  // Subchunk2Size
    214219  bytes_read += fread(buf, 1, 4, s->fid);
     220  duration = read_little_endian(buf, 4) / blockalign;
     221
    215222  //data_size = buf[0] + (buf[1] << 8) + (buf[2] << 16) + (buf[3] << 24);
    216223  //AUBIO_MSG("found %d frames in %s\n", 8 * data_size / bitspersample / channels, s->path);
     
    232239  s->blockalign= blockalign;
    233240  s->bitspersample = bitspersample;
     241
     242  s->duration = duration;
    234243
    235244  s->short_output = (unsigned char *)calloc(s->blockalign, AUBIO_WAVREAD_BUFSIZE);
     
    372381}
    373382
     383uint_t aubio_source_wavread_get_duration (const aubio_source_wavread_t * s) {
     384  if (s && s->duration) {
     385    return s->duration;
     386  }
     387  return 0;
     388}
     389
    374390uint_t aubio_source_wavread_close (aubio_source_wavread_t * s) {
    375391  if (!s->fid) {
     
    389405  if (s->short_output) AUBIO_FREE(s->short_output);
    390406  if (s->output) del_fmat(s->output);
     407  if (s->path) AUBIO_FREE(s->path);
    391408  AUBIO_FREE(s);
    392409}
  • TabularUnified src/io/source_wavread.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_SOURCE_WAVREAD_H
    22 #define _AUBIO_SOURCE_WAVREAD_H
     21#ifndef AUBIO_SOURCE_WAVREAD_H
     22#define AUBIO_SOURCE_WAVREAD_H
    2323
    2424/** \file
     
    6262
    6363*/
    64 aubio_source_wavread_t * new_aubio_source_wavread(char_t * uri, uint_t samplerate, uint_t hop_size);
     64aubio_source_wavread_t * new_aubio_source_wavread(const char_t * uri, uint_t samplerate, uint_t hop_size);
    6565
    6666/**
     
    126126/**
    127127
     128  get the duration of source object, in frames
     129
     130  \param s source object, created with ::new_aubio_source_sndfile
     131  \return number of frames in file
     132
     133*/
     134uint_t aubio_source_wavread_get_duration (const aubio_source_wavread_t *s);
     135
     136/**
     137
    128138  close source
    129139
     
    148158#endif
    149159
    150 #endif /* _AUBIO_SOURCE_WAVREAD_H */
     160#endif /* AUBIO_SOURCE_WAVREAD_H */
  • TabularUnified src/io/utils_apple_audio.c

    r60fc05b rf264b17  
    3434}
    3535
    36 CFURLRef getURLFromPath(const char * path) {
     36CFURLRef createURLFromPath(const char * path) {
    3737  CFStringRef cfTotalPath = CFStringCreateWithCString (kCFAllocatorDefault,
    3838      path, kCFStringEncodingUTF8);
    3939
    40   return CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfTotalPath,
     40  CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfTotalPath,
    4141      kCFURLPOSIXPathStyle, false);
     42  CFRelease(cfTotalPath);
     43  return url;
    4244}
    4345
Note: See TracChangeset for help on using the changeset viewer.