Changes in src/io/source_apple_audio.c [4865e4b:6bbdcff]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/source_apple_audio.c
r4865e4b r6bbdcff 52 52 extern CFURLRef getURLFromPath(const char * path); 53 53 54 uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, char_t * path); 55 54 56 aubio_source_apple_audio_t * new_aubio_source_apple_audio(char_t * path, uint_t samplerate, uint_t block_size) 55 57 { 56 58 aubio_source_apple_audio_t * s = AUBIO_NEW(aubio_source_apple_audio_t); 57 59 58 s->path = path;59 60 s->block_size = block_size; 60 61 s->samplerate = samplerate; 62 63 if ( aubio_source_apple_audio_open ( s, path ) ) { 64 goto beach; 65 } 66 return s; 67 68 beach: 69 AUBIO_FREE(s); 70 return NULL; 71 } 72 73 uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, char_t * path) 74 { 61 75 OSStatus err = noErr; 62 76 UInt32 propSize; 77 s->path = path; 63 78 64 79 // open the resource url … … 77 92 if (err) { AUBIO_ERROR("error in ExtAudioFileGetProperty, %d\n", (int)err); goto beach;} 78 93 79 if (s amplerate == 0) {80 s amplerate = fileFormat.mSampleRate;94 if (s->samplerate == 0) { 95 s->samplerate = fileFormat.mSampleRate; 81 96 //AUBIO_DBG("sampling rate set to 0, automagically adjusting to %d\n", samplerate); 82 97 } 83 s->samplerate = samplerate; 98 84 99 s->source_samplerate = fileFormat.mSampleRate; 85 100 s->channels = fileFormat.mChannelsPerFrame; … … 124 139 125 140 // compute the size of the segments needed to read the input file 126 UInt32 samples = s->block_size * clientFormat.mChannelsPerFrame;127 Float64 rateRatio = clientFormat.mSampleRate / fileFormat.mSampleRate;141 UInt32 samples = s->block_size * s->channels; 142 Float64 rateRatio = s->samplerate / s->source_samplerate; 128 143 uint_t segmentSize= (uint_t)(samples * rateRatio + .5); 129 144 if (rateRatio < 1.) { 130 145 segmentSize = (uint_t)(samples / rateRatio + .5); 131 146 } else if (rateRatio > 1.) { 132 AUBIO_WRN("up-sampling %s from %0 .2fHz to %0.2fHz\n", s->path, fileFormat.mSampleRate, clientFormat.mSampleRate);147 AUBIO_WRN("up-sampling %s from %0dHz to %0dHz\n", s->path, s->source_samplerate, s->samplerate); 133 148 } else { 134 149 assert ( segmentSize == samples ); … … 137 152 138 153 // allocate the AudioBufferList 139 if (createAubioBufferList(&s->bufferList, s->channels, segmentSize)) err = -1;140 141 return s;142 143 beach: 144 AUBIO_FREE(s); 145 return NULL;154 if (createAubioBufferList(&s->bufferList, s->channels, segmentSize)) { 155 AUBIO_ERR("source_apple_audio: failed creating bufferList\n"); 156 goto beach; 157 } 158 159 beach: 160 return err; 146 161 } 147 162 … … 205 220 } 206 221 207 void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s){ 222 uint_t aubio_source_apple_audio_close (aubio_source_apple_audio_t *s) 223 { 208 224 OSStatus err = noErr; 209 if (!s || !s->audioFile) { return ; }225 if (!s || !s->audioFile) { return 1; } 210 226 err = ExtAudioFileDispose(s->audioFile); 211 227 if (err) AUBIO_ERROR("error in ExtAudioFileDispose, %d\n", (int)err); 212 228 s->audioFile = NULL; 229 return err; 230 } 231 232 void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s){ 233 aubio_source_apple_audio_close (s); 213 234 freeAudioBufferList(&s->bufferList); 214 235 AUBIO_FREE(s);
Note: See TracChangeset
for help on using the changeset viewer.