我在Mic/Line In音頻渲染回調的末尾添加了以下代碼。ExtAudioFileWriteAsync上的EXC_BAD_ACCESS
,但應用程序保持與EXC_BAD_ACCESS關於崩潰:
err = ExtAudioFileWriteAsync(mOutputAudioFile, inNumberFrames, ioData);
的其餘代碼如下:
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 ....");
我已經試過幾乎與此一切。如果有人能幫我解決這個問題,我將非常感激。謝謝 !
更新1:
如果我使用ExtAudioFileWrite代替ExtAudioFileWriteAsync,應用程序不會崩潰,但返回錯誤-50的ExtAudioFileWrite。
我仍然不知道它發生了什麼。任何在這方面的幫助,非常感謝。
謝謝。
控制檯的整個錯誤消息是什麼? – zaph 2012-02-14 14:01:50
您之前沒有查看通話中的錯誤,也許如果您檢查返回值,您將獲得所需的信息。另外,如何定義以下內容:inNumberFrames,ioData – MByD 2012-02-14 14:03:49
@CocoaFu控制檯中沒有消息。這是可悲的一部分。它只說: [切換到進程6191線程0x18203] [切換到進程6191線程0x18203] 當前語言:auto;目前objective-c – Myxtic 2012-02-14 14:08:55