EXC_BAD_ACCESS上ExtAudioFileWriteAsync [英] EXC_BAD_ACCESS on ExtAudioFileWriteAsync
问题描述
我添加了以下code。在话筒/线路年底在音频渲染回调。
I have added the following code at the end of the Mic / Line In Audio Rendering Callback.
但应用程序保持与EXC_BAD_ACCESS崩溃上:
But the app keeps crashing with EXC_BAD_ACCESS on :
err = ExtAudioFileWriteAsync(mOutputAudioFile, inNumberFrames, ioData);
在code的其余部分如下:
The rest of the code is as follows :
ExtAudioFileRef mOutputAudioFile;
AudioFileID mAfid;
NSLog(@"Writing output to file ....");
NSArray *dirPaths;
NSString *docsDir;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSLog(@"docDir = %@", docsDir);
NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"sound.caf"];
NSURL *inPath = [NSURL fileURLWithPath:soundFilePath];
NSLog(@"Output file path is : %@", inPath);
AudioStreamBasicDescription mStreamFormat;
mStreamFormat.mChannelsPerFrame = 1;
mStreamFormat.mSampleRate = 44100.00;
mStreamFormat.mFormatID = kAudioFormatLinearPCM;
mStreamFormat.mFormatFlags = kAudioFormatFlagIsBigEndian | kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
mStreamFormat.mBitsPerChannel = 16;
mStreamFormat.mBytesPerFrame = 2;
mStreamFormat.mFramesPerPacket = 1;
mStreamFormat.mBytesPerPacket = 2;
mStreamFormat.mReserved = 0;
err = AudioFileCreateWithURL((CFURLRef)inPath, kAudioFileCAFType, &mStreamFormat, kAudioFileFlags_EraseFile, &mAfid);
if (err != noErr) {
NSLog(@"ERROR : Audio file could not be created !! %d", (int)err);
}
err = ExtAudioFileWrapAudioFileID(mAfid, true, &mOutputAudioFile);
err = ExtAudioFileSetProperty(mOutputAudioFile, kExtAudioFileProperty_ClientDataFormat, sizeof(AudioStreamBasicDescription), &mStreamFormat);
if (ioData) {
err = ExtAudioFileWriteAsync(mOutputAudioFile, inNumberFrames, ioData);
if (err != noErr) {
NSLog(@"ERROR : Audio file could not be written !! %d", (int)err);
}
}
else {
NSLog(@"No ioData found");
}
NSLog(@"Done writing output to file ....");
我已经试过几乎与此一切。我将非常感激,如果有人可以帮助我解决这个问题。谢谢!
I have tried almost everything with this. I would be extremely thankful if somebody could help me resolve it. Thanks !
更新1:
如果我用ExtAudioFileWrite代替ExtAudioFileWriteAsync,应用程序不会崩溃,但返回错误-50为ExtAudioFileWrite。
If I use ExtAudioFileWrite instead of ExtAudioFileWriteAsync, the app doesn't crash, but returns error -50 for ExtAudioFileWrite.
我仍然不知道发生了什么与它发生。在这方面的任何帮助是非常AP preciated。
I still have no idea what's happening with it. Any help in this regard is much appreciated.
感谢。
推荐答案
样品code张贴在这里的答案回答了我所有的问题:
The sample code posted in the answer here answered all my questions :
<一个href=\"http://stackoverflow.com/questions/8615358/can-anybody-help-me-in-recording-iphone-output-sound-through-audio-unit\">Can任何人帮助我通过音频单元
非常感谢大家的帮助。
这篇关于EXC_BAD_ACCESS上ExtAudioFileWriteAsync的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!