- Timestamp:
- Dec 19, 2018, 2:11:23 PM (6 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:
- 7b5e1a5
- Parents:
- 12e5d89
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/source_apple_audio.c
r12e5d89 rff6d1b6 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); … … 139 137 140 138 AudioStreamBasicDescription clientFormat; 141 propSize = sizeof( clientFormat);139 propSize = sizeof(AudioStreamBasicDescription); 142 140 memset(&clientFormat, 0, sizeof(AudioStreamBasicDescription)); 143 141 clientFormat.mFormatID = kAudioFormatLinearPCM; 144 142 clientFormat.mSampleRate = (Float64)(s->samplerate); 145 clientFormat.mFormatFlags = kAudioFormatFlagIs SignedInteger | kAudioFormatFlagIsPacked;143 clientFormat.mFormatFlags = kAudioFormatFlagIsFloat; 146 144 clientFormat.mChannelsPerFrame = s->channels; 147 clientFormat.mBitsPerChannel = sizeof(s hort) * 8;145 clientFormat.mBitsPerChannel = sizeof(smpl_t) * 8; 148 146 clientFormat.mFramesPerPacket = 1; 149 147 clientFormat.mBytesPerFrame = clientFormat.mBitsPerChannel * clientFormat.mChannelsPerFrame / 8; 150 148 clientFormat.mBytesPerPacket = clientFormat.mFramesPerPacket * clientFormat.mBytesPerFrame; 151 clientFormat.mReserved = 0;152 149 153 150 // set the client format description … … 187 184 // allocate the AudioBufferList 188 185 freeAudioBufferList(&s->bufferList); 189 if (createAu bioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) {186 if (createAudioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) { 190 187 AUBIO_ERR("source_apple_audio: failed creating bufferList\n"); 191 188 goto beach; … … 196 193 } 197 194 198 void aubio_source_apple_audio_do(aubio_source_apple_audio_t *s, fvec_t * read_to, uint_t * read) { 199 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; 200 198 OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList); 201 199 if (err) { … … 204 202 "with ExtAudioFileRead (%s)\n", s->path, 205 203 getPrintableOSStatusError(errorstr, err)); 206 goto beach; 207 } 208 209 short *data = (short*)s->bufferList.mBuffers[0].mData; 210 211 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; 212 213 213 214 for (v = 0; v < loadedPackets; v++) { 214 buf[v] = 0.;215 read_to->data[v] = 0.; 215 216 for (c = 0; c < s->channels; c++) { 216 buf[v] += SHORT_TO_FLOAT(data[ v * s->channels + c]);217 } 218 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; 219 220 } 220 221 // short read, fill with zeros 221 222 if (loadedPackets < s->block_size) { 222 223 for (v = loadedPackets; v < s->block_size; v++) { 223 buf[v] = 0.;224 read_to->data[v] = 0.; 224 225 } 225 226 } … … 227 228 *read = (uint_t)loadedPackets; 228 229 return; 229 beach:230 *read = 0;231 return;232 230 } 233 231 234 232 void aubio_source_apple_audio_do_multi(aubio_source_apple_audio_t *s, fmat_t * read_to, uint_t * read) { 235 UInt32 c, v, loadedPackets = s->block_size; 236 OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList); 237 if (err) { 238 char_t errorstr[20]; 239 AUBIO_ERROR("source_apple_audio: error while reading %s " 240 "with ExtAudioFileRead (%s)\n", s->path, 241 getPrintableOSStatusError(errorstr, err)); 242 goto beach; 243 } 244 245 short *data = (short*)s->bufferList.mBuffers[0].mData; 246 247 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; 248 236 249 237 for (v = 0; v < loadedPackets; v++) { 250 238 for (c = 0; c < read_to->height; c++) { 251 buf[c][v] = SHORT_TO_FLOAT(data[ v * s->channels + c]);239 read_to->data[c][v] = data[ v * s->channels + c]; 252 240 } 253 241 } … … 257 245 for (v = 0; v < loadedPackets; v++) { 258 246 for (c = s->channels; c < read_to->height; c++) { 259 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)]; 260 248 } 261 249 } … … 265 253 for (v = loadedPackets; v < s->block_size; v++) { 266 254 for (c = 0; c < read_to->height; c++) { 267 buf[c][v] = 0.;255 read_to->data[c][v] = 0.; 268 256 } 269 257 } 270 258 } 259 271 260 *read = (uint_t)loadedPackets; 272 return;273 beach:274 *read = 0;275 261 return; 276 262 } … … 323 309 // after a short read, the bufferList size needs to resetted to prepare for a full read 324 310 AudioBufferList *bufferList = &s->bufferList; 325 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); 326 312 // do the actual seek 327 313 err = ExtAudioFileSeek(s->audioFile, resampled_pos);
Note: See TracChangeset
for help on using the changeset viewer.