36

我正在尝试编写一个添加音效的 iOS 应用程序。我正在尝试在 auconverter 和 remoteIO 之间放置一个效果音频单元(例如,失真和混响)。设置好所说的AU后,没有声音。

    NewAUGraph(&mAuGraph);
    AUGraphOpen(mAuGraph);

    AUNode remoteOutputNode, converterNode, effectNode;
    AudioUnit remoteIOAudioUnit, converterUnit, effectUnit;

    AudioComponentDescription cd;

    cd.componentManufacturer = kAudioUnitManufacturer_Apple;
    cd.componentFlags = cd.componentFlagsMask = 0;

    // remote io
    cd.componentType = kAudioUnitType_Output;
    cd.componentSubType = kAudioUnitSubType_RemoteIO;
    AUGraphAddNode(mAuGraph, &cd, &remoteOutputNode);

    // converter
    cd.componentType = kAudioUnitType_FormatConverter;
    cd.componentSubType = kAudioUnitSubType_AUConverter;
    AUGraphAddNode(mAuGraph, &cd, &converterNode);

    // ipodeq
    cd.componentType = kAudioUnitType_Effect;
    cd.componentSubType = kAudioUnitSubType_Distortion;
    AUGraphAddNode(mAuGraph, &cd, &effectNode);

    //callback
    AURenderCallbackStruct callbackStruct;
    callbackStruct.inputProc = renderCallback;
    callbackStruct.inputProcRefCon = &audioDataInfo;
    AUGraphSetNodeInputCallback(mAuGraph, converterNode, 0, &callbackStruct);

    // set audio unit asbd
    AudioStreamBasicDescription audioFormat = AUCanonicalASBD(44100.0, audioDataInfo.inputFormat.mChannelsPerFrame);
    AUGraphNodeInfo(mAuGraph, converterNode, NULL, &converterUnit);

    AudioUnitSetProperty(converterUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &audioDataInfo.inputFormat, sizeof(AudioStreamBasicDescription));
    AudioUnitSetProperty(converterUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &audioFormat, sizeof(AudioStreamBasicDescription));

    // get effect unit
    AUGraphNodeInfo(mAuGraph, effectNode, NULL, &effectUnit);

    // set effect unit asbd
    AudioUnitSetProperty(effectUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &audioFormat, sizeof(AudioStreamBasicDescription));
    AudioUnitSetProperty(effectUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &audioFormat, sizeof(audioFormat));

    // set remoteio unit asbd
    AUGraphNodeInfo(mAuGraph, remoteOutputNode, 0, &remoteIOAudioUnit);
    AudioUnitSetProperty(remoteIOAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &audioFormat, sizeof(AudioStreamBasicDescription));

    AUGraphConnectNodeInput(mAuGraph, converterNode, 0, effectNode, 0);
    AUGraphConnectNodeInput(mAuGraph, effectNode, 0, remoteOutputNode, 0);

    AUGraphInitialize(mAuGraph);

AUGraphConnectNodeInput部分,如果没有

AUGraphConnectNodeInput(mAuGraph, converterNode, 0, effectNode, 0);
AUGraphConnectNodeInput(mAuGraph, effectNode, 0, remoteOutputNode, 0);

AUGraphConnectNodeInput(mAuGraph, converterNode, 0, remoteOutputNode, 0);

它产生没有效果的声音。

4

1 回答 1

1

诚然,我之前对您的问题一无所知,所以我稍微查看了您的代码,并查看了 Mac 开发人员的CoreAudioOverview.pdf,这让我无所适从。我没有在您的代码中看到任何太偷偷摸摸的事情。它看起来很紧,但我确实想知道这些行:

// set effect unit asbd
AudioUnitSetProperty(effectUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &audioFormat, sizeof(AudioStreamBasicDescription));
AudioUnitSetProperty(effectUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &audioFormat, sizeof(audioFormat));

最特别的是为什么这里有两行。你不应该只有第一行吗?

只是一个想法。

如果那没有价值,那么,您是否检查过以确保您的音频图都已正确连接。你也可以尝试不同的效果,看看是否有效?

在这个项目上取得了很好的成功。干杯!

于 2013-02-06T15:22:57.080 回答