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