【问题标题】:Failed to setup audio file in apple sample code "AVCaptureToAudioUnit"在苹果示例代码“AVCaptureToAudioUnit”中设置音频文件失败
【发布时间】:2015-05-19 11:30:31
【问题描述】:

我不熟悉 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”的提取不起作用,但我找不到自己的解决方案。 如果有人知道如何解决这个问题并分享它,我非常感谢。

最好的问候。

杜布里

【问题讨论】:

    标签: ios objective-c xcode core-audio audio-recording


    【解决方案1】:
    AudioStreamBasicDescription: 0 ch,0 Hz,'lpcm' (0x0000000E) 16-bit signed integer
    

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

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

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

    【讨论】:

    • 你好 ruoho!对不起,来晚了。自从您回答以来,我得到了解决方案。似乎与音频设置相关的代码只能用真实设备制作。所以我用真机得到了很好的结果。谢谢!杜布里
    猜你喜欢
    • 2011-03-15
    • 2022-11-02
    • 2010-12-20
    • 1970-01-01
    • 2011-02-04
    • 2019-02-02
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    相关资源
    最近更新 更多