Low pass filter on audio?

Hi.
So I’ve seen in the aud documentation that there are a wide range of things to use with audio. One thing I’d want to use is the low pass filter. Now I’m not sure how to apply that filter with Python, but I assume it wouldn’t be a large script to do.

Anyone willing to help?

Thanks.

You’re right, it’s pretty easy to apply a lowpass filter to a sound using aud. You basically load a sound file into memory, apply the filters then play it. Unfortunatelly, you can’t change the filter in realtime, only before playing the sound, but it’s still possible. Example script and working example file provided below.

For other pre-precessing effects, see the reference from the aud.Factory. For realtime attributes, see aud.Handle.

import bge
import aud

from bge.logic import expandPath

def main(cont):
	
	# Objects
	own = cont.owner
	
	# Sensors
	sensor = cont.sensors[0]
	
	### INIT PROCESSING ###
	if sensor.positive:
		
		# Sound file expanded path
		path = expandPath("//whitenoise.ogg")
		
		# Creates an audio factory in memory, then applies
		# lowpass / hipass based on own properties
		factory = aud.Factory(path) \
					.lowpass(own['lowpass']) \
					.highpass(own['hipass'])
		
		# Plays the resulting factory
		aud.device().play(factory)

ex_hipass_lowpass.zip (119.7 KB)

3 Likes

Sorry for the late reply. I’m surprised it works, but having it work in realtime is what I was looking for.

You say it’s still possible, do you mean that it’s very difficult to do?

Thank you for taking the time to do the script anyway and explain it.

you need to get the current time of the sound -> set the stuff -> play the sound again at the same time it stopped

Nice, thanks for this clean example. I would like to leave here, that the use of the expression controller is also a nice way of limiting the parameter ranges.

1 Like