36

I'm trying to write an iOS app that adds sound effects. I'm trying to put an effect audio unit (ex, distortion and reverb) inbetween the auconverter and remoteIO. After setting up said AU, there is no sound.

    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);

in AUGraphConnectNodeInput section, if not

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

but

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

it produces a sound without effects.

Ivaylo Slavov
  • 8,839
  • 12
  • 65
  • 108
  • Are you checking the return value when you set the distortion unit's stream format? I've found effects audio units to be extremely picky about which formats they'll accept. – Art Gillespie Feb 06 '13 at 17:14
  • Does the provided answer help you? That is if this is still an issue. Otherwise provide the solution yourself below and accept it. Thanks! – Josiah Feb 26 '13 at 01:07

1 Answers1

1

Admittedly, I didn't know anything about your issue before, so I did a little bit of looking at your code, and at Mac Developer's CoreAudioOverview.pdf which led me all over the place. I didn't see anything too sneaky going on in your code. It looks quite tight, but I did wonder about these lines:

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

Most particulalry why there are two lines here. Should you not just have the first line?

Just a thought.

If that is of no value, then, have you checked to make sure that your audio graph is all connected properly. And also can you try a different effect and see if that works?

Good success on this project. CHEERS!

happy coder
  • 1,517
  • 1
  • 14
  • 29