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?

Thanks
Cheers
Sean

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.

e.g.

Dim eqNode as new AVAudioUnitEQ(1)

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

audioEngine.attachNode(eqNode)

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>
Thanks

EQnode.reset
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

After taking a break and relooking at this problem, I solved it.

The Bandwidth (BW) for the parametric filters is defined in term of octaves (0.05 to 5) – not frequency. So when I was entering BW = 500 Hz this was actually 500 octaves (the limit for the parameter 5) which explains the wide band effect when using parametric filters.

1 Like