Changeset d0f19a7 for src


Ignore:
Timestamp:
Dec 19, 2018, 7:31:27 PM (12 months ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/pitchshift, feature/timestretch
Children:
0770148, cb0d7d0
Parents:
34d4232 (diff), 0045668 (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 feature/pitchshift

Location:
src
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • src/aubio_priv.h

    r34d4232 rd0f19a7  
    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
    370377#endif /* AUBIO_PRIV_H */
  • src/io/ioutils.c

    r34d4232 rd0f19a7  
    5252  return AUBIO_OK;
    5353}
     54
     55uint_t
     56aubio_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
     77uint_t
     78aubio_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}
  • src/io/ioutils.h

    r34d4232 rd0f19a7  
    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*/
     66uint_t
     67aubio_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*/
     79uint_t
     80aubio_sink_validate_input_channels(const char_t *kind, const char_t *path,
     81    uint_t sink_channels, uint_t write_data_height);
     82
    5683#ifdef __cplusplus
    5784}
  • src/io/sink.c

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

    r34d4232 rd0f19a7  
    3232#include <AudioToolbox/AudioToolbox.h>
    3333
    34 #define FLOAT_TO_SHORT(x) (short)(x * 32768)
    35 
    36 extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
     34extern int createAudioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
    3735extern void freeAudioBufferList(AudioBufferList *bufferList);
    3836extern CFURLRef createURLFromPath(const char * path);
     
    6260  s->async = false;
    6361
    64   if ( (uri == NULL) || (strlen(uri) < 1) ) {
     62  if ( (uri == NULL) || (strnlen(uri, PATH_MAX) < 1) ) {
    6563    AUBIO_ERROR("sink_apple_audio: Aborted opening null path\n");
    6664    goto beach;
    6765  }
    68   if (s->path != NULL) AUBIO_FREE(s->path);
     66
    6967  s->path = AUBIO_ARRAY(char_t, strnlen(uri, PATH_MAX) + 1);
    7068  strncpy(s->path, uri, strnlen(uri, PATH_MAX) + 1);
     
    7775    return s;
    7876  }
     77
    7978  // invalid samplerate given, abort
    8079  if (aubio_io_validate_samplerate("sink_apple_audio", s->path, samplerate)) {
     
    9291  return s;
    9392beach:
    94   AUBIO_FREE(s);
     93  del_aubio_sink_apple_audio(s);
    9594  return NULL;
    9695}
     
    103102  s->samplerate = samplerate;
    104103  // automatically open when both samplerate and channels have been set
    105   if (s->samplerate != 0 && s->channels != 0) {
     104  if (/* s->samplerate != 0 && */ s->channels != 0) {
    106105    return aubio_sink_apple_audio_open(s);
    107106  }
     
    116115  s->channels = channels;
    117116  // automatically open when both samplerate and channels have been set
    118   if (s->samplerate != 0 && s->channels != 0) {
     117  if (s->samplerate != 0 /* && s->channels != 0 */) {
    119118    return aubio_sink_apple_audio_open(s);
    120119  }
     
    151150  CFURLRef fileURL = createURLFromPath(s->path);
    152151  bool overwrite = true;
     152
     153  // set the in-memory format
     154  AudioStreamBasicDescription inputFormat;
     155  memset(&inputFormat, 0, sizeof(AudioStreamBasicDescription));
     156  inputFormat.mFormatID         = kAudioFormatLinearPCM;
     157  inputFormat.mSampleRate       = (Float64)(s->samplerate);
     158  inputFormat.mFormatFlags      = kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked;
     159  inputFormat.mChannelsPerFrame = s->channels;
     160  inputFormat.mBitsPerChannel   = sizeof(smpl_t) * 8;
     161  inputFormat.mFramesPerPacket  = 1;
     162  inputFormat.mBytesPerFrame    = inputFormat.mBitsPerChannel * inputFormat.mChannelsPerFrame / 8;
     163  inputFormat.mBytesPerPacket   = inputFormat.mFramesPerPacket * inputFormat.mBytesPerFrame;
    153164  OSStatus err = noErr;
    154165  err = ExtAudioFileCreateWithURL(fileURL, fileType, &clientFormat, NULL,
     
    162173    goto beach;
    163174  }
    164   if (createAubioBufferList(&s->bufferList, s->channels, s->max_frames * s->channels)) {
     175
     176  err = ExtAudioFileSetProperty(s->audioFile,
     177      kExtAudioFileProperty_ClientDataFormat,
     178      sizeof(AudioStreamBasicDescription), &inputFormat);
     179  if (err) {
     180    char_t errorstr[20];
     181    AUBIO_ERR("sink_apple_audio: error when trying to set output format on %s "
     182        "(%s)\n", s->path, getPrintableOSStatusError(errorstr, err));
     183    goto beach;
     184  }
     185
     186  if (createAudioBufferList(&s->bufferList, s->channels, s->max_frames * s->channels)) {
    165187    AUBIO_ERR("sink_apple_audio: error when creating buffer list for %s, "
    166188        "out of memory? \n", s->path);
     
    175197void aubio_sink_apple_audio_do(aubio_sink_apple_audio_t * s, fvec_t * write_data, uint_t write) {
    176198  UInt32 c, v;
    177   short *data = (short*)s->bufferList.mBuffers[0].mData;
    178   if (write > s->max_frames) {
    179     AUBIO_WRN("sink_apple_audio: trying to write %d frames, max %d\n", write, s->max_frames);
    180     write = s->max_frames;
    181   }
    182   smpl_t *buf = write_data->data;
    183 
    184   if (buf) {
    185       for (c = 0; c < s->channels; c++) {
    186           for (v = 0; v < write; v++) {
    187               data[v * s->channels + c] =
    188                   FLOAT_TO_SHORT(buf[ v * s->channels + c]);
    189           }
    190       }
    191   }
    192   aubio_sink_apple_audio_write(s, write);
     199  smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
     200  uint_t length = aubio_sink_validate_input_length("sink_apple_audio", s->path,
     201      s->max_frames, write_data->length, write);
     202
     203  for (c = 0; c < s->channels; c++) {
     204    for (v = 0; v < length; v++) {
     205      data[v * s->channels + c] = write_data->data[v];
     206    }
     207  }
     208
     209  aubio_sink_apple_audio_write(s, length);
    193210}
    194211
    195212void aubio_sink_apple_audio_do_multi(aubio_sink_apple_audio_t * s, fmat_t * write_data, uint_t write) {
    196213  UInt32 c, v;
    197   short *data = (short*)s->bufferList.mBuffers[0].mData;
    198   if (write > s->max_frames) {
    199     AUBIO_WRN("sink_apple_audio: trying to write %d frames, max %d\n", write, s->max_frames);
    200     write = s->max_frames;
    201   }
    202   smpl_t **buf = write_data->data;
    203 
    204   if (buf) {
    205       for (c = 0; c < s->channels; c++) {
    206           for (v = 0; v < write; v++) {
    207               data[v * s->channels + c] =
    208                   FLOAT_TO_SHORT(buf[c][v]);
    209           }
    210       }
    211   }
    212   aubio_sink_apple_audio_write(s, write);
     214  smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
     215  uint_t channels = aubio_sink_validate_input_channels("sink_apple_audio",
     216      s->path, s->channels, write_data->height);
     217  uint_t length = aubio_sink_validate_input_length("sink_apple_audio", s->path,
     218      s->max_frames, write_data->length, write);
     219
     220  for (c = 0; c < channels; c++) {
     221    for (v = 0; v < length; v++) {
     222      data[v * s->channels + c] = write_data->data[c][v];
     223    }
     224  }
     225
     226  aubio_sink_apple_audio_write(s, length);
    213227}
    214228
    215229void aubio_sink_apple_audio_write(aubio_sink_apple_audio_t *s, uint_t write) {
    216230  OSStatus err = noErr;
     231  // set mDataByteSize to match the number of frames to be written
     232  // see https://www.mail-archive.com/coreaudio-api@lists.apple.com/msg01109.html
     233  s->bufferList.mBuffers[0].mDataByteSize = write * s->channels
     234    * sizeof(smpl_t);
    217235  if (s->async) {
    218236    err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList);
     
    258276
    259277void del_aubio_sink_apple_audio(aubio_sink_apple_audio_t * s) {
    260   if (s->audioFile) aubio_sink_apple_audio_close (s);
    261   if (s->path) AUBIO_FREE(s->path);
     278  AUBIO_ASSERT(s);
     279  if (s->audioFile)
     280    aubio_sink_apple_audio_close (s);
     281  if (s->path)
     282    AUBIO_FREE(s->path);
    262283  freeAudioBufferList(&s->bufferList);
    263284  AUBIO_FREE(s);
    264   return;
    265285}
    266286
  • src/io/sink_sndfile.c

    r34d4232 rd0f19a7  
    5959  if (path == NULL) {
    6060    AUBIO_ERR("sink_sndfile: Aborted opening null path\n");
    61     return NULL;
    62   }
    63 
    64   if (s->path) AUBIO_FREE(s->path);
     61    goto beach;
     62  }
     63
    6564  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    6665  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    9897  s->samplerate = samplerate;
    9998  // automatically open when both samplerate and channels have been set
    100   if (s->samplerate != 0 && s->channels != 0) {
     99  if (/* s->samplerate != 0 && */ s->channels != 0) {
    101100    return aubio_sink_sndfile_open(s);
    102101  }
     
    111110  s->channels = channels;
    112111  // automatically open when both samplerate and channels have been set
    113   if (s->samplerate != 0 && s->channels != 0) {
     112  if (s->samplerate != 0 /* && s->channels != 0 */) {
    114113    return aubio_sink_sndfile_open(s);
    115114  }
     
    148147  /* allocate data for de/interleaving reallocated when needed. */
    149148  if (s->scratch_size >= MAX_SIZE * AUBIO_MAX_CHANNELS) {
    150     abort();
    151     AUBIO_ERR("sink_sndfile: %d x %d exceeds maximum aubio_sink_sndfile buffer size %d\n",
     149    AUBIO_ERR("sink_sndfile: %d x %d exceeds maximum buffer size %d\n",
    152150        s->max_size, s->channels, MAX_SIZE * AUBIO_MAX_CHANNELS);
    153151    return AUBIO_FAIL;
     
    159157
    160158void aubio_sink_sndfile_do(aubio_sink_sndfile_t *s, fvec_t * write_data, uint_t write){
    161   uint_t i, j, channels = s->channels;
    162   int nsamples = 0;
    163   smpl_t *pwrite;
     159  uint_t i, j;
    164160  sf_count_t written_frames;
    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;
     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;
    173165
    174166  /* interleaving data  */
    175167  for ( i = 0; i < channels; i++) {
    176     pwrite = (smpl_t *)write_data->data;
    177     for (j = 0; j < write; j++) {
    178       s->scratch_data[channels*j+i] = pwrite[j];
     168    for (j = 0; j < length; j++) {
     169      s->scratch_data[channels*j+i] = write_data->data[j];
    179170    }
    180171  }
     
    189180
    190181void aubio_sink_sndfile_do_multi(aubio_sink_sndfile_t *s, fmat_t * write_data, uint_t write){
    191   uint_t i, j, channels = s->channels;
    192   int nsamples = 0;
    193   smpl_t *pwrite;
     182  uint_t i, j;
    194183  sf_count_t written_frames;
    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;
     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;
    203189
    204190  /* interleaving data  */
    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];
     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];
    209194    }
    210195  }
     
    231216
    232217void del_aubio_sink_sndfile(aubio_sink_sndfile_t * s){
    233   if (!s) return;
    234   if (s->path) AUBIO_FREE(s->path);
    235   aubio_sink_sndfile_close(s);
    236   AUBIO_FREE(s->scratch_data);
     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);
    237225  AUBIO_FREE(s);
    238226}
  • src/io/sink_wavwrite.c

    r34d4232 rd0f19a7  
    8888    goto beach;
    8989  }
    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);
     90
    9691  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    9792  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    136131  s->samplerate = samplerate;
    137132  // automatically open when both samplerate and channels have been set
    138   if (s->samplerate != 0 && s->channels != 0) {
     133  if (/* s->samplerate != 0 && */ s->channels != 0) {
    139134    return aubio_sink_wavwrite_open(s);
    140135  }
     
    149144  s->channels = channels;
    150145  // automatically open when both samplerate and channels have been set
    151   if (s->samplerate != 0 && s->channels != 0) {
     146  if (s->samplerate != 0 /* && s->channels != 0 */) {
    152147    return aubio_sink_wavwrite_open(s);
    153148  }
     
    234229
    235230void aubio_sink_wavwrite_do(aubio_sink_wavwrite_t *s, fvec_t * write_data, uint_t write){
    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);
     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);
    248241
    249242  if (written_frames != write) {
     
    258251  uint_t c = 0, i = 0, written_frames = 0;
    259252
    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++) {
     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++) {
    268260      s->scratch_data[i * s->channels + c] = HTOLES(FLOAT_TO_SHORT(write_data->data[c][i]));
    269261    }
    270262  }
    271   written_frames = fwrite(s->scratch_data, 2, write * s->channels, s->fid);
     263  written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid);
    272264
    273265  if (written_frames != write * s->channels) {
     
    298290
    299291void del_aubio_sink_wavwrite(aubio_sink_wavwrite_t * s){
    300   if (!s) return;
    301   aubio_sink_wavwrite_close(s);
    302   if (s->path) AUBIO_FREE(s->path);
    303   AUBIO_FREE(s->scratch_data);
     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);
    304299  AUBIO_FREE(s);
    305300}
  • src/io/source.c

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

    r34d4232 rd0f19a7  
    6060
    6161  \example io/test-source.c
    62   \example io/test-source_multi.c
    6362
    6463*/
  • src/io/source_apple_audio.c

    r34d4232 rd0f19a7  
    3434#define RT_BYTE3( a )      ( ((a) >> 16) & 0xff )
    3535#define RT_BYTE4( a )      ( ((a) >> 24) & 0xff )
    36 
    37 #define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)
    3836
    3937struct _aubio_source_apple_audio_t {
     
    4947};
    5048
    51 extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);
     49extern int createAudioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);
    5250extern void freeAudioBufferList(AudioBufferList *bufferList);
    5351extern CFURLRef createURLFromPath(const char * path);
     
    6058  aubio_source_apple_audio_t * s = AUBIO_NEW(aubio_source_apple_audio_t);
    6159
    62   if (path == NULL) {
     60  if (path == NULL || strnlen(path, PATH_MAX) < 1) {
    6361    AUBIO_ERROR("source_apple_audio: Aborted opening null path\n");
    6462    goto beach;
     
    8684
    8785beach:
    88   AUBIO_FREE(s);
     86  del_aubio_source_apple_audio(s);
    8987  return NULL;
    9088}
     
    9593  UInt32 propSize;
    9694
    97   if (s->path) AUBIO_FREE(s->path);
    9895  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    9996  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    140137
    141138  AudioStreamBasicDescription clientFormat;
    142   propSize = sizeof(clientFormat);
     139  propSize = sizeof(AudioStreamBasicDescription);
    143140  memset(&clientFormat, 0, sizeof(AudioStreamBasicDescription));
    144141  clientFormat.mFormatID         = kAudioFormatLinearPCM;
    145142  clientFormat.mSampleRate       = (Float64)(s->samplerate);
    146   clientFormat.mFormatFlags      = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
     143  clientFormat.mFormatFlags      = kAudioFormatFlagIsFloat;
    147144  clientFormat.mChannelsPerFrame = s->channels;
    148   clientFormat.mBitsPerChannel   = sizeof(short) * 8;
     145  clientFormat.mBitsPerChannel   = sizeof(smpl_t) * 8;
    149146  clientFormat.mFramesPerPacket  = 1;
    150147  clientFormat.mBytesPerFrame    = clientFormat.mBitsPerChannel * clientFormat.mChannelsPerFrame / 8;
    151148  clientFormat.mBytesPerPacket   = clientFormat.mFramesPerPacket * clientFormat.mBytesPerFrame;
    152   clientFormat.mReserved         = 0;
    153149
    154150  // set the client format description
     
    188184  // allocate the AudioBufferList
    189185  freeAudioBufferList(&s->bufferList);
    190   if (createAubioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) {
     186  if (createAudioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) {
    191187    AUBIO_ERR("source_apple_audio: failed creating bufferList\n");
    192188    goto beach;
     
    197193}
    198194
    199 void aubio_source_apple_audio_do(aubio_source_apple_audio_t *s, fvec_t * read_to, uint_t * read) {
    200   UInt32 c, v, loadedPackets = s->block_size;
     195static UInt32 aubio_source_apple_audio_read_frame(aubio_source_apple_audio_t *s)
     196{
     197  UInt32 loadedPackets = s->block_size;
    201198  OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);
    202199  if (err) {
     
    205202        "with ExtAudioFileRead (%s)\n", s->path,
    206203        getPrintableOSStatusError(errorstr, err));
    207     goto beach;
    208   }
    209 
    210   short *data = (short*)s->bufferList.mBuffers[0].mData;
    211 
    212   smpl_t *buf = read_to->data;
     204  }
     205  return loadedPackets;
     206}
     207
     208void aubio_source_apple_audio_do(aubio_source_apple_audio_t *s, fvec_t * read_to,
     209    uint_t * read) {
     210  uint_t c, v;
     211  UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s);
     212  smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
    213213
    214214  for (v = 0; v < loadedPackets; v++) {
    215     buf[v] = 0.;
     215    read_to->data[v] = 0.;
    216216    for (c = 0; c < s->channels; c++) {
    217       buf[v] += SHORT_TO_FLOAT(data[ v * s->channels + c]);
    218     }
    219     buf[v] /= (smpl_t)s->channels;
     217      read_to->data[v] += data[ v * s->channels + c];
     218    }
     219    read_to->data[v] /= (smpl_t)s->channels;
    220220  }
    221221  // short read, fill with zeros
    222222  if (loadedPackets < s->block_size) {
    223223    for (v = loadedPackets; v < s->block_size; v++) {
    224       buf[v] = 0.;
     224      read_to->data[v] = 0.;
    225225    }
    226226  }
     
    228228  *read = (uint_t)loadedPackets;
    229229  return;
    230 beach:
    231   *read = 0;
    232   return;
    233230}
    234231
    235232void aubio_source_apple_audio_do_multi(aubio_source_apple_audio_t *s, fmat_t * read_to, uint_t * read) {
    236   UInt32 c, v, loadedPackets = s->block_size;
    237   OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);
    238   if (err) {
    239     char_t errorstr[20];
    240     AUBIO_ERROR("source_apple_audio: error while reading %s "
    241         "with ExtAudioFileRead (%s)\n", s->path,
    242         getPrintableOSStatusError(errorstr, err));
    243     goto beach;
    244   }
    245 
    246   short *data = (short*)s->bufferList.mBuffers[0].mData;
    247 
    248   smpl_t **buf = read_to->data;
     233  uint_t c, v;
     234  UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s);
     235  smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
    249236
    250237  for (v = 0; v < loadedPackets; v++) {
    251238    for (c = 0; c < read_to->height; c++) {
    252       buf[c][v] = SHORT_TO_FLOAT(data[ v * s->channels + c]);
     239      read_to->data[c][v] = data[ v * s->channels + c];
    253240    }
    254241  }
     
    258245    for (v = 0; v < loadedPackets; v++) {
    259246      for (c = s->channels; c < read_to->height; c++) {
    260         buf[c][v] = SHORT_TO_FLOAT(data[ v * s->channels + (s->channels - 1)]);
     247        read_to->data[c][v] = data[ v * s->channels + (s->channels - 1)];
    261248      }
    262249    }
     
    266253    for (v = loadedPackets; v < s->block_size; v++) {
    267254      for (c = 0; c < read_to->height; c++) {
    268         buf[c][v] = 0.;
     255        read_to->data[c][v] = 0.;
    269256      }
    270257    }
    271258  }
     259
    272260  *read = (uint_t)loadedPackets;
    273   return;
    274 beach:
    275   *read = 0;
    276261  return;
    277262}
     
    294279
    295280void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s){
     281  AUBIO_ASSERT(s);
    296282  aubio_source_apple_audio_close (s);
    297283  if (s->path) AUBIO_FREE(s->path);
    298284  freeAudioBufferList(&s->bufferList);
    299285  AUBIO_FREE(s);
    300   return;
    301286}
    302287
     
    324309  // after a short read, the bufferList size needs to resetted to prepare for a full read
    325310  AudioBufferList *bufferList = &s->bufferList;
    326   bufferList->mBuffers[0].mDataByteSize = s->block_size * s->channels * sizeof (short);
     311  bufferList->mBuffers[0].mDataByteSize = s->block_size * s->channels * sizeof (smpl_t);
    327312  // do the actual seek
    328313  err = ExtAudioFileSeek(s->audioFile, resampled_pos);
  • src/io/source_avcodec.c

    r34d4232 rd0f19a7  
    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
    4751#endif
    4852
     
    144148  s->channels = 1;
    145149
    146   if (s->path) AUBIO_FREE(s->path);
    147150  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    148151  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    240243    goto beach;
    241244  }
     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
    242250#endif
    243251
     
    631639
    632640void del_aubio_source_avcodec(aubio_source_avcodec_t * s){
    633   if (!s) return;
     641  AUBIO_ASSERT(s);
    634642  aubio_source_avcodec_close(s);
    635643  if (s->output != NULL) {
  • src/io/source_sndfile.c

    r34d4232 rd0f19a7  
    8787  s->channels = 1;
    8888
    89   if (s->path) AUBIO_FREE(s->path);
    9089  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    9190  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    332331
    333332void del_aubio_source_sndfile(aubio_source_sndfile_t * s){
    334   if (!s) return;
     333  AUBIO_ASSERT(s);
    335334  aubio_source_sndfile_close(s);
    336335#ifdef HAVE_SAMPLERATE
  • src/io/source_wavread.c

    r34d4232 rd0f19a7  
    9292  }
    9393
    94   if (s->path) AUBIO_FREE(s->path);
    9594  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    9695  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    472471
    473472void del_aubio_source_wavread(aubio_source_wavread_t * s) {
    474   if (!s) return;
     473  AUBIO_ASSERT(s);
    475474  aubio_source_wavread_close(s);
    476475  if (s->short_output) AUBIO_FREE(s->short_output);
  • src/io/utils_apple_audio.c

    r34d4232 rd0f19a7  
    1313char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
    1414
    15 int createAubioBufferList(AudioBufferList * bufferList, int channels, int max_source_samples) {
     15int createAudioBufferList(AudioBufferList * bufferList, int channels,
     16    int max_source_samples) {
    1617  bufferList->mNumberBuffers = 1;
    1718  bufferList->mBuffers[0].mNumberChannels = channels;
    18   bufferList->mBuffers[0].mData = AUBIO_ARRAY(short, max_source_samples);
    19   bufferList->mBuffers[0].mDataByteSize = max_source_samples * sizeof(short);
     19  bufferList->mBuffers[0].mData = AUBIO_ARRAY(smpl_t, max_source_samples);
     20  bufferList->mBuffers[0].mDataByteSize = max_source_samples * sizeof(smpl_t);
    2021  return 0;
    2122}
Note: See TracChangeset for help on using the changeset viewer.