通过AUGraph启动和停止麦克风的错误

时间:2014-09-25 14:02:15

标签: ios objective-c audio core-audio

我正在使用AUGraph来访问麦克风。一切似乎在90%的时间都有效,但我常常在AudioOutputUnitStartAudioOutputUnitStop看到崩溃报告。

它们伴随着非常神秘的错误消息

The operation couldn’t be completed. (OSStatus error -66635.)

The operation couldn’t be completed. (OSStatus error -50.)

分别

是否有任何方法可以减少这些操作失败的可能性,或者是仅仅捕获异常并继续前进的指导?

更新w / Sample

- (void)start
{
    dispatch_async(dispatch_get_main_queue(), ^() {
        AudioOutputUnitStart(_unit);
    });
}

- (void)stop
{
    dispatch_async(dispatch_get_main_queue(), ^() {
        AudioOutputUnitStop(_unit);
    });
}

- (void)setup
{  
    AudioComponentDescription inputDescription;
    inputDescription.componentType = kAudioUnitType_Output;
    inputDescription.componentSubType = _useVoiceProcessingIO ? kAudioUnitSubType_VoiceProcessingIO : kAudioUnitSubType_RemoteIO;
    inputDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
    inputDescription.componentFlags = 0;
    inputDescription.componentFlagsMask = 0;

    AudioComponent inputComponent = AudioComponentFindNext(nil, &inputDescription);

    AudioComponentInstanceNew(inputComponent, &_unit)
    AudioComponentCopyName(inputComponent, (CFStringRef *)&_label)

    int enable = 1;
    AudioUnitSetProperty(_unit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, IO_INPUT_BUS, &enable, sizeof(enable)

    AudioStreamBasicDescription format;
    format.mChannelsPerFrame = self.desiredChannels;
    format.mFramesPerPacket = 1;
    format.mBitsPerChannel = SAMPLE_LENGTH * 8;
    format.mBytesPerFrame = (format.mBitsPerChannel / 8) * format.mChannelsPerFrame;
    format.mBytesPerPacket = format.mBytesPerFrame * format.mFramesPerPacket;
    format.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked;
    format.mFormatID = kAudioFormatLinearPCM;
    format.mSampleRate = self.desiredClockRate;
    AudioUnitSetProperty(_unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, IO_INPUT_BUS, &format, sizeof(format)

    int disable = 0;
    AudioUnitSetProperty(_unit, kAudioUnitProperty_ShouldAllocateBuffer, kAudioUnitScope_Output, IO_INPUT_BUS, &disable, sizeof(disable)

    AURenderCallbackStruct callback;
    callback.inputProc = CaptureAudioUnitInputCallback;
    callback.inputProcRefCon = self;
    AudioUnitSetProperty(_unit, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, IO_INPUT_BUS, &callback, sizeof(callback)
    AudioUnitInitialize(_unit)
}

0 个答案:

没有答案