Changeset c833f56 for src/io


Ignore:
Timestamp:
Mar 23, 2013, 7:06:02 AM (12 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
0318cc1, ef47246
Parents:
b8389de
Message:

src/io/source_apple_audio.c: simplify buffer creation, reset size on seek

Location:
src/io
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/io/source_apple_audio.c

    rb8389de rc833f56  
    4848};
    4949
    50 extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
     50extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);
    5151extern void freeAudioBufferList(AudioBufferList *bufferList);
    5252extern CFURLRef getURLFromPath(const char * path);
     
    138138  }
    139139
    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);
     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);
    151144  }
    152145
    153146  // allocate the AudioBufferList
    154   if (createAubioBufferList(&s->bufferList, s->channels, segmentSize)) {
     147  freeAudioBufferList(&s->bufferList);
     148  if (createAubioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) {
    155149    AUBIO_ERR("source_apple_audio: failed creating bufferList\n");
    156150    goto beach;
     
    247241
    248242uint_t aubio_source_apple_audio_seek (aubio_source_apple_audio_t * s, uint_t pos) {
    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 );
     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 );
    257249  OSStatus err = ExtAudioFileSeek(s->audioFile, resampled_pos);
    258250  if (err) AUBIO_ERROR("source_apple_audio: error in ExtAudioFileSeek (%d)\n", (int)err);
  • src/io/utils_apple_audio.c

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