Changes in src/io/sink_apple_audio.c [7b5e1a5:cf387e3]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/io/sink_apple_audio.c
r7b5e1a5 rcf387e3 32 32 #include <AudioToolbox/AudioToolbox.h> 33 33 34 extern int createAudioBufferList(AudioBufferList *bufferList, int channels, int segmentSize); 34 #define FLOAT_TO_SHORT(x) (short)(x * 32768) 35 36 extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize); 35 37 extern void freeAudioBufferList(AudioBufferList *bufferList); 36 38 extern CFURLRef createURLFromPath(const char * path); … … 75 77 return s; 76 78 } 77 78 79 // invalid samplerate given, abort 79 80 if (aubio_io_validate_samplerate("sink_apple_audio", s->path, samplerate)) { … … 150 151 CFURLRef fileURL = createURLFromPath(s->path); 151 152 bool overwrite = true; 152 153 // set the in-memory format154 AudioStreamBasicDescription inputFormat;155 memset(&inputFormat, 0, sizeof(AudioStreamBasicDescription));156 inputFormat.mFormatID = kAudioFormatLinearPCM;157 inputFormat.mSampleRate = (Float64)(s->samplerate);158 inputFormat.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked;159 inputFormat.mChannelsPerFrame = s->channels;160 inputFormat.mBitsPerChannel = sizeof(smpl_t) * 8;161 inputFormat.mFramesPerPacket = 1;162 inputFormat.mBytesPerFrame = inputFormat.mBitsPerChannel * inputFormat.mChannelsPerFrame / 8;163 inputFormat.mBytesPerPacket = inputFormat.mFramesPerPacket * inputFormat.mBytesPerFrame;164 153 OSStatus err = noErr; 165 154 err = ExtAudioFileCreateWithURL(fileURL, fileType, &clientFormat, NULL, … … 173 162 goto beach; 174 163 } 175 176 err = ExtAudioFileSetProperty(s->audioFile, 177 kExtAudioFileProperty_ClientDataFormat, 178 sizeof(AudioStreamBasicDescription), &inputFormat); 179 if (err) { 180 char_t errorstr[20]; 181 AUBIO_ERR("sink_apple_audio: error when trying to set output format on %s " 182 "(%s)\n", s->path, getPrintableOSStatusError(errorstr, err)); 183 goto beach; 184 } 185 186 if (createAudioBufferList(&s->bufferList, s->channels, s->max_frames * s->channels)) { 164 if (createAubioBufferList(&s->bufferList, s->channels, s->max_frames * s->channels)) { 187 165 AUBIO_ERR("sink_apple_audio: error when creating buffer list for %s, " 188 166 "out of memory? \n", s->path); … … 197 175 void aubio_sink_apple_audio_do(aubio_sink_apple_audio_t * s, fvec_t * write_data, uint_t write) { 198 176 UInt32 c, v; 199 s mpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;177 short *data = (short*)s->bufferList.mBuffers[0].mData; 200 178 uint_t length = aubio_sink_validate_input_length("sink_apple_audio", s->path, 201 179 s->max_frames, write_data->length, write); … … 203 181 for (c = 0; c < s->channels; c++) { 204 182 for (v = 0; v < length; v++) { 205 data[v * s->channels + c] = write_data->data[v];183 data[v * s->channels + c] = FLOAT_TO_SHORT(write_data->data[v]); 206 184 } 207 185 } … … 212 190 void aubio_sink_apple_audio_do_multi(aubio_sink_apple_audio_t * s, fmat_t * write_data, uint_t write) { 213 191 UInt32 c, v; 214 s mpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;192 short *data = (short*)s->bufferList.mBuffers[0].mData; 215 193 uint_t channels = aubio_sink_validate_input_channels("sink_apple_audio", 216 194 s->path, s->channels, write_data->height); … … 220 198 for (c = 0; c < channels; c++) { 221 199 for (v = 0; v < length; v++) { 222 data[v * s->channels + c] = write_data->data[c][v];200 data[v * s->channels + c] = FLOAT_TO_SHORT(write_data->data[c][v]); 223 201 } 224 202 } … … 229 207 void aubio_sink_apple_audio_write(aubio_sink_apple_audio_t *s, uint_t write) { 230 208 OSStatus err = noErr; 231 // set mDataByteSize to match the number of frames to be written232 // see https://www.mail-archive.com/coreaudio-api@lists.apple.com/msg01109.html233 s->bufferList.mBuffers[0].mDataByteSize = write * s->channels234 * sizeof(smpl_t);235 209 if (s->async) { 236 210 err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList);
Note: See TracChangeset
for help on using the changeset viewer.