Creating an equalizer/filter using AVFoundationMSB

I am trying to use the AVFoundationMSB to create a parametric equalizer to filter audio – or even one filter.

I looked through the audio-related code examples provided by MSB but couldn’t find any examples that use the classes to do this (e.g. AVAudioUnitEQFilterParametersMBS).

Has anyone written working code that equalizes audio they are willing to share as an example how to use this class?


Well, sorry for missing this topic earlier.

For AVAudioUnitEQMBS class, you would create an instance, add it to the AVAudioEngineMBS object for the session. Then you may query the AVAudioUnitEQFilterParametersMBS objects from AVAudioUnitEQMBS with the bands method and change properties.


Dim eqNode as new AVAudioUnitEQ(1)

eqNode.bands(0).filterType = AVAudioUnitEQFilterParametersMBS.FilterTypeLowPass
eqNode.bands(0).frequency = 20
eqNode.bands(0).byPass = false


Thank you for this example.

The code runs (after adding “MSB” to the class AVAudioUnitEQ(1) up to the next line where I get the following exception:

Window1.Open, line 18
Too many arguments: got 1, expected only 0.
eqNode.bands(0).filterType = AVAudioUnitEQFilterParametersMBS.FilterTypeLowPass

Window1.Open, line 18
Type “Int32” has no member named “filterType”
eqNode.bands(0).filterType = AVAudioUnitEQFilterParametersMBS.FilterTypeLowPass

sorry, you may need to write it differently:

dim bands() as AVAudioUnitEQFilterParametersMBS = eqNode.bands
bands(0).filterType = AVAudioUnitEQFilterParametersMBS.FilterTypeLowPass

Because Xojo doesn’t allow to directly look into the array returned by a function.

Thanks. This helped. I can now create and modify different types of filters, listen to their effect on pink noise, and measure them on a real-time analyzer to verify they are working as expected.

The one exception is the Parametric filter which is nothing more than a wide-band volume control affecting the entire spectrum when you would expect a narrow peak or dip (e,g, freq = 1000, BW = 500, gain = -5 produces the black curve below when it should be a narrow dip centered at 1kHz)
This happens with the following code: Any ideas why it’s not working as expected>

dim bands() as AVAudioUnitEQFilterParametersMBS = EQNode.Bands

Dim Freq as Double
Dim BW as Double
Dim Gain as Double

Freq = Textfield1.text.ToDouble
BW = TextField2.Text.ToDouble
Gain = TextField3.Text.ToDouble

Bands(0).filterType =AVAudioUnitEQFilterParametersMBS.FilterTypeParametric
Bands(0).gain = Gain
Bands(0).bandwidth = BW
Bands(0).frequency = Freq
Bands(0).byPass = False