I've used ExtAudioFileCreateWithURL and ExtAudioFileWrite from the AudioToolBox framework to save my samples to a file. But now I need to save it to an NSFileWrapper since I'm now using NSDocument:
- (NSFileWrapper *)fileWrapperOfType:(NSString *)typeName error:(NSError **)outError
Is there any way to use the ExtAudioFileXXX functions with an NSMutableData object so I can use NSFileWrapper initRegularFileWithContents:(NSData*)contents
method?
Stripped down code for saving to file (which works):
AudioStreamBasicDescription file_desc;
FillOutASBDForLPCM(file_desc, _sample_rate, _channel_count, 32, 32, true, false);
OSStatus rv = ExtAudioFileCreateWithURL(url, kAudioFileWAVEType, &file_desc, NULL, kAudioFileFlags_EraseFile, &fout);
if (rv == noErr){
int buff_size = sizeof(AudioBufferList) + sizeof(AudioBuffer);
AudioBufferList* bufferList = (AudioBufferList*)malloc(buff_size);
bufferList->mNumberBuffers = 1;
bufferList->mBuffers[0].mData = _samples;
bufferList->mBuffers[0].mNumberChannels = _channel_count;
bufferList->mBuffers[0].mDataByteSize = _channel_count * _frame_count * sizeof(float);
ExtAudioFileWrite(fout, _frame_count, bufferList);
free(bufferList);
ExtAudioFileDispose(fout);
}