Changes in / [0440778:e6a5aa5]


Ignore:
Files:
6 added
2 deleted
26 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/aubio_priv.h

    r0440778 re6a5aa5  
    368368#endif /* __STRICT_ANSI__ */
    369369
    370 #if defined(DEBUG)
    371 #include <assert.h>
    372 #define AUBIO_ASSERT(x) assert(x)
    373 #else
    374 #define AUBIO_ASSERT(x)
    375 #endif /* DEBUG */
    376 
    377370#endif /* AUBIO_PRIV_H */
  • TabularUnified src/io/ioutils.c

    r0440778 re6a5aa5  
    5252  return AUBIO_OK;
    5353}
    54 
    55 uint_t
    56 aubio_sink_validate_input_length(const char_t *kind, const char_t *path,
    57     uint_t max_size, uint_t write_data_length, uint_t write)
    58 {
    59   uint_t can_write = write;
    60 
    61   if (write > max_size) {
    62     AUBIO_WRN("%s: partial write to %s, trying to write %d frames,"
    63         " at most %d can be written at once\n", kind, path, write, max_size);
    64     can_write = max_size;
    65   }
    66 
    67   if (can_write > write_data_length) {
    68     AUBIO_WRN("%s: partial write to %s, trying to write %d frames,"
    69         " but found input of length %d\n", kind, path, write,
    70         write_data_length);
    71     can_write = write_data_length;
    72   }
    73 
    74   return can_write;
    75 }
    76 
    77 uint_t
    78 aubio_sink_validate_input_channels(const char_t *kind, const char_t *path,
    79     uint_t sink_channels, uint_t write_data_height)
    80 {
    81   uint_t channels = sink_channels;
    82   if (write_data_height < sink_channels) {
    83     AUBIO_WRN("%s: partial write to %s, trying to write %d channels,"
    84         " but found input of height %d\n", kind, path, sink_channels,
    85         write_data_height);
    86     channels = write_data_height;
    87   }
    88   return channels;
    89 }
  • TabularUnified src/io/ioutils.h

    r0440778 re6a5aa5  
    5454    uint_t channels);
    5555
    56 /** validate length of input
    57 
    58   \param kind       the object kind to report on
    59   \param path       the path to report on
    60   \param max_size   maximum number of frames that can be written
    61   \param write_data_length actual length of input vector/matrix
    62   \param write number of samples asked
    63 
    64   \return write or the maximum number of frames that can be written
    65 */
    66 uint_t
    67 aubio_sink_validate_input_length(const char_t *kind, const char_t *path,
    68     uint_t max_size, uint_t write_data_length, uint_t write);
    69 
    70 /** validate height of input
    71 
    72   \param kind       the object kind to report on
    73   \param path       the path to report on
    74   \param max_size   maximum number of channels that can be written
    75   \param write_data_height actual height of input matrix
    76 
    77   \return write_data_height or the maximum number of channels
    78 */
    79 uint_t
    80 aubio_sink_validate_input_channels(const char_t *kind, const char_t *path,
    81     uint_t sink_channels, uint_t write_data_height);
    82 
    8356#ifdef __cplusplus
    8457}
  • TabularUnified src/io/sink.c

    r0440778 re6a5aa5  
    103103  AUBIO_ERROR("sink: failed creating '%s' at %dHz (no sink built-in)\n", uri, samplerate);
    104104#endif
    105   del_aubio_sink(s);
     105  AUBIO_FREE(s);
    106106  return NULL;
    107107}
     
    136136
    137137void del_aubio_sink(aubio_sink_t * s) {
    138   AUBIO_ASSERT(s);
    139   if (s->s_del && s->sink)
    140     s->s_del((void *)s->sink);
     138  if (!s) return;
     139  s->s_del((void *)s->sink);
    141140  AUBIO_FREE(s);
     141  return;
    142142}
  • TabularUnified src/io/sink_apple_audio.c

    r0440778 re6a5aa5  
    6262  s->async = false;
    6363
    64   if ( (uri == NULL) || (strnlen(uri, PATH_MAX) < 1) ) {
     64  if ( (uri == NULL) || (strlen(uri) < 1) ) {
    6565    AUBIO_ERROR("sink_apple_audio: Aborted opening null path\n");
    6666    goto beach;
    6767  }
    68 
     68  if (s->path != NULL) AUBIO_FREE(s->path);
    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   del_aubio_sink_apple_audio(s);
     94  AUBIO_FREE(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   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);
     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);
    188193}
    189194
     
    191196  UInt32 c, v;
    192197  short *data = (short*)s->bufferList.mBuffers[0].mData;
    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);
     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);
    205213}
    206214
     
    250258
    251259void del_aubio_sink_apple_audio(aubio_sink_apple_audio_t * s) {
    252   AUBIO_ASSERT(s);
    253   if (s->audioFile)
    254     aubio_sink_apple_audio_close (s);
    255   if (s->path)
    256     AUBIO_FREE(s->path);
     260  if (s->audioFile) aubio_sink_apple_audio_close (s);
     261  if (s->path) AUBIO_FREE(s->path);
    257262  freeAudioBufferList(&s->bufferList);
    258263  AUBIO_FREE(s);
     264  return;
    259265}
    260266
  • TabularUnified src/io/sink_sndfile.c

    r0440778 re6a5aa5  
    5959  if (path == NULL) {
    6060    AUBIO_ERR("sink_sndfile: Aborted opening null path\n");
    61     goto beach;
    62   }
    63 
     61    return NULL;
     62  }
     63
     64  if (s->path) AUBIO_FREE(s->path);
    6465  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    6566  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    9798  s->samplerate = samplerate;
    9899  // automatically open when both samplerate and channels have been set
    99   if (/* s->samplerate != 0 && */ s->channels != 0) {
     100  if (s->samplerate != 0 && s->channels != 0) {
    100101    return aubio_sink_sndfile_open(s);
    101102  }
     
    110111  s->channels = channels;
    111112  // automatically open when both samplerate and channels have been set
    112   if (s->samplerate != 0 /* && s->channels != 0 */) {
     113  if (s->samplerate != 0 && s->channels != 0) {
    113114    return aubio_sink_sndfile_open(s);
    114115  }
     
    147148  /* allocate data for de/interleaving reallocated when needed. */
    148149  if (s->scratch_size >= MAX_SIZE * AUBIO_MAX_CHANNELS) {
    149     AUBIO_ERR("sink_sndfile: %d x %d exceeds maximum buffer size %d\n",
     150    abort();
     151    AUBIO_ERR("sink_sndfile: %d x %d exceeds maximum aubio_sink_sndfile buffer size %d\n",
    150152        s->max_size, s->channels, MAX_SIZE * AUBIO_MAX_CHANNELS);
    151153    return AUBIO_FAIL;
     
    157159
    158160void aubio_sink_sndfile_do(aubio_sink_sndfile_t *s, fvec_t * write_data, uint_t write){
    159   uint_t i, j;
     161  uint_t i, j, channels = s->channels;
     162  int nsamples = 0;
     163  smpl_t *pwrite;
    160164  sf_count_t written_frames;
    161   uint_t channels = s->channels;
    162   uint_t length = aubio_sink_validate_input_length("sink_sndfile", s->path,
    163       s->max_size, write_data->length, write);
    164   int nsamples = channels * length;
     165
     166  if (write > s->max_size) {
     167    AUBIO_WRN("sink_sndfile: trying to write %d frames, but only %d can be written at a time\n",
     168      write, s->max_size);
     169    write = s->max_size;
     170  }
     171
     172  nsamples = channels * write;
    165173
    166174  /* interleaving data  */
    167175  for ( i = 0; i < channels; i++) {
    168     for (j = 0; j < length; j++) {
    169       s->scratch_data[channels*j+i] = write_data->data[j];
     176    pwrite = (smpl_t *)write_data->data;
     177    for (j = 0; j < write; j++) {
     178      s->scratch_data[channels*j+i] = pwrite[j];
    170179    }
    171180  }
     
    180189
    181190void aubio_sink_sndfile_do_multi(aubio_sink_sndfile_t *s, fmat_t * write_data, uint_t write){
    182   uint_t i, j;
     191  uint_t i, j, channels = s->channels;
     192  int nsamples = 0;
     193  smpl_t *pwrite;
    183194  sf_count_t written_frames;
    184   uint_t channels = aubio_sink_validate_input_channels("sink_sndfile", s->path,
    185       s->channels, write_data->height);
    186   uint_t length = aubio_sink_validate_input_length("sink_sndfile", s->path,
    187       s->max_size, write_data->length, write);
    188   int nsamples = channels * length;
     195
     196  if (write > s->max_size) {
     197    AUBIO_WRN("sink_sndfile: trying to write %d frames, but only %d can be written at a time\n",
     198      write, s->max_size);
     199    write = s->max_size;
     200  }
     201
     202  nsamples = channels * write;
    189203
    190204  /* interleaving data  */
    191   for ( i = 0; i < channels; i++) {
    192     for (j = 0; j < length; j++) {
    193       s->scratch_data[channels*j+i] = write_data->data[i][j];
     205  for ( i = 0; i < write_data->height; i++) {
     206    pwrite = (smpl_t *)write_data->data[i];
     207    for (j = 0; j < write; j++) {
     208      s->scratch_data[channels*j+i] = pwrite[j];
    194209    }
    195210  }
     
    216231
    217232void del_aubio_sink_sndfile(aubio_sink_sndfile_t * s){
    218   AUBIO_ASSERT(s);
    219   if (s->handle)
    220     aubio_sink_sndfile_close(s);
    221   if (s->path)
    222     AUBIO_FREE(s->path);
    223   if (s->scratch_data)
    224     AUBIO_FREE(s->scratch_data);
     233  if (!s) return;
     234  if (s->path) AUBIO_FREE(s->path);
     235  aubio_sink_sndfile_close(s);
     236  AUBIO_FREE(s->scratch_data);
    225237  AUBIO_FREE(s);
    226238}
  • TabularUnified src/io/sink_vorbis.c

    r0440778 re6a5aa5  
    3636#include <errno.h> // errno
    3737#include <time.h> // time
    38 
    39 #define MAX_SIZE 2048
    4038
    4139struct _aubio_sink_vorbis_t {
     
    6967  aubio_sink_vorbis_t * s = AUBIO_NEW(aubio_sink_vorbis_t);
    7068
    71   if (!uri) {
    72     AUBIO_ERROR("sink_apple_audio: Aborted opening null path\n");
    73     goto failure;
    74   }
    75 
    7669  s->path = AUBIO_ARRAY(char_t, strnlen(uri, PATH_MAX) + 1);
    7770  strncpy(s->path, uri, strnlen(uri, PATH_MAX) + 1);
     
    117110
    118111  s->fid = fopen((const char *)s->path, "wb");
    119   if (!s->fid) {
    120     AUBIO_ERR("sink_vorbis: Error opening file %s (%s)\n",
    121         s->path, strerror(errno));
    122     return AUBIO_FAIL;
    123   }
     112  if (!s->fid) return AUBIO_FAIL;
    124113
    125114  vorbis_info_init(&s->vi);
     
    145134  {
    146135    int ret = 0;
    147     size_t wrote;
    148136    ogg_packet header;
    149137    ogg_packet header_comm;
     
    162150      ret = ogg_stream_flush(&s->os, &s->og);
    163151      if (ret==0) break;
    164       wrote = fwrite(s->og.header, 1, s->og.header_len, s->fid);
    165       ret = (wrote == (unsigned)s->og.header_len);
    166       wrote = fwrite(s->og.body,   1, s->og.body_len,   s->fid);
    167       ret &= (wrote == (unsigned)s->og.body_len);
    168       if (ret == 0) {
    169         AUBIO_ERR("sink_vorbis: failed writing \'%s\' to disk (%s)\n",
    170             s->path, strerror(errno));
    171         return AUBIO_FAIL;
    172       }
     152      fwrite(s->og.header, 1, s->og.header_len, s->fid);
     153      fwrite(s->og.body,   1, s->og.body_len,   s->fid);
    173154    }
    174155  }
     
    183164    return AUBIO_FAIL;
    184165  s->samplerate = samplerate;
    185   if (/* s->samplerate != 0 && */ s->channels != 0)
     166  if (s->samplerate != 0 && s->channels != 0)
    186167    return aubio_sink_vorbis_open(s);
    187168  return AUBIO_OK;
     
    196177  s->channels = channels;
    197178  // automatically open when both samplerate and channels have been set
    198   if (s->samplerate != 0 /* && s->channels != 0 */) {
     179  if (s->samplerate != 0 && s->channels != 0) {
    199180    return aubio_sink_vorbis_open(s);
    200181  }
     
    214195void aubio_sink_vorbis_write(aubio_sink_vorbis_t *s)
    215196{
    216   int result;
    217   size_t wrote;
    218197  // pre-analysis
    219198  while (vorbis_analysis_blockout(&s->vd, &s->vb) == 1) {
     
    227206
    228207      while (1) {
    229         result = ogg_stream_pageout (&s->os, &s->og);
     208        int result = ogg_stream_pageout (&s->os, &s->og);
    230209        if (result == 0) break;
    231         wrote = fwrite(s->og.header, 1, s->og.header_len, s->fid);
    232         result = (wrote == (unsigned)s->og.header_len);
    233         wrote = fwrite(s->og.body, 1, s->og.body_len,     s->fid);
    234         result &= (wrote == (unsigned)s->og.body_len);
    235         if (result == 0) {
    236           AUBIO_WRN("sink_vorbis: failed writing \'%s\' to disk (%s)\n",
    237               s->path, strerror(errno));
    238         }
     210        fwrite(s->og.header, 1, s->og.header_len, s->fid);
     211        fwrite(s->og.body,   1, s->og.body_len,   s->fid);
    239212        if (ogg_page_eos(&s->og)) break;
    240213      }
     
    247220{
    248221  uint_t c, v;
    249   uint_t length = aubio_sink_validate_input_length("sink_vorbis", s->path,
    250       MAX_SIZE, write_data->length, write);
    251   float **buffer = vorbis_analysis_buffer(&s->vd, (long)length);
     222  float **buffer = vorbis_analysis_buffer(&s->vd, (long)write);
    252223  // fill buffer
    253224  if (!write) {
     
    258229  } else {
    259230    for (c = 0; c < s->channels; c++) {
    260       for (v = 0; v < length; v++) {
     231      for (v = 0; v < write; v++) {
    261232        buffer[c][v] = write_data->data[v];
    262233      }
    263234    }
    264235    // tell vorbis how many frames were written
    265     vorbis_analysis_wrote(&s->vd, (long)length);
     236    vorbis_analysis_wrote(&s->vd, (long)write);
    266237  }
    267238  // write to file
     
    273244{
    274245  uint_t c, v;
    275   uint_t channels = aubio_sink_validate_input_channels("sink_vorbis", s->path,
    276       s->channels, write_data->height);
    277   uint_t length = aubio_sink_validate_input_length("sink_vorbis", s->path,
    278       MAX_SIZE, write_data->length, write);
    279   float **buffer = vorbis_analysis_buffer(&s->vd, (long)length);
     246  uint_t channels = MIN(s->channels, write_data->height);
     247  float **buffer = vorbis_analysis_buffer(&s->vd, (long)write);
    280248  // fill buffer
    281249  if (!write) {
     
    286254  } else {
    287255    for (c = 0; c < channels; c++) {
    288       for (v = 0; v < length; v++) {
     256      for (v = 0; v < write; v++) {
    289257        buffer[c][v] = write_data->data[c][v];
    290258      }
     
    299267uint_t aubio_sink_vorbis_close (aubio_sink_vorbis_t *s)
    300268{
    301   if (!s->fid) return AUBIO_FAIL;
    302269  //mark the end of stream
    303270  vorbis_analysis_wrote(&s->vd, 0);
     
    305272  aubio_sink_vorbis_write(s);
    306273
    307   if (s->fid && fclose(s->fid)) {
     274  if (fclose(s->fid)) {
    308275    AUBIO_ERR("sink_vorbis: Error closing file %s (%s)\n",
    309276        s->path, strerror(errno));
    310277    return AUBIO_FAIL;
    311278  }
    312   s->fid = NULL;
    313279  return AUBIO_OK;
    314280}
  • TabularUnified src/io/sink_wavwrite.c

    r0440778 re6a5aa5  
    8888    goto beach;
    8989  }
    90 
     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);
    9196  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    9297  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    131136  s->samplerate = samplerate;
    132137  // automatically open when both samplerate and channels have been set
    133   if (/* s->samplerate != 0 && */ s->channels != 0) {
     138  if (s->samplerate != 0 && s->channels != 0) {
    134139    return aubio_sink_wavwrite_open(s);
    135140  }
     
    144149  s->channels = channels;
    145150  // automatically open when both samplerate and channels have been set
    146   if (s->samplerate != 0 /* && s->channels != 0 */) {
     151  if (s->samplerate != 0 && s->channels != 0) {
    147152    return aubio_sink_wavwrite_open(s);
    148153  }
     
    229234
    230235void aubio_sink_wavwrite_do(aubio_sink_wavwrite_t *s, fvec_t * write_data, uint_t write){
    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);
     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);
    241248
    242249  if (written_frames != write) {
     
    251258  uint_t c = 0, i = 0, written_frames = 0;
    252259
    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++) {
     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++) {
    260268      s->scratch_data[i * s->channels + c] = HTOLES(FLOAT_TO_SHORT(write_data->data[c][i]));
    261269    }
    262270  }
    263   written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid);
     271  written_frames = fwrite(s->scratch_data, 2, write * s->channels, s->fid);
    264272
    265273  if (written_frames != write * s->channels) {
     
    290298
    291299void del_aubio_sink_wavwrite(aubio_sink_wavwrite_t * s){
    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);
     300  if (!s) return;
     301  aubio_sink_wavwrite_close(s);
     302  if (s->path) AUBIO_FREE(s->path);
     303  AUBIO_FREE(s->scratch_data);
    299304  AUBIO_FREE(s);
    300305}
  • TabularUnified src/io/source.c

    r0440778 re6a5aa5  
    122122     " (no source built-in)\n", uri, samplerate, hop_size);
    123123#endif
    124   del_aubio_source(s);
     124  AUBIO_FREE(s);
    125125  return NULL;
    126126}
     
    139139
    140140void del_aubio_source(aubio_source_t * s) {
    141   AUBIO_ASSERT(s);
    142   if (s->s_del && s->source)
    143     s->s_del((void *)s->source);
     141  if (!s) return;
     142  s->s_del((void *)s->source);
    144143  AUBIO_FREE(s);
    145144}
  • TabularUnified src/io/source.h

    r0440778 re6a5aa5  
    6060
    6161  \example io/test-source.c
     62  \example io/test-source_multi.c
    6263
    6364*/
  • TabularUnified src/io/source_apple_audio.c

    r0440778 re6a5aa5  
    6060  aubio_source_apple_audio_t * s = AUBIO_NEW(aubio_source_apple_audio_t);
    6161
    62   if (path == NULL || strnlen(path, PATH_MAX) < 1) {
     62  if (path == NULL) {
    6363    AUBIO_ERROR("source_apple_audio: Aborted opening null path\n");
    6464    goto beach;
     
    8686
    8787beach:
    88   del_aubio_source_apple_audio(s);
     88  AUBIO_FREE(s);
    8989  return NULL;
    9090}
     
    9595  UInt32 propSize;
    9696
     97  if (s->path) AUBIO_FREE(s->path);
    9798  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    9899  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    293294
    294295void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s){
    295   AUBIO_ASSERT(s);
    296296  aubio_source_apple_audio_close (s);
    297297  if (s->path) AUBIO_FREE(s->path);
    298298  freeAudioBufferList(&s->bufferList);
    299299  AUBIO_FREE(s);
     300  return;
    300301}
    301302
  • TabularUnified src/io/source_avcodec.c

    r0440778 re6a5aa5  
    4545#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,0,0)
    4646#define HAVE_AUBIO_LIBAVCODEC_DEPRECATED 1
    47 #endif
    48 
    49 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58,3,102)
    50 #define HAVE_AUBIO_LIBAVCODEC_TIMEBASE_FIX 1
    5147#endif
    5248
     
    148144  s->channels = 1;
    149145
     146  if (s->path) AUBIO_FREE(s->path);
    150147  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    151148  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    243240    goto beach;
    244241  }
    245 #if HAVE_AUBIO_LIBAVCODEC_TIMEBASE_FIX
    246   // avoids 'skipped frames warning' with avecodec < 58, deprecated after
    247   av_codec_set_pkt_timebase(avCodecCtx,
    248       avFormatCtx->streams[selected_stream]->time_base);
    249 #endif
    250242#endif
    251243
     
    639631
    640632void del_aubio_source_avcodec(aubio_source_avcodec_t * s){
    641   AUBIO_ASSERT(s);
     633  if (!s) return;
    642634  aubio_source_avcodec_close(s);
    643635  if (s->output != NULL) {
  • TabularUnified src/io/source_sndfile.c

    r0440778 re6a5aa5  
    8787  s->channels = 1;
    8888
     89  if (s->path) AUBIO_FREE(s->path);
    8990  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    9091  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    331332
    332333void del_aubio_source_sndfile(aubio_source_sndfile_t * s){
    333   AUBIO_ASSERT(s);
     334  if (!s) return;
    334335  aubio_source_sndfile_close(s);
    335336#ifdef HAVE_SAMPLERATE
  • TabularUnified src/io/source_wavread.c

    r0440778 re6a5aa5  
    9292  }
    9393
     94  if (s->path) AUBIO_FREE(s->path);
    9495  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    9596  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    471472
    472473void del_aubio_source_wavread(aubio_source_wavread_t * s) {
    473   AUBIO_ASSERT(s);
     474  if (!s) return;
    474475  aubio_source_wavread_close(s);
    475476  if (s->short_output) AUBIO_FREE(s->short_output);
  • TabularUnified tests/src/io/test-sink.c

    r0440778 re6a5aa5  
    22#include "utils_tests.h"
    33
    4 int test_wrong_params(void);
     4int main (int argc, char **argv)
     5{
     6  sint_t err = 0;
    57
    6 int main(int argc, char **argv)
    7 {
    8   uint_t err = 0;
    9   if (argc < 3 || argc >= 6) {
    10     PRINT_ERR("wrong number of arguments, running tests\n");
    11     err = test_wrong_params();
    12     PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n",
    13         argv[0]);
     8  if (argc < 3) {
     9    PRINT_ERR("not enough arguments, running tests\n");
     10    err = run_on_default_source_and_sink(main);
     11    PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
    1412    return err;
    1513  }
     
    2422  if ( argc >= 4 ) samplerate = atoi(argv[3]);
    2523  if ( argc >= 5 ) hop_size = atoi(argv[4]);
     24  if ( argc >= 6 ) {
     25    err = 2;
     26    PRINT_ERR("too many arguments\n");
     27    return err;
     28  }
    2629
    2730  fvec_t *vec = new_fvec(hop_size);
     31  if (!vec) { err = 1; goto beach_fvec; }
    2832
    2933  aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
     34  if (!i) { err = 1; goto beach_source; }
     35
    3036  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
    3137
    3238  aubio_sink_t *o = new_aubio_sink(sink_path, samplerate);
    33 
    34   if (!vec || !i || !o) { err = 1; goto failure; }
     39  if (!o) { err = 1; goto beach_sink; }
    3540
    3641  do {
     
    4045  } while ( read == hop_size );
    4146
    42   PRINT_MSG("%d frames read at %dHz (%d blocks) from %s and written to %s\n",
     47  PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
    4348      n_frames, samplerate, n_frames / hop_size,
    4449      source_path, sink_path);
    4550
    46   // close sink now (optional)
    47   aubio_sink_close(o);
    48 
    49 failure:
    50   if (o)
    51     del_aubio_sink(o);
    52   if (i)
    53     del_aubio_source(i);
    54   if (vec)
    55     del_fvec(vec);
    56 
     51  del_aubio_sink(o);
     52beach_sink:
     53  del_aubio_source(i);
     54beach_source:
     55  del_fvec(vec);
     56beach_fvec:
    5757  return err;
    5858}
    59 
    60 int test_wrong_params(void)
    61 {
    62   fvec_t *vec;
    63   fmat_t *mat;
    64   aubio_sink_t *s;
    65   char_t sink_path[PATH_MAX] = "tmp_aubio_XXXXXX";
    66   uint_t samplerate = 44100;
    67   uint_t hop_size = 256;
    68   uint_t oversized_hop_size = 4097;
    69   uint_t oversized_samplerate = 192000 * 8 + 1;
    70   uint_t channels = 3;
    71   uint_t oversized_channels = 1025;
    72   // create temp file
    73   int fd = create_temp_sink(sink_path);
    74 
    75   if (!fd) return 1;
    76 
    77   if (new_aubio_sink(   0,   samplerate)) return 1;
    78   if (new_aubio_sink("\0",   samplerate)) return 1;
    79   if (new_aubio_sink(sink_path,      -1)) return 1;
    80 
    81   s = new_aubio_sink(sink_path, 0);
    82 
    83   // check setting wrong parameters fails
    84   if (!aubio_sink_preset_samplerate(s, oversized_samplerate)) return 1;
    85   if (!aubio_sink_preset_channels(s, oversized_channels)) return 1;
    86   if (!aubio_sink_preset_channels(s, -1)) return 1;
    87 
    88   // check setting valid parameters passes
    89   if (aubio_sink_preset_samplerate(s, samplerate)) return 1;
    90   if (aubio_sink_preset_channels(s, 1)) return 1;
    91 
    92   // check writing a vector with valid length
    93   vec = new_fvec(hop_size);
    94   aubio_sink_do(s, vec, hop_size);
    95   // check writing more than in the input
    96   aubio_sink_do(s, vec, hop_size+1);
    97   // check write 0 frames
    98   aubio_sink_do(s, vec, 0);
    99   del_fvec(vec);
    100 
    101   // check writing an oversized vector
    102   vec = new_fvec(oversized_hop_size);
    103   aubio_sink_do(s, vec, oversized_hop_size);
    104   del_fvec(vec);
    105 
    106   // test delete without closing
    107   del_aubio_sink(s);
    108 
    109   s = new_aubio_sink(sink_path, 0);
    110 
    111   // preset channels first
    112   if (aubio_sink_preset_channels(s, channels)) return 1;
    113   if (aubio_sink_preset_samplerate(s, samplerate)) return 1;
    114 
    115   if (aubio_sink_get_samplerate(s) != samplerate) return 1;
    116   if (aubio_sink_get_channels(s) != channels) return 1;
    117 
    118   mat = new_fmat(channels, hop_size);
    119   // check writing a vector with valid length
    120   aubio_sink_do_multi(s, mat, hop_size);
    121   // check writing 0 frames
    122   aubio_sink_do_multi(s, mat, 0);
    123   // check writing more than in the input
    124   aubio_sink_do_multi(s, mat, hop_size+1);
    125   del_fmat(mat);
    126 
    127   // check writing oversized input
    128   mat = new_fmat(channels, oversized_hop_size);
    129   aubio_sink_do_multi(s, mat, oversized_hop_size);
    130   del_fmat(mat);
    131 
    132   // check writing undersized input
    133   mat = new_fmat(channels - 1, hop_size);
    134   aubio_sink_do_multi(s, mat, hop_size);
    135   del_fmat(mat);
    136 
    137   aubio_sink_close(s);
    138   // test closing twice
    139   aubio_sink_close(s);
    140 
    141   del_aubio_sink(s);
    142 
    143   // delete temp file
    144   close_temp_sink(sink_path, fd);
    145 
    146   return run_on_default_source_and_sink(main);
    147 }
  • TabularUnified tests/src/io/test-sink_apple_audio.c

    r0440778 re6a5aa5  
    22#include <aubio.h>
    33#include "utils_tests.h"
    4 
    5 #define aubio_sink_custom "apple_audio"
    6 
    7 #ifdef HAVE_SINK_APPLE_AUDIO
    8 #define HAVE_AUBIO_SINK_CUSTOM
    9 #define aubio_sink_custom_t aubio_sink_apple_audio_t
    10 #define new_aubio_sink_custom new_aubio_sink_apple_audio
    11 #define del_aubio_sink_custom del_aubio_sink_apple_audio
    12 #define aubio_sink_custom_do aubio_sink_apple_audio_do
    13 #define aubio_sink_custom_do_multi aubio_sink_apple_audio_do_multi
    14 #define aubio_sink_custom_close aubio_sink_apple_audio_close
    15 #define aubio_sink_custom_preset_samplerate aubio_sink_apple_audio_preset_samplerate
    16 #define aubio_sink_custom_preset_channels aubio_sink_apple_audio_preset_channels
    17 #define aubio_sink_custom_get_samplerate aubio_sink_apple_audio_get_samplerate
    18 #define aubio_sink_custom_get_channels aubio_sink_apple_audio_get_channels
    19 #endif /* HAVE_SINK_APPLE_AUDIO */
    20 
    21 #include "base-sink_custom.h"
    224
    235// this file uses the unstable aubio api, please use aubio_sink instead
     
    268int main (int argc, char **argv)
    279{
    28   return base_main(argc, argv);
     10  sint_t err = 0;
     11
     12  if (argc < 3) {
     13    PRINT_ERR("not enough arguments, running tests\n");
     14    err = run_on_default_source_and_sink(main);
     15    PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
     16    return err;
     17  }
     18
     19#ifdef HAVE_SINK_APPLE_AUDIO
     20  uint_t samplerate = 0;
     21  uint_t hop_size = 512;
     22  uint_t n_frames = 0, read = 0;
     23
     24  char_t *source_path = argv[1];
     25  char_t *sink_path = argv[2];
     26
     27  if ( argc >= 4 ) samplerate = atoi(argv[3]);
     28  if ( argc >= 5 ) hop_size = atoi(argv[4]);
     29  if ( argc >= 6 ) {
     30    err = 2;
     31    PRINT_ERR("too many arguments\n");
     32    return err;
     33  }
     34
     35  fvec_t *vec = new_fvec(hop_size);
     36  if (!vec) { err = 1; goto beach_fvec; }
     37
     38  aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
     39  if (!i) { err = 1; goto beach_source; }
     40
     41  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
     42
     43  aubio_sink_apple_audio_t *o = new_aubio_sink_apple_audio(sink_path, samplerate);
     44  if (!o) { err = 1; goto beach_sink; }
     45
     46  do {
     47    aubio_source_do(i, vec, &read);
     48    aubio_sink_apple_audio_do(o, vec, read);
     49    n_frames += read;
     50  } while ( read == hop_size );
     51
     52  PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
     53      n_frames, samplerate, n_frames / hop_size,
     54      source_path, sink_path);
     55
     56  del_aubio_sink_apple_audio(o);
     57beach_sink:
     58  del_aubio_source(i);
     59beach_source:
     60  del_fvec(vec);
     61beach_fvec:
     62#else /* HAVE_SINK_APPLE_AUDIO */
     63  err = 0;
     64  PRINT_ERR("aubio was not compiled with aubio_source_apple_audio\n");
     65#endif /* HAVE_SINK_APPLE_AUDIO */
     66  return err;
    2967}
  • TabularUnified tests/src/io/test-sink_sndfile.c

    r0440778 re6a5aa5  
    22#include <aubio.h>
    33#include "utils_tests.h"
    4 
    5 #define aubio_sink_custom "sndfile"
    6 
    7 #ifdef HAVE_SNDFILE
    8 #define HAVE_AUBIO_SINK_CUSTOM
    9 #define aubio_sink_custom_t aubio_sink_sndfile_t
    10 #define new_aubio_sink_custom new_aubio_sink_sndfile
    11 #define del_aubio_sink_custom del_aubio_sink_sndfile
    12 #define aubio_sink_custom_do aubio_sink_sndfile_do
    13 #define aubio_sink_custom_do_multi aubio_sink_sndfile_do_multi
    14 #define aubio_sink_custom_close aubio_sink_sndfile_close
    15 #define aubio_sink_custom_preset_samplerate aubio_sink_sndfile_preset_samplerate
    16 #define aubio_sink_custom_preset_channels aubio_sink_sndfile_preset_channels
    17 #define aubio_sink_custom_get_samplerate aubio_sink_sndfile_get_samplerate
    18 #define aubio_sink_custom_get_channels aubio_sink_sndfile_get_channels
    19 #endif /* HAVE_SNDFILE */
    20 
    21 #include "base-sink_custom.h"
    224
    235// this file uses the unstable aubio api, please use aubio_sink instead
     
    268int main (int argc, char **argv)
    279{
    28   return base_main(argc, argv);
     10  sint_t err = 0;
     11
     12  if (argc < 3) {
     13    PRINT_ERR("not enough arguments, running tests\n");
     14    err = run_on_default_source_and_sink(main);
     15    PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
     16    return err;
     17  }
     18
     19#ifdef HAVE_SNDFILE
     20  uint_t samplerate = 0;
     21  uint_t hop_size = 512;
     22  uint_t n_frames = 0, read = 0;
     23
     24  char_t *source_path = argv[1];
     25  char_t *sink_path = argv[2];
     26
     27  if ( argc >= 4 ) samplerate = atoi(argv[3]);
     28  if ( argc >= 5 ) hop_size = atoi(argv[4]);
     29  if ( argc >= 6 ) {
     30    err = 2;
     31    PRINT_ERR("too many arguments\n");
     32    return err;
     33  }
     34
     35  fvec_t *vec = new_fvec(hop_size);
     36  if (!vec) { err = 1; goto beach_fvec; }
     37
     38  aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
     39  if (!i) { err = 1; goto beach_source; }
     40
     41  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
     42
     43  aubio_sink_sndfile_t *o = new_aubio_sink_sndfile(sink_path, samplerate);
     44  if (!o) { err = 1; goto beach_sink; }
     45
     46  do {
     47    aubio_source_do(i, vec, &read);
     48    aubio_sink_sndfile_do(o, vec, read);
     49    n_frames += read;
     50  } while ( read == hop_size );
     51
     52  PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
     53      n_frames, samplerate, n_frames / hop_size,
     54      source_path, sink_path);
     55
     56  del_aubio_sink_sndfile(o);
     57beach_sink:
     58  del_aubio_source(i);
     59beach_source:
     60  del_fvec(vec);
     61beach_fvec:
     62#else
     63  err = 0;
     64  PRINT_ERR("aubio was not compiled with aubio_source_sndfile\n");
     65#endif /* HAVE_SNDFILE */
     66  return err;
    2967}
  • TabularUnified tests/src/io/test-sink_vorbis.c

    r0440778 re6a5aa5  
    33#include "utils_tests.h"
    44
    5 #define aubio_sink_custom "vorbis"
    6 
    7 #ifdef HAVE_VORBISENC
    8 // functions not exposed in the headers, declared here
     5#if 1 // test without inclusion in headers
    96typedef struct _aubio_sink_vorbis_t aubio_sink_vorbis_t;
    107extern aubio_sink_vorbis_t * new_aubio_sink_vorbis(const char_t *uri,
     
    129extern void del_aubio_sink_vorbis (aubio_sink_vorbis_t *s);
    1310extern uint_t aubio_sink_vorbis_open(aubio_sink_vorbis_t *s);
    14 extern uint_t aubio_sink_vorbis_close(aubio_sink_vorbis_t *s);
    1511extern uint_t aubio_sink_vorbis_preset_channels(aubio_sink_vorbis_t *s,
    1612    uint_t channels);
    1713extern uint_t aubio_sink_vorbis_preset_samplerate(aubio_sink_vorbis_t *s,
    1814    uint_t samplerate);
    19 extern void aubio_sink_vorbis_do(aubio_sink_vorbis_t *s, fvec_t *write_data,
    20     uint_t write);
    21 extern void aubio_sink_vorbis_do_multi(aubio_sink_vorbis_t *s,
    22     fmat_t *write_data, uint_t write);
    2315extern uint_t aubio_sink_vorbis_get_channels(aubio_sink_vorbis_t *s);
    2416extern uint_t aubio_sink_vorbis_get_samplerate(aubio_sink_vorbis_t *s);
     17extern void aubio_sink_vorbis_do_multi(aubio_sink_vorbis_t *s, fmat_t*
     18    write_data, uint_t write);
     19#endif
    2520
    26 #define HAVE_AUBIO_SINK_CUSTOM
    27 #define aubio_sink_custom_t aubio_sink_vorbis_t
    28 #define new_aubio_sink_custom new_aubio_sink_vorbis
    29 #define del_aubio_sink_custom del_aubio_sink_vorbis
    30 #define aubio_sink_custom_do aubio_sink_vorbis_do
    31 #define aubio_sink_custom_do_multi aubio_sink_vorbis_do_multi
    32 #define aubio_sink_custom_close aubio_sink_vorbis_close
    33 #define aubio_sink_custom_preset_samplerate aubio_sink_vorbis_preset_samplerate
    34 #define aubio_sink_custom_preset_channels aubio_sink_vorbis_preset_channels
    35 #define aubio_sink_custom_get_samplerate aubio_sink_vorbis_get_samplerate
    36 #define aubio_sink_custom_get_channels aubio_sink_vorbis_get_channels
    37 #endif /* HAVE_VORBISENC */
    38 
    39 #include "base-sink_custom.h"
    40 
    41 // this file uses the unstable aubio api, please use aubio_sink instead
    42 // see src/io/sink.h and tests/src/sink/test-sink.c
     21// this file uses the unstable aubio api to test aubio_sink_vorbis, please
     22// use aubio_sink instead see src/io/sink.h and tests/src/sink/test-sink.c
    4323
    4424int main (int argc, char **argv)
    4525{
    46   return base_main(argc, argv);
     26  sint_t err = 0;
     27
     28  if (argc < 3) {
     29    PRINT_ERR("not enough arguments, running tests\n");
     30    err = run_on_default_source_and_sink(main);
     31    PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [channels] [hop_size]\n", argv[0]);
     32    return err;
     33  }
     34
     35#ifdef HAVE_VORBISENC
     36  uint_t samplerate = 0;
     37  uint_t channels = 0;
     38  uint_t hop_size = 512;
     39  uint_t n_frames = 0, read = 0;
     40
     41  char_t *source_path = argv[1];
     42  char_t *sink_path = argv[2];
     43
     44  if ( argc >= 4 ) samplerate = atoi(argv[3]);
     45  if ( argc >= 5 ) channels = atoi(argv[4]);
     46  if ( argc >= 6 ) hop_size = atoi(argv[5]);
     47  if ( argc >= 7 ) {
     48    err = 2;
     49    PRINT_ERR("too many arguments\n");
     50    return err;
     51  }
     52
     53  aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
     54  if (!i) { err = 1; goto beach_source; }
     55
     56  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
     57  if (channels == 0 ) channels = aubio_source_get_channels(i);
     58
     59  fmat_t *mat = new_fmat(channels, hop_size);
     60  if (!mat) { err = 1; goto beach_fmat; }
     61
     62  aubio_sink_vorbis_t *o = new_aubio_sink_vorbis(sink_path, 0);
     63  if (!o) { err = 1; goto beach_sink; }
     64  err = aubio_sink_vorbis_preset_samplerate(o, samplerate);
     65  if (err) { goto beach; }
     66  err = aubio_sink_vorbis_preset_channels(o, channels);
     67  if (err) { goto beach; }
     68
     69  do {
     70    aubio_source_do_multi(i, mat, &read);
     71    aubio_sink_vorbis_do_multi(o, mat, read);
     72    n_frames += read;
     73  } while ( read == hop_size );
     74
     75  PRINT_MSG("read %d frames at %dHz in %d channels (%d blocks) from %s written to %s\n",
     76      n_frames, samplerate, channels, n_frames / hop_size,
     77      source_path, sink_path);
     78  PRINT_MSG("wrote %s with %dHz in %d channels\n", sink_path,
     79      aubio_sink_vorbis_get_samplerate(o),
     80      aubio_sink_vorbis_get_channels(o) );
     81
     82beach:
     83  del_aubio_sink_vorbis(o);
     84beach_sink:
     85  del_fmat(mat);
     86beach_fmat:
     87  del_aubio_source(i);
     88beach_source:
     89#else /* HAVE_VORBISENC */
     90  err = 0;
     91  PRINT_ERR("aubio was not compiled with aubio_sink_vorbis\n");
     92#endif /* HAVE_VORBISENC */
     93  return err;
    4794}
  • TabularUnified tests/src/io/test-sink_wavwrite.c

    r0440778 re6a5aa5  
    22#include <aubio.h>
    33#include "utils_tests.h"
    4 
    5 #define aubio_sink_custom "wavwrite"
    6 
    7 #ifdef HAVE_WAVWRITE
    8 #define HAVE_AUBIO_SINK_CUSTOM
    9 #define aubio_sink_custom_t aubio_sink_wavwrite_t
    10 #define new_aubio_sink_custom new_aubio_sink_wavwrite
    11 #define del_aubio_sink_custom del_aubio_sink_wavwrite
    12 #define aubio_sink_custom_do aubio_sink_wavwrite_do
    13 #define aubio_sink_custom_do_multi aubio_sink_wavwrite_do_multi
    14 #define aubio_sink_custom_close aubio_sink_wavwrite_close
    15 #define aubio_sink_custom_preset_samplerate aubio_sink_wavwrite_preset_samplerate
    16 #define aubio_sink_custom_preset_channels aubio_sink_wavwrite_preset_channels
    17 #define aubio_sink_custom_get_samplerate aubio_sink_wavwrite_get_samplerate
    18 #define aubio_sink_custom_get_channels aubio_sink_wavwrite_get_channels
    19 #endif /* HAVE_WAVWRITE */
    20 
    21 #include "base-sink_custom.h"
    224
    235// this file uses the unstable aubio api, please use aubio_sink instead
     
    268int main (int argc, char **argv)
    279{
    28   return base_main(argc, argv);
     10  sint_t err = 0;
     11
     12  if (argc < 3) {
     13    PRINT_ERR("not enough arguments, running tests\n");
     14    err = run_on_default_source_and_sink(main);
     15    PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
     16    return err;
     17  }
     18
     19#ifdef HAVE_WAVWRITE
     20  uint_t samplerate = 0;
     21  uint_t hop_size = 512;
     22  uint_t n_frames = 0, read = 0;
     23
     24  char_t *source_path = argv[1];
     25  char_t *sink_path = argv[2];
     26
     27  if ( argc >= 4 ) samplerate = atoi(argv[3]);
     28  if ( argc >= 5 ) hop_size = atoi(argv[4]);
     29  if ( argc >= 6 ) {
     30    err = 2;
     31    PRINT_ERR("too many arguments\n");
     32    return err;
     33  }
     34
     35  fvec_t *vec = new_fvec(hop_size);
     36  if (!vec) { err = 1; goto beach_fvec; }
     37
     38  aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
     39  if (!i) { err = 1; goto beach_source; }
     40
     41  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
     42
     43  aubio_sink_wavwrite_t *o = new_aubio_sink_wavwrite(sink_path, samplerate);
     44  if (!o) { err = 1; goto beach_sink; }
     45
     46  do {
     47    aubio_source_do(i, vec, &read);
     48    aubio_sink_wavwrite_do(o, vec, read);
     49    n_frames += read;
     50  } while ( read == hop_size );
     51
     52  PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
     53      n_frames, samplerate, n_frames / hop_size,
     54      source_path, sink_path);
     55
     56  del_aubio_sink_wavwrite(o);
     57beach_sink:
     58  del_aubio_source(i);
     59beach_source:
     60  del_fvec(vec);
     61beach_fvec:
     62#else
     63  err = 0;
     64  PRINT_ERR("aubio was not compiled with aubio_sink_wavwrite\n");
     65#endif /* HAVE_WAVWRITE */
     66  return err;
    2967}
  • TabularUnified tests/src/io/test-source.c

    r0440778 re6a5aa5  
    22#include "utils_tests.h"
    33
    4 int test_wrong_params(void);
    5 
    6 int main(int argc, char **argv)
     4int main (int argc, char **argv)
    75{
    86  uint_t err = 0;
    97  if (argc < 2) {
    108    PRINT_ERR("not enough arguments, running tests\n");
    11     err = test_wrong_params();
     9    err = run_on_default_source(main);
    1210    PRINT_MSG("read a wave file as a mono vector\n");
    1311    PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
     
    3028  char_t *source_path = argv[1];
    3129
     30
    3231  aubio_source_t* s =
    3332    new_aubio_source(source_path, samplerate, hop_size);
     33  if (!s) { err = 1; goto beach; }
    3434  fvec_t *vec = new_fvec(hop_size);
    35   if (!s || !vec) { err = 1; goto beach; }
    3635
    3736  uint_t n_frames_expected = aubio_source_get_duration(s);
     
    5150  // close the file (optional)
    5251  aubio_source_close(s);
    53 
    54 beach:
    55   if (vec)
    56     del_fvec(vec);
    57   if (s)
    58     del_aubio_source(s);
    59   return err;
    60 }
    61 
    62 int test_wrong_params(void)
    63 {
    64   char_t *uri = DEFINEDSTRING(AUBIO_TESTS_SOURCE);
    65   uint_t samplerate = 44100;
    66   uint_t hop_size = 512;
    67   uint_t channels, read = 0;
    68   fvec_t *vec;
    69   fmat_t *mat;
    70   aubio_source_t *s;
    71 
    72   if (new_aubio_source(0,    samplerate, hop_size)) return 1;
    73   if (new_aubio_source("\0", samplerate, hop_size)) return 1;
    74   if (new_aubio_source(uri,          -1, hop_size)) return 1;
    75   if (new_aubio_source(uri,           0,        0)) return 1;
    76 
    77   s = new_aubio_source(uri, samplerate, hop_size);
    78   if (!s) return 1;
    79   channels = aubio_source_get_channels(s);
    80 
    81   // vector to read downmixed samples
    82   vec = new_fvec(hop_size);
    83   // matrix to read individual channels
    84   mat = new_fmat(channels, hop_size);
    85 
    86   if (aubio_source_get_samplerate(s) != samplerate) return 1;
    87 
    88   // read first hop_size frames
    89   aubio_source_do(s, vec, &read);
    90   if (read != hop_size) return 1;
    91 
    92   // seek to 0
    93   if(aubio_source_seek(s, 0)) return 1;
    94 
    95   // read again as multiple channels
    96   aubio_source_do_multi(s, mat, &read);
    97   if (read != hop_size) return 1;
    98 
    99   // close the file (optional)
    100   aubio_source_close(s);
    10152  // test closing the file a second time
    10253  aubio_source_close(s);
    10354
    104   del_aubio_source(s);
    105   del_fmat(mat);
    106   del_fvec(vec);
    107 
    108   return run_on_default_source(main);
     55  del_fvec (vec);
     56  del_aubio_source (s);
     57beach:
     58  return err;
    10959}
  • TabularUnified tests/src/io/test-source_apple_audio.c

    r0440778 re6a5aa5  
    22#include <aubio.h>
    33#include "utils_tests.h"
    4 
    5 #define aubio_source_custom "apple_audio"
    6 
    7 #ifdef HAVE_SOURCE_APPLE_AUDIO
    8 #define HAVE_AUBIO_SOURCE_CUSTOM
    9 #define aubio_source_custom_t aubio_source_apple_audio_t
    10 #define new_aubio_source_custom new_aubio_source_apple_audio
    11 #define del_aubio_source_custom del_aubio_source_apple_audio
    12 #define aubio_source_custom_get_samplerate aubio_source_apple_audio_get_samplerate
    13 #define aubio_source_custom_get_duration aubio_source_apple_audio_get_duration
    14 #define aubio_source_custom_do aubio_source_apple_audio_do
    15 #define aubio_source_custom_do_multi aubio_source_apple_audio_do_multi
    16 #define aubio_source_custom_seek aubio_source_apple_audio_seek
    17 #define aubio_source_custom_close aubio_source_apple_audio_close
    18 #define aubio_source_custom_get_channels aubio_source_apple_audio_get_channels
    19 #define aubio_source_custom_get_samplerate aubio_source_apple_audio_get_samplerate
    20 #endif /* HAVE_SOURCE_APPLE_AUDIO */
    21 
    22 #include "base-source_custom.h"
    234
    245// this file uses the unstable aubio api, please use aubio_source instead
     
    278int main (int argc, char **argv)
    289{
    29   return base_main(argc, argv);
     10  uint_t err = 0;
     11  if (argc < 2) {
     12    PRINT_ERR("not enough arguments, running tests\n");
     13    err = run_on_default_source(main);
     14    PRINT_MSG("read a wave file as a mono vector\n");
     15    PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
     16    PRINT_MSG("examples:\n");
     17    PRINT_MSG(" - read file.wav at original samplerate\n");
     18    PRINT_MSG("       %s file.wav\n", argv[0]);
     19    PRINT_MSG(" - read file.aif at 32000Hz\n");
     20    PRINT_MSG("       %s file.aif 32000\n", argv[0]);
     21    PRINT_MSG(" - read file.mp3 at original samplerate with 4096 blocks\n");
     22    PRINT_MSG("       %s file.mp3 0 4096 \n", argv[0]);
     23    return err;
     24  }
     25
     26#if HAVE_SOURCE_APPLE_AUDIO
     27  uint_t samplerate = 0;
     28  uint_t hop_size = 256;
     29  uint_t n_frames = 0, read = 0;
     30  if ( argc >= 3 ) samplerate = atoi(argv[2]);
     31  if ( argc >= 4 ) hop_size = atoi(argv[3]);
     32
     33  char_t *source_path = argv[1];
     34
     35
     36  aubio_source_apple_audio_t * s =
     37    new_aubio_source_apple_audio(source_path, samplerate, hop_size);
     38  if (!s) { err = 1; goto beach; }
     39  fvec_t *vec = new_fvec(hop_size);
     40
     41  uint_t n_frames_expected = aubio_source_apple_audio_get_duration(s);
     42
     43  samplerate = aubio_source_apple_audio_get_samplerate(s);
     44
     45  do {
     46    aubio_source_apple_audio_do(s, vec, &read);
     47    fvec_print (vec);
     48    n_frames += read;
     49  } while ( read == hop_size );
     50
     51  PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
     52            n_frames, n_frames_expected, samplerate, n_frames / hop_size,
     53            source_path);
     54
     55  del_fvec (vec);
     56  del_aubio_source_apple_audio (s);
     57beach:
     58#else /* HAVE_SOURCE_APPLE_AUDIO */
     59  err = 0;
     60  PRINT_ERR("aubio was not compiled with aubio_source_apple_audio\n");
     61#endif /* HAVE_SOURCE_APPLE_AUDIO */
     62  return err;
    3063}
  • TabularUnified tests/src/io/test-source_avcodec.c

    r0440778 re6a5aa5  
    22#include <aubio.h>
    33#include "utils_tests.h"
    4 
    5 #define aubio_source_custom "avcodec"
    6 
    7 #ifdef HAVE_LIBAV
    8 #define HAVE_AUBIO_SOURCE_CUSTOM
    9 #define aubio_source_custom_t aubio_source_avcodec_t
    10 #define new_aubio_source_custom new_aubio_source_avcodec
    11 #define del_aubio_source_custom del_aubio_source_avcodec
    12 #define aubio_source_custom_get_samplerate aubio_source_avcodec_get_samplerate
    13 #define aubio_source_custom_get_duration aubio_source_avcodec_get_duration
    14 #define aubio_source_custom_do aubio_source_avcodec_do
    15 #define aubio_source_custom_do_multi aubio_source_avcodec_do_multi
    16 #define aubio_source_custom_seek aubio_source_avcodec_seek
    17 #define aubio_source_custom_close aubio_source_avcodec_close
    18 #define aubio_source_custom_get_channels aubio_source_avcodec_get_channels
    19 #define aubio_source_custom_get_samplerate aubio_source_avcodec_get_samplerate
    20 #endif /* HAVE_LIBAV */
    21 
    22 #include "base-source_custom.h"
    234
    245// this file uses the unstable aubio api, please use aubio_source instead
     
    278int main (int argc, char **argv)
    289{
    29   return base_main(argc, argv);
     10  uint_t err = 0;
     11  if (argc < 2) {
     12    PRINT_ERR("not enough arguments, running tests\n");
     13    err = run_on_default_source(main);
     14    PRINT_MSG("read a wave file as a mono vector\n");
     15    PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
     16    PRINT_MSG("examples:\n");
     17    PRINT_MSG(" - read file.wav at original samplerate\n");
     18    PRINT_MSG("       %s file.wav\n", argv[0]);
     19    PRINT_MSG(" - read file.wav at 32000Hz\n");
     20    PRINT_MSG("       %s file.aif 32000\n", argv[0]);
     21    PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
     22    PRINT_MSG("       %s file.wav 0 4096 \n", argv[0]);
     23    return err;
     24  }
     25
     26#ifdef HAVE_LIBAV
     27  uint_t samplerate = 0;
     28  uint_t hop_size = 256;
     29  uint_t n_frames = 0, read = 0;
     30  if ( argc >= 3 ) samplerate = atoi(argv[2]);
     31  if ( argc >= 4 ) hop_size = atoi(argv[3]);
     32
     33  char_t *source_path = argv[1];
     34
     35
     36  aubio_source_avcodec_t * s =
     37    new_aubio_source_avcodec(source_path, samplerate, hop_size);
     38  if (!s) { err = 1; goto beach; }
     39  fvec_t *vec = new_fvec(hop_size);
     40
     41  uint_t n_frames_expected = aubio_source_avcodec_get_duration(s);
     42
     43  samplerate = aubio_source_avcodec_get_samplerate(s);
     44
     45  do {
     46    aubio_source_avcodec_do(s, vec, &read);
     47    fvec_print (vec);
     48    n_frames += read;
     49  } while ( read == hop_size );
     50
     51  PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
     52            n_frames, n_frames_expected, samplerate, n_frames / hop_size,
     53            source_path);
     54
     55  del_fvec (vec);
     56  del_aubio_source_avcodec (s);
     57beach:
     58#else /* HAVE_LIBAV */
     59  err = 0;
     60  PRINT_ERR("aubio was not compiled with aubio_source_avcodec\n");
     61#endif /* HAVE_LIBAV */
     62  return err;
    3063}
  • TabularUnified tests/src/io/test-source_sndfile.c

    r0440778 re6a5aa5  
    22#include <aubio.h>
    33#include "utils_tests.h"
    4 
    5 #define aubio_source_custom "sndfile"
    6 
    7 #ifdef HAVE_SNDFILE
    8 #define HAVE_AUBIO_SOURCE_CUSTOM
    9 #define aubio_source_custom_t aubio_source_sndfile_t
    10 #define new_aubio_source_custom new_aubio_source_sndfile
    11 #define del_aubio_source_custom del_aubio_source_sndfile
    12 #define aubio_source_custom_get_samplerate aubio_source_sndfile_get_samplerate
    13 #define aubio_source_custom_get_duration aubio_source_sndfile_get_duration
    14 #define aubio_source_custom_do aubio_source_sndfile_do
    15 #define aubio_source_custom_do_multi aubio_source_sndfile_do_multi
    16 #define aubio_source_custom_seek aubio_source_sndfile_seek
    17 #define aubio_source_custom_close aubio_source_sndfile_close
    18 #define aubio_source_custom_get_channels aubio_source_sndfile_get_channels
    19 #define aubio_source_custom_get_samplerate aubio_source_sndfile_get_samplerate
    20 #endif /* HAVE_LIBAV */
    21 
    22 #include "base-source_custom.h"
    234
    245// this file uses the unstable aubio api, please use aubio_source instead
     
    278int main (int argc, char **argv)
    289{
    29   return base_main(argc, argv);
     10  uint_t err = 0;
     11  if (argc < 2) {
     12    PRINT_ERR("not enough arguments, running tests\n");
     13    err = run_on_default_source(main);
     14    PRINT_MSG("read a wave file as a mono vector\n");
     15    PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
     16    PRINT_MSG("examples:\n");
     17    PRINT_MSG(" - read file.wav at original samplerate\n");
     18    PRINT_MSG("       %s file.wav\n", argv[0]);
     19    PRINT_MSG(" - read file.wav at 32000Hz\n");
     20    PRINT_MSG("       %s file.aif 32000\n", argv[0]);
     21    PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
     22    PRINT_MSG("       %s file.wav 0 4096 \n", argv[0]);
     23    return err;
     24  }
     25
     26#ifdef HAVE_SNDFILE
     27  uint_t samplerate = 0;
     28  uint_t hop_size = 256;
     29  uint_t n_frames = 0, read = 0;
     30  if ( argc >= 3 ) samplerate = atoi(argv[2]);
     31  if ( argc >= 4 ) hop_size = atoi(argv[3]);
     32
     33  char_t *source_path = argv[1];
     34
     35
     36  aubio_source_sndfile_t * s =
     37    new_aubio_source_sndfile(source_path, samplerate, hop_size);
     38  if (!s) { err = 1; goto beach; }
     39  fvec_t *vec = new_fvec(hop_size);
     40
     41  uint_t n_frames_expected = aubio_source_sndfile_get_duration(s);
     42
     43  samplerate = aubio_source_sndfile_get_samplerate(s);
     44
     45  do {
     46    aubio_source_sndfile_do(s, vec, &read);
     47    fvec_print (vec);
     48    n_frames += read;
     49  } while ( read == hop_size );
     50
     51  PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
     52            n_frames, n_frames_expected, samplerate, n_frames / hop_size,
     53            source_path);
     54
     55  del_fvec (vec);
     56  del_aubio_source_sndfile (s);
     57beach:
     58#else
     59  err = 0;
     60  PRINT_ERR("aubio was not compiled with aubio_source_sndfile\n");
     61#endif /* HAVE_SNDFILE */
     62  return err;
    3063}
  • TabularUnified tests/src/io/test-source_wavread.c

    r0440778 re6a5aa5  
    22#include <aubio.h>
    33#include "utils_tests.h"
    4 
    5 #define aubio_source_custom "wavread"
    6 
    7 #ifdef HAVE_WAVREAD
    8 #define HAVE_AUBIO_SOURCE_CUSTOM
    9 #define aubio_source_custom_t aubio_source_wavread_t
    10 #define new_aubio_source_custom new_aubio_source_wavread
    11 #define del_aubio_source_custom del_aubio_source_wavread
    12 #define aubio_source_custom_get_samplerate aubio_source_wavread_get_samplerate
    13 #define aubio_source_custom_get_duration aubio_source_wavread_get_duration
    14 #define aubio_source_custom_do aubio_source_wavread_do
    15 #define aubio_source_custom_do_multi aubio_source_wavread_do_multi
    16 #define aubio_source_custom_seek aubio_source_wavread_seek
    17 #define aubio_source_custom_close aubio_source_wavread_close
    18 #define aubio_source_custom_get_channels aubio_source_wavread_get_channels
    19 #define aubio_source_custom_get_samplerate aubio_source_wavread_get_samplerate
    20 #endif /* HAVE_WAVREAD */
    21 
    22 #include "base-source_custom.h"
    234
    245// this file uses the unstable aubio api, please use aubio_source instead
     
    278int main (int argc, char **argv)
    289{
    29   return base_main(argc, argv);
     10  uint_t err = 0;
     11  if (argc < 2) {
     12    PRINT_ERR("not enough arguments, running tests\n");
     13    err = run_on_default_source(main);
     14    PRINT_MSG("read a wave file as a mono vector\n");
     15    PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
     16    PRINT_MSG("examples:\n");
     17    PRINT_MSG(" - read file.wav at original samplerate\n");
     18    PRINT_MSG("       %s file.wav\n", argv[0]);
     19    PRINT_MSG(" - read file.wav at 32000Hz\n");
     20    PRINT_MSG("       %s file.aif 32000\n", argv[0]);
     21    PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
     22    PRINT_MSG("       %s file.wav 0 4096 \n", argv[0]);
     23    return err;
     24  }
     25
     26#ifdef HAVE_WAVREAD
     27  uint_t samplerate = 0;
     28  uint_t hop_size = 256;
     29  uint_t n_frames = 0, read = 0;
     30  if ( argc >= 3 ) samplerate = atoi(argv[2]);
     31  if ( argc >= 4 ) hop_size = atoi(argv[3]);
     32
     33  char_t *source_path = argv[1];
     34
     35
     36  aubio_source_wavread_t * s =
     37    new_aubio_source_wavread(source_path, samplerate, hop_size);
     38  if (!s) { err = 1; goto beach; }
     39  fvec_t *vec = new_fvec(hop_size);
     40
     41  uint_t n_frames_expected = aubio_source_wavread_get_duration(s);
     42
     43  samplerate = aubio_source_wavread_get_samplerate(s);
     44
     45  do {
     46    aubio_source_wavread_do(s, vec, &read);
     47    fvec_print (vec);
     48    n_frames += read;
     49  } while ( read == hop_size );
     50
     51  PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
     52            n_frames, n_frames_expected, samplerate, n_frames / hop_size,
     53            source_path);
     54
     55  del_fvec (vec);
     56  del_aubio_source_wavread (s);
     57beach:
     58#else
     59  err = 0;
     60  PRINT_ERR("aubio was not compiled with aubio_source_wavread\n");
     61#endif /* HAVE_WAVREAD */
     62  return err;
    3063}
  • TabularUnified tests/utils_tests.h

    r0440778 re6a5aa5  
    5656#endif
    5757
    58 #if defined(HAVE_WIN_HACKS)
     58// are we on windows ? or are we using -std=c99 ?
     59#if defined(HAVE_WIN_HACKS) || defined(__STRICT_ANSI__)
     60// http://en.wikipedia.org/wiki/Linear_congruential_generator
     61// no srandom/random on win32
    5962
    60 // use srand/rand on windows
    61 #define srandom srand
    62 #define random rand
     63uint_t srandom_seed = 1029;
    6364
    64 #elif defined(__STRICT_ANSI__)
     65void srandom(uint_t new_seed) {
     66    srandom_seed = new_seed;
     67}
    6568
    66 // workaround to build with -std=c99 (for instance with older cygwin),
    67 // assuming libbc is recent enough to supports these functions.
    68 extern void srandom(unsigned);
    69 extern int random(void);
    70 extern char mkstemp(const char *pat);
    71 
     69uint_t random(void) {
     70    srandom_seed = 1664525 * srandom_seed + 1013904223;
     71    return srandom_seed;
     72}
    7273#endif
    7374
  • TabularUnified wscript

    r0440778 re6a5aa5  
    576576                target = bld.path.find_or_declare('api/index.html'),
    577577                cwd = bld.path.find_dir('doc'))
    578         # evaluate nodes lazily to prevent build directory traversal warnings
    579578        bld.install_files('${DATAROOTDIR}/doc/libaubio-doc/api',
    580                 bld.path.find_or_declare('api').ant_glob('**/*',
    581                     generator=True), cwd=bld.path.find_or_declare('api'),
     579                bld.path.find_or_declare('api').ant_glob('**/*'),
     580                cwd=bld.path.find_or_declare('api'),
    582581                relative_trick=True)
    583582
     
    601600                source = bld.path.find_dir('doc').ant_glob('*.rst'),
    602601                target = bld.path.find_or_declare('manual/index.html'))
    603         # evaluate nodes lazily to prevent build directory traversal warnings
    604602        bld.install_files('${DATAROOTDIR}/doc/libaubio-doc/manual',
    605                 bld.path.find_or_declare('manual').ant_glob('**/*',
    606                     generator=True), cwd=bld.path.find_or_declare('manual'),
     603                bld.path.find_or_declare('manual').ant_glob('**/*'),
     604                cwd=bld.path.find_or_declare('manual'),
    607605                relative_trick=True)
    608606
Note: See TracChangeset for help on using the changeset viewer.