iOS equalizer by kAudioUnitSubType_NBandEQ

1.7k views Asked by At

I want to implement my equalizer on iOS device, and it seems to be achievable by kAudioUnitSubType_NBandEQ. However, after I set the gain of each band, I heard nothing changed on the sound.

I use the sample code of BandEQDemo(https://github.com/springlo/BandEQDemo)

OSStatus TOAUGraphAddNode(OSType inComponentType, OSType inComponentSubType, AUGraph inGraph, AUNode *outNode)
{
    AudioComponentDescription desc;
    desc.componentType = inComponentType;
    desc.componentSubType = inComponentSubType;
    desc.componentFlags = 0;
    desc.componentFlagsMask = 0;
    desc.componentManufacturer = kAudioUnitManufacturer_Apple;

    return AUGraphAddNode(inGraph, &desc, outNode);
}

TOAUGraphAddNode(kAudioUnitType_Effect,
                 kAudioUnitSubType_NBandEQ,
                 graph,
                 &eqNode);

AUGraphNodeInfo(graph,
                eqNode,
                NULL,
                &equalizerUnit);
// @[ @32, @64, @128, @256, @512, @1025, @2048, @4096, @8192, @16384 ]

Then after I set the gain and check again by these two functions:

- (AudioUnitParameterValue)gainForBandAtPosition:(NSUInteger)bandPosition
{
    AudioUnitParameterValue gain;
    AudioUnitParameterID parameterID = kAUNBandEQParam_Gain + bandPosition;

    TOThrowOnError(AudioUnitGetParameter(equalizerUnit,
                                         parameterID,
                                         kAudioUnitScope_Global,
                                         0,
                                         &gain));

    return gain;
}


- (void)setGain:(AudioUnitParameterValue)gain forBandAtPosition:(NSUInteger)bandPosition
{
    AudioUnitParameterID parameterID = kAUNBandEQParam_Gain + bandPosition;

    TOThrowOnError(AudioUnitSetParameter(equalizerUnit,
                                         parameterID,      
                                         kAudioUnitScope_Global,
                                         0,
                                         gain,
                                         0));
    NSLog(@"After set gain@[%d]->%f", bandPosition, [self gainForBandAtPosition:bandPosition]);
}

When I get the gain value of each band after I set it(-96dB ~ 24dB), it does correspond to the value I set. But I cannot hear any different on the sound.

1

There are 1 answers

3
Milan Đorić On

Hi fellow audio enthusiast!

I am also creating an app with an equaliser feature and have stumbled upon this web page:

http://www.deluge.co/?q=content/coreaudio-iphone-creating-graphic-equalizer

With a little of cross-referencing, I have found out that the code from your Git source lacks some key features. After line 142, additional parameter set up must be made. For example, setNumBands method is not utilised, neither is setBands. Also, make sure to include the bypass setting loop - it really won't work without it! Most importantly, check what pieces of code is lacking in your implementation, based on the ling above.

I am sorry I can't give you more through explanation; I have started to learn Audio Units a few days ago; but your question (as well as the BandEQ project) and the page I stumbled upon have solved some of my problems, so I am trying to help you as well.

Nevertheless, this is an official guide for Audio Units and do study it, as so will I! Good luck!