I make some effects to audio, using avaudioplayernode. And then i want to save the result. I try to do like this:
Output = engine.outputNode;
AudioStreamBasicDescription asbd;
memset(&asbd, 0, sizeof(asbd));
asbd.mSampleRate = SAMPLE_RATE;
asbd.mFormatID = kAudioFormatLinearPCM;
asbd.mFormatFlags = kAudioFormatFlagIsBigEndian | kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
asbd.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
asbd.mBitsPerChannel = 16;
asbd.mChannelsPerFrame = 2;
asbd.mFramesPerPacket = 1;
asbd.mBytesPerFrame = 4;
asbd.mBytesPerPacket = 4;
AudioFileID OutputFile;
CFStringRef inputFile = (__bridge CFStringRef)(save);
CFURLRef inputFileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, inputFile, kCFURLPOSIXPathStyle,false);
CheckError (AudioFileCreateWithURL(inputFileURL, kAudioFileWAVEType, &asbd, kAudioFileFlags_EraseFile, &OutputFile), "err");
CFRelease(inputFileURL);
float y = 6871947*16;//audio.length;
myData1 = [NSData dataWithBytesNoCopy:(__bridge void * _Nonnull)(Output) length:y freeWhenDone:NO];
NSUInteger length1 = [myData1 length]-4096;
UInt32 lgt = (UInt32) length1/4;
UInt16 *cdata = (UInt16*) malloc (length1);
[myData1 getBytes:(void*)cdata range:NSMakeRange(0, length1)];
CheckError ( AudioFileWritePackets(OutputFile, TRUE, lgt, NULL, 0, &lgt, cdata), "err");
AudioFileClose(OutputFile);
But saving file is wrong. I think that set Output to NSData is wrong step. But I don't know another way. And try to do like this. How can i save new file?