How to blur music and sound effects underwater?

I would like to make it so when a sound plays underwater, it will be muffled, like how many games like Banjo-Kazooie do it. Inversely, if the player is walking in a cave, the sounds created echo.

Can these sound enhancements be done without relying on hundreds of sound files?

interesting subject . For instance, there’s only the “volume” and the “pitch” you can tune with upbge sound actuator (well some distance based stuff which is related to the volume anyway). But for sure, it’s all about applying +or- dB for each sound frequencies. It’s a transformation they call “filter”

(With “denoising” you can decompose a sound into 2 that you should be theoretically be able to sum them back to get the original sound)

Also, upbge use this sound library . https://audaspace.github.io/group__fx.html
https://docs.blender.org/api/2.79b/aud.html

If you look at the doc, there’s 3 classes : Device, Factory (about creating your sound as a playable object), Handle (play the “factory” object)

docs.blender.org/api/2.79b/aud.html#aud.Device
docs.blender.org/api/2.79b/aud.html#aud.Factory
docs.blender.org/api/2.79b/aud.html#aud.Handle (the sound actuator covers the “Handle”)

When you look at the class Factory there’s some interesting stuff

  • fadein(start, length)
  • fadeout(start, length)
  • filter(b, a = (1))
  • highpass(frequency, Q=0.5)
  • lowpass(frequency, Q=0.5)
  • mix(factory)
  • etc

so with that Factory functions you gonna create sound object, out of a sound file, and ready to be played . And so, it’s not something you are going to exe each frame :open_mouth: .

(Please, post feed-back for the sake of upbge learning community)

1 Like

Here’s is a try to use Logic brick with Sound and apply a lowpass filter or the IIR filter to the sound.
It’s not as complicated as doing all with AUD.
filter.blend (639.2 KB)

Space = original Sound
L = lowpass filter
F = IIR filter

I have no clue how to use the IIR filter. Just took some filter coefficients from here:

import bge

cont = bge.logic.getCurrentController()
own = cont.owner

act = cont.actuators["Sound"]

SPACE = cont.sensors["Space"]
Key_L = cont.sensors["Key_L"]
Key_F = cont.sensors["Key_F"]


if 'original_sound' not in own:
    own['original_sound']=act.sound

if SPACE.positive:
    act.sound=own['original_sound']
    
if Key_L.positive:
    act.sound=own['original_sound'].lowpass(800,0.2) 

if Key_F.positive:
    a=[0.00020298, 0.0004059599, 0.00020298]
    b=[1.0126964558, -1.9991880801, 0.9873035442]
    act.sound=own['original_sound'].filter(a,b)

	#filter coefficients from:
	# https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Using_IIR_filters	   

cont.activate(act)

AUD in UPBGE 0.3 has more possibilities like ADSR which could be useful for echoes I suppose.

1 Like

@musikai i was not asking