Applying sound filters

i was wondering if its possible to apply sound filters (also working with FlxSound)

like in this example:

I believe you have to write your own logic to manipulate raw audio data with whatever effects/filters you have in mind, and then feed the data to OpenFL/Lime sound playback. although it’s not overly difficult, it think it might be a bit complex/complicated if you don’t understand how audio samples are being processed in relevant software (digital signal processing, DSP)

afaik OpenFL/Lime does not have audio filters/effects implemented (maybe there’s something available on haxelib), but Heaps has an Effect package to manipulate audio, which might be a good starting point. The effect demonstrated in your example is I believe a LowPass filter which is already available in Heaps.

Interactive demo: (look for the LowPass slider while playing audio)

but openal has some kind of lowpass filter

and i can already change the pitch with this

but that doesnt work with the lowpass (i tried both sourcef and sourcei)

Try this. I tested it on mac c++ and it looks like it’s working; // sound is playing
@:privateAccess var a = sound.__buffer; // get AudioBuffer
@:privateAccess var b = a.__srcBuffer; // get ALBuffer
// I believe it's the FlxG sound source handle in your code, so you don't need this if you already have this handle available

var af = AL.createFilter(); // create AudioFilter
AL.filteri( af, AL.FILTER_TYPE, AL.FILTER_LOWPASS ); // set filter type
AL.filterf( af, AL.LOWPASS_GAIN, 1 ); // set gain
AL.filterf( af, AL.LOWPASS_GAINHF, .0134 ); // set gainhf
AL.sourcei( b, AL.DIRECT_FILTER, af ); // apply filter to source (handle)

So basically you need to create an ALFilter, set its type, define its parameters (GAIN and GAINHF) and apply this filter to source.

Experiment with GAIN and GAINHF values, because too low GAINHF caused too low volume so I had to increase GAIN. You’ll see.

Let me know if it works

Edit: I wasn’t aware of OpenAL implementation in Lime, but I guess the guys get another thumbs up from me

1 Like