首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未能在苹果示例代码"AVCaptureToAudioUnit“中设置音频文件

未能在苹果示例代码"AVCaptureToAudioUnit“中设置音频文件
EN

Stack Overflow用户
提问于 2015-03-17 06:00:36
回答 1查看 1.6K关注 0票数 0

我不熟悉目标C和audioUnit。

我想要做的iOS应用程序,可以保存声音信号从麦克风通过一些audioUnit效果,在设备中的声音。因此,现在我正在尝试研究苹果的示例代码"AVCaptureToAudioUnit“

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

但是它暴露了下面的错误

代码语言:javascript
复制
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方法编写的

代码语言:javascript
复制
- (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“的提取似乎不起作用,但我无法为自己找到解决方案。如果有人知道如何解决这个问题,并分享它,我非常感谢。

诚挚的问候。

杜布玉

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-19 21:00:30

代码语言:javascript
复制
AudioStreamBasicDescription: 0 ch,0 Hz,'lpcm' (0x0000000E) 16-bit signed integer

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

您应该看到类似于:

代码语言:javascript
复制
AudioStreamBasicDescription: 1 ch, 44100 Hz, 'lpcm' (0x0000000E) 16-bit signed integer
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29092279

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档