无法通过2个渲染回调对AUGraphStart进行简单的语音处理I / O.

时间:2015-06-15 04:58:05

标签: ios objective-c core-audio audiounit

我目前只有一个语音处理I / O设置了音频图表。输入和输出总线都有渲染回调,并且它们适当的AudioStreamBasicDescription应用于总线的内向两侧。

所以我的音频图设置如此

输入

  • 用户的语音 - >麦克风 - >在输入回拨中通过网络发送pcm帧。

输出

  • network - > TPCircularBuffer ....然后通过回调将其拉到ioUnit的输出端。

现在每当我尝试启动图表时,我都会kAudioFormatUnsupportedDataFormatError。从搜索周围,这个错误弹出,因为我试图写一个无效的文件格式。但正如你在上面看到的,我不是在写任何文件?什么给出了什么?我猜测错误描述,AudioStreamBasicDescription有问题,但在我设置它时不会给我一个错误吗?

这是我的流设置方式。这两个函数都返回noErr。

- (BOOL)setUpStreamFormat:(NSError **)error
{
    UInt32 bytesPerSample = sizeof(SInt16);
    double sampleRate = [AVAudioSession sharedInstance].sampleRate;

    self.currentAudioSampleRate = sampleRate;

    AudioStreamBasicDescription asbd = {0};
    asbd.mSampleRate = sampleRate;
    asbd.mFormatID = kAudioFormatLinearPCM;
    asbd.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger;
    asbd.mChannelsPerFrame = 2;
    asbd.mBytesPerFrame = bytesPerSample;
    asbd.mBitsPerChannel = 8 * bytesPerSample;
    asbd.mFramesPerPacket = 1;
    asbd.mBytesPerPacket = bytesPerSample;

    OSStatus status = AudioUnitSetProperty(self.ioUnit,
                                            kAudioUnitProperty_StreamFormat,
                                            kAudioUnitScope_Output,
                                            kInputBus,
                                            &asbd,
                                            sizeof(asbd));
    if (status != noErr) {
        [self fillError:error
               withCode:status
            description:@"Stream Format"
          failureReason:@"Failed to setup input stream format"];
        return NO;
    }

    status = AudioUnitSetProperty(self.ioUnit,
                                            kAudioUnitProperty_StreamFormat,
                                            kAudioUnitScope_Input,
                                            kOutputBus,
                                            &asbd,
                                            sizeof(asbd));
    if (status != noErr) {
        [self fillError:error
               withCode:status
            description:@"Stream Format"
          failureReason:@"Failed to setup output stream format"];
        return NO;
    }
    return YES;
}

1 个答案:

答案 0 :(得分:0)

我找到了问题的答案。显然我设置的ABSD是不正确的。格式应该如下:

06-15 21:11:09.253    4063-4063/com.tophatter E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.tophatter, PID: 4063
java.lang.NullPointerException
        at android.support.v7.widget.SuggestionsAdapter.newView(SuggestionsAdapter.java:249)
        at android.support.v7.widget.SuggestionsAdapter.getView(SuggestionsAdapter.java:453)
        at android.widget.AbsListView.obtainView(AbsListView.java:2255)
        at android.widget.ListPopupWindow$DropDownListView.obtainView(ListPopupWindow.java:1585)
        at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
        at android.widget.ListPopupWindow.buildDropDown(ListPopupWindow.java:1167)
        at android.widget.ListPopupWindow.show(ListPopupWindow.java:554)
        at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1096)
        at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:971)
        at android.widget.AutoCompleteTextView.onFilterComplete(AutoCompleteTextView.java:953)
        at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:285)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5001)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
        at dalvik.system.NativeStart.main(Native Method)