Changes in src/io/source_apple_audio.c [b8389de:c833f56]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/source_apple_audio.c
rb8389de rc833f56 48 48 }; 49 49 50 extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);50 extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples); 51 51 extern void freeAudioBufferList(AudioBufferList *bufferList); 52 52 extern CFURLRef getURLFromPath(const char * path); … … 138 138 } 139 139 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); 151 144 } 152 145 153 146 // 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)) { 155 149 AUBIO_ERR("source_apple_audio: failed creating bufferList\n"); 156 150 goto beach; … … 247 241 248 242 uint_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 ); 257 249 OSStatus err = ExtAudioFileSeek(s->audioFile, resampled_pos); 258 250 if (err) AUBIO_ERROR("source_apple_audio: error in ExtAudioFileSeek (%d)\n", (int)err);
Note: See TracChangeset
for help on using the changeset viewer.