AUGraphAddNode -10862

两盒软妹~` 提交于 2019-12-12 02:54:28

问题


I want to implement a Audio Unit pattern,I/O Pass Through.My code below

    OSStatus result = noErr;
    result = NewAUGraph(&audioGraph);
    if (noErr != result) {[self printErrorMessage: @"NewAUGraph" withStatus: result]; return;}

    // 2.add AUNode
    AUNode inputNode;
    AUNode outputNode;

    // client format audio goes into the mixer
    clientFromat.SetCanonical(1, true);
    clientFromat.mSampleRate = kGraphSampleRate;
    clientFromat.Print();

    CAComponentDescription input_desc(kAudioUnitType_Output,kAudioUnitSubType_RemoteIO,kAudioUnitManufacturer_Apple);
    CAComponentDescription output_desc(kAudioUnitType_Output,kAudioUnitSubType_RemoteIO,kAudioUnitManufacturer_Apple);

    result = AUGraphAddNode(audioGraph, &input_desc, &inputNode);
    if (noErr != result) {[self printErrorMessage: @"AUGraphNewNode failed for Mixer unit" withStatus: result]; return;}

    result = AUGraphAddNode(audioGraph, &output_desc, &outputNode); // this line crash
    if (noErr != result) {[self printErrorMessage: @"AUGraphNewNode failed for Mixer unit" withStatus: result]; return;}

result = AUGraphAddNode(audioGraph, &output_desc, &outputNode); this line crashed.Why? How to sends incoming audio directly to the output hardware without render call function ?


回答1:


I know -10862 mean is that input_desc and out_desc are all kAudioUnit_Output, AUGraph can have only one output node. And the correct code below here.

  OSStatus result = noErr;
    result = NewAUGraph(&audioGraph);
    if (noErr != result) {[self printErrorMessage: @"NewAUGraph" withStatus: result]; return;}

    // 2.add AUNode
    AUNode ioNode;

    // client format audio goes into the mixer
    clientFromat.SetCanonical(1, true);
    clientFromat.mSampleRate = kGraphSampleRate;
    clientFromat.Print();

    CAComponentDescription io_desc(kAudioUnitType_Output,kAudioUnitSubType_RemoteIO,kAudioUnitManufacturer_Apple);

    result = AUGraphAddNode(audioGraph, &io_desc, &ioNode);
    if (noErr != result) {[self printErrorMessage: @"AUGraphNewNode failed for Mixer unit" withStatus: result]; return;}

    // 3.open augraphic
    result = AUGraphOpen(audioGraph);
    if (noErr != result) {[self printErrorMessage: @"AUGraphOpen" withStatus: result]; return;}

    // 4.get audio unit instance from nodes
    result = AUGraphNodeInfo(audioGraph, ioNode, NULL, &ioUnit);
    if (result) { printf("AUGraphNodeInfo result %ld %08X %4.4s\n", result, (unsigned int)result, (char*)&result); return; }

    // 5. set audio unit property
    CAStreamBasicDescription outputFormat;
    // output format
    outputFormat.SetAUCanonical(1, false);
    outputFormat.mSampleRate = kGraphSampleRate;
    outputFormat.Print();

    AudioUnitElement inputBus = 1;
    UInt32 enableInput = 1;
    result = AudioUnitSetProperty(ioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, inputBus, &enableInput, sizeof(enableInput));

    // 6.connect input->eq->output node        
    result = AUGraphConnectNodeInput(audioGraph, ioNode, 1,ioNode, 0);
    if (result) { printf("AUGraphConnectNodeInput result %lu %4.4s\n", result, (char*)&result); return; }


    // 7. initialize graphic
    result = AUGraphInitialize(audioGraph);
    if (result) { printf("AUGraphInitialize result %ld %08X %4.4s\n", result, (unsigned int)result, (char*)&result); return; }
    CAShow(audioGraph);


来源:https://stackoverflow.com/questions/36325291/augraphaddnode-10862

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!