Changeset 74c1fb9 for src/io/source_apple_audio.c
- Timestamp:
- Dec 19, 2018, 5:50:42 PM (5 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
- Children:
- 0045668
- Parents:
- c1ba75b (diff), fda3394 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/source_apple_audio.c
rc1ba75b r74c1fb9 34 34 #define RT_BYTE3( a ) ( ((a) >> 16) & 0xff ) 35 35 #define RT_BYTE4( a ) ( ((a) >> 24) & 0xff ) 36 37 #define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)38 36 39 37 struct _aubio_source_apple_audio_t { … … 49 47 }; 50 48 51 extern int createAu bioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);49 extern int createAudioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples); 52 50 extern void freeAudioBufferList(AudioBufferList *bufferList); 53 51 extern CFURLRef createURLFromPath(const char * path); … … 60 58 aubio_source_apple_audio_t * s = AUBIO_NEW(aubio_source_apple_audio_t); 61 59 62 if (path == NULL ) {60 if (path == NULL || strnlen(path, PATH_MAX) < 1) { 63 61 AUBIO_ERROR("source_apple_audio: Aborted opening null path\n"); 64 62 goto beach; … … 86 84 87 85 beach: 88 AUBIO_FREE(s);86 del_aubio_source_apple_audio(s); 89 87 return NULL; 90 88 } … … 95 93 UInt32 propSize; 96 94 97 if (s->path) AUBIO_FREE(s->path);98 95 s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1); 99 96 strncpy(s->path, path, strnlen(path, PATH_MAX) + 1); … … 140 137 141 138 AudioStreamBasicDescription clientFormat; 142 propSize = sizeof( clientFormat);139 propSize = sizeof(AudioStreamBasicDescription); 143 140 memset(&clientFormat, 0, sizeof(AudioStreamBasicDescription)); 144 141 clientFormat.mFormatID = kAudioFormatLinearPCM; 145 142 clientFormat.mSampleRate = (Float64)(s->samplerate); 146 clientFormat.mFormatFlags = kAudioFormatFlagIs SignedInteger | kAudioFormatFlagIsPacked;143 clientFormat.mFormatFlags = kAudioFormatFlagIsFloat; 147 144 clientFormat.mChannelsPerFrame = s->channels; 148 clientFormat.mBitsPerChannel = sizeof(s hort) * 8;145 clientFormat.mBitsPerChannel = sizeof(smpl_t) * 8; 149 146 clientFormat.mFramesPerPacket = 1; 150 147 clientFormat.mBytesPerFrame = clientFormat.mBitsPerChannel * clientFormat.mChannelsPerFrame / 8; 151 148 clientFormat.mBytesPerPacket = clientFormat.mFramesPerPacket * clientFormat.mBytesPerFrame; 152 clientFormat.mReserved = 0;153 149 154 150 // set the client format description … … 188 184 // allocate the AudioBufferList 189 185 freeAudioBufferList(&s->bufferList); 190 if (createAu bioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) {186 if (createAudioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) { 191 187 AUBIO_ERR("source_apple_audio: failed creating bufferList\n"); 192 188 goto beach; … … 197 193 } 198 194 199 void aubio_source_apple_audio_do(aubio_source_apple_audio_t *s, fvec_t * read_to, uint_t * read) { 200 UInt32 c, v, loadedPackets = s->block_size; 195 static UInt32 aubio_source_apple_audio_read_frame(aubio_source_apple_audio_t *s) 196 { 197 UInt32 loadedPackets = s->block_size; 201 198 OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList); 202 199 if (err) { … … 205 202 "with ExtAudioFileRead (%s)\n", s->path, 206 203 getPrintableOSStatusError(errorstr, err)); 207 goto beach; 208 } 209 210 short *data = (short*)s->bufferList.mBuffers[0].mData; 211 212 smpl_t *buf = read_to->data; 204 } 205 return loadedPackets; 206 } 207 208 void aubio_source_apple_audio_do(aubio_source_apple_audio_t *s, fvec_t * read_to, 209 uint_t * read) { 210 uint_t c, v; 211 UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s); 212 smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData; 213 213 214 214 for (v = 0; v < loadedPackets; v++) { 215 buf[v] = 0.;215 read_to->data[v] = 0.; 216 216 for (c = 0; c < s->channels; c++) { 217 buf[v] += SHORT_TO_FLOAT(data[ v * s->channels + c]);218 } 219 buf[v] /= (smpl_t)s->channels;217 read_to->data[v] += data[ v * s->channels + c]; 218 } 219 read_to->data[v] /= (smpl_t)s->channels; 220 220 } 221 221 // short read, fill with zeros 222 222 if (loadedPackets < s->block_size) { 223 223 for (v = loadedPackets; v < s->block_size; v++) { 224 buf[v] = 0.;224 read_to->data[v] = 0.; 225 225 } 226 226 } … … 228 228 *read = (uint_t)loadedPackets; 229 229 return; 230 beach:231 *read = 0;232 return;233 230 } 234 231 235 232 void aubio_source_apple_audio_do_multi(aubio_source_apple_audio_t *s, fmat_t * read_to, uint_t * read) { 236 UInt32 c, v, loadedPackets = s->block_size; 237 OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList); 238 if (err) { 239 char_t errorstr[20]; 240 AUBIO_ERROR("source_apple_audio: error while reading %s " 241 "with ExtAudioFileRead (%s)\n", s->path, 242 getPrintableOSStatusError(errorstr, err)); 243 goto beach; 244 } 245 246 short *data = (short*)s->bufferList.mBuffers[0].mData; 247 248 smpl_t **buf = read_to->data; 233 uint_t c, v; 234 UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s); 235 smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData; 249 236 250 237 for (v = 0; v < loadedPackets; v++) { 251 238 for (c = 0; c < read_to->height; c++) { 252 buf[c][v] = SHORT_TO_FLOAT(data[ v * s->channels + c]);239 read_to->data[c][v] = data[ v * s->channels + c]; 253 240 } 254 241 } … … 258 245 for (v = 0; v < loadedPackets; v++) { 259 246 for (c = s->channels; c < read_to->height; c++) { 260 buf[c][v] = SHORT_TO_FLOAT(data[ v * s->channels + (s->channels - 1)]);247 read_to->data[c][v] = data[ v * s->channels + (s->channels - 1)]; 261 248 } 262 249 } … … 266 253 for (v = loadedPackets; v < s->block_size; v++) { 267 254 for (c = 0; c < read_to->height; c++) { 268 buf[c][v] = 0.;255 read_to->data[c][v] = 0.; 269 256 } 270 257 } 271 258 } 259 272 260 *read = (uint_t)loadedPackets; 273 return;274 beach:275 *read = 0;276 261 return; 277 262 } … … 294 279 295 280 void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s){ 281 AUBIO_ASSERT(s); 296 282 aubio_source_apple_audio_close (s); 297 283 if (s->path) AUBIO_FREE(s->path); 298 284 freeAudioBufferList(&s->bufferList); 299 285 AUBIO_FREE(s); 300 return;301 286 } 302 287 … … 324 309 // after a short read, the bufferList size needs to resetted to prepare for a full read 325 310 AudioBufferList *bufferList = &s->bufferList; 326 bufferList->mBuffers[0].mDataByteSize = s->block_size * s->channels * sizeof (s hort);311 bufferList->mBuffers[0].mDataByteSize = s->block_size * s->channels * sizeof (smpl_t); 327 312 // do the actual seek 328 313 err = ExtAudioFileSeek(s->audioFile, resampled_pos);
Note: See TracChangeset
for help on using the changeset viewer.