Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set kAudioUnitSubType_Distortion

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.

like image 805
Masatatsu Nakamura Avatar asked Sep 02 '12 07:09

Masatatsu Nakamura


1 Answers

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!

like image 85
happy coder Avatar answered Nov 05 '22 13:11

happy coder