gpt4 book ai didi

objective-c - ExtAudioFileWriteAsync上的EXC_BAD_ACCESS

转载 作者:行者123 更新时间:2023-12-02 23:59:40 25 4
gpt4 key购买 nike

我在“麦克风/线路输入音频渲染回调”的末尾添加了以下代码。

但是,该应用始终会崩溃,并带有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,则该应用不会崩溃,但ExtAudioFileWrite返回错误-50。

我仍然不知道这是怎么回事。非常感谢在这方面的任何帮助。

谢谢。

最佳答案

答案中张贴的示例代码回答了我所有的问题:

Can anybody help me in recording iPhone output sound through Audio Unit

非常感谢大家的帮助。

关于objective-c - ExtAudioFileWriteAsync上的EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9278147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com