无法在 Apple 示例代码中设置音频文件 "AVCaptureToAudioUnit"

Failed to setup audio file in apple sample code "AVCaptureToAudioUnit"

我不熟悉 Objective-C 和 audioUnit。

我想制作 iOS 应用程序,它可以通过设备中发出的一些 audioUnit 效果保存来自麦克风的音频信号。 所以现在我正在尝试研究苹果的示例代码"AVCaptureToAudioUnit"

https://developer.apple.com/library/ios/samplecode/AVCaptureToAudioUnit/Introduction/Intro.html (使用 Xcode 6.1 和模拟器 iphone5 构建。)

但它暴露了下面的错误

AudioStreamBasicDescription: 0 ch,0 Hz,'lpcm' (0x0000000E) 16-bit signed integer

2015-03-17 13:44:56.589 AVCaptureToAudioUnit[1462:151210] Failed to setup audio file! (29759)

这些日志是用下面CaptureSessionController.mm的方法写的

- (void)startRecording
{
 if (!self.isRecording) {
    OSErr err = kAudioFileUnspecifiedError;
    @synchronized(self) {
        if (!extAudioFile) {
            /*
             Start recording by creating an ExtAudioFile and configuring it with the same sample rate and
             channel layout as those of the current sample buffer.
            */

            // recording format is the format of the audio file itself
            CAStreamBasicDescription recordingFormat(currentInputASBD.mSampleRate,
                                                     currentInputASBD.mChannelsPerFrame,
                                                     CAStreamBasicDescription::kPCMFormatInt16,
                                                     true);
            recordingFormat.mFormatFlags |= kAudioFormatFlagIsBigEndian;

            NSLog(@"Recording Audio Format:");
            recordingFormat.Print();

            err = ExtAudioFileCreateWithURL(_outputFile,
                                            kAudioFileAIFFType,
                                            &recordingFormat,
                                            currentRecordingChannelLayout,
                                            kAudioFileFlags_EraseFile,
                                            &extAudioFile);
            if (noErr == err)
                // client format is the output format from the delay unit
                err = ExtAudioFileSetProperty(extAudioFile,
                                              kExtAudioFileProperty_ClientDataFormat,
                                              sizeof(graphOutputASBD),
                                              &graphOutputASBD);

            if (noErr != err) {
                if (extAudioFile) ExtAudioFileDispose(extAudioFile);
                extAudioFile = NULL;
            }
        }
    } // @synchronized

    if (noErr == err) {
        self.recording = YES;
        NSLog(@"Recording Started");
    } else {
        NSLog(@"Failed to setup audio file! (%ld)", (long)err);
    }
}
}

好像"currentInputASBD"的提取没有用,但我自己找不到解决办法。 如果有人知道如何解决这个问题并分享它,我非常感谢。

此致。

杜布鲁

AudioStreamBasicDescription: 0 ch,0 Hz,'lpcm' (0x0000000E) 16-bit signed integer

一个问题是您没有指定通道数(参见0 ch)。所以你需要指定它。

您应该会看到类似以下内容:

AudioStreamBasicDescription: 1 ch, 44100 Hz, 'lpcm' (0x0000000E) 16-bit signed integer