Changes in / [ef47246:c059581]


Ignore:
Location:
src/io
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_apple_audio.c

    ref47246 rc059581  
    4848};
    4949
    50 extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);
     50extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
    5151extern void freeAudioBufferList(AudioBufferList *bufferList);
    5252extern CFURLRef getURLFromPath(const char * path);
     
    138138  }
    139139
    140   smpl_t ratio = s->source_samplerate * 1. / s->samplerate;
    141   if (ratio < 1.) {
    142     AUBIO_WRN("source_apple_audio: up-sampling %s from %0dHz to %0dHz\n",
    143         s->path, s->source_samplerate, s->samplerate);
     140  // compute the size of the segments needed to read the input file
     141  UInt32 samples = s->block_size * s->channels;
     142  Float64 rateRatio = s->samplerate / s->source_samplerate;
     143  uint_t segmentSize= (uint_t)(samples * rateRatio + .5);
     144  if (rateRatio < 1.) {
     145    segmentSize = (uint_t)(samples / rateRatio + .5);
     146  } else if (rateRatio > 1.) {
     147    AUBIO_WRN("up-sampling %s from %0dHz to %0dHz\n", s->path, s->source_samplerate, s->samplerate);
     148  } else {
     149    assert ( segmentSize == samples );
     150    //AUBIO_DBG("not resampling, segmentSize %d, block_size %d\n", segmentSize, s->block_size);
    144151  }
    145152
    146153  // allocate the AudioBufferList
    147   freeAudioBufferList(&s->bufferList);
    148   if (createAubioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) {
     154  if (createAubioBufferList(&s->bufferList, s->channels, segmentSize)) {
    149155    AUBIO_ERR("source_apple_audio: failed creating bufferList\n");
    150156    goto beach;
     
    241247
    242248uint_t aubio_source_apple_audio_seek (aubio_source_apple_audio_t * s, uint_t pos) {
    243   // after a short read, the bufferList size needs to resetted to prepare for a full read
    244   AudioBufferList *bufferList = &s->bufferList;
    245   bufferList->mBuffers[0].mDataByteSize = s->block_size * s->channels * sizeof (short);
    246   // compute position in the source file, before resampling
    247   smpl_t ratio = s->source_samplerate * 1. / s->samplerate;
    248   SInt64 resampled_pos = (SInt64)ROUND( pos * ratio );
     249  if (1) {
     250    AudioBufferList *bufferList = &s->bufferList;
     251    UInt32 samples = s->block_size * s->channels;
     252    Float64 rateRatio = s->samplerate / s->source_samplerate;
     253    uint_t segmentSize= (uint_t)(samples * rateRatio + .5);
     254    bufferList->mBuffers[0].mDataByteSize = segmentSize * sizeof(short);
     255  }
     256  SInt64 resampled_pos = (SInt64)ROUND( pos * s->source_samplerate * 1. / s->samplerate );
    249257  OSStatus err = ExtAudioFileSeek(s->audioFile, resampled_pos);
    250258  if (err) AUBIO_ERROR("source_apple_audio: error in ExtAudioFileSeek (%d)\n", (int)err);
  • src/io/utils_apple_audio.c

    ref47246 rc059581  
    1111CFURLRef getURLFromPath(const char * path);
    1212
    13 int createAubioBufferList(AudioBufferList * bufferList, int channels, int max_source_samples) {
     13int createAubioBufferList(AudioBufferList * bufferList, int channels, int segmentSize) {
    1414  bufferList->mNumberBuffers = 1;
    1515  bufferList->mBuffers[0].mNumberChannels = channels;
    16   bufferList->mBuffers[0].mData = AUBIO_ARRAY(short, max_source_samples);
    17   bufferList->mBuffers[0].mDataByteSize = max_source_samples * sizeof(short);
     16  bufferList->mBuffers[0].mData = AUBIO_ARRAY(short, segmentSize);
     17  bufferList->mBuffers[0].mDataByteSize = segmentSize * sizeof(short);
    1818  return 0;
    1919}
Note: See TracChangeset for help on using the changeset viewer.