- Timestamp:
- Mar 23, 2013, 7:06:02 AM (12 years ago)
- 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
- Location:
- src/io
- Files:
-
- 2 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); -
src/io/utils_apple_audio.c
rb8389de rc833f56 11 11 CFURLRef getURLFromPath(const char * path); 12 12 13 int createAubioBufferList(AudioBufferList * bufferList, int channels, int segmentSize) {13 int createAubioBufferList(AudioBufferList * bufferList, int channels, int max_source_samples) { 14 14 bufferList->mNumberBuffers = 1; 15 15 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); 18 18 return 0; 19 19 }
Note: See TracChangeset
for help on using the changeset viewer.