AudioStream2D attenuation/max distance/volume db not working?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By kozaluss


I am using Godot 3.0.6.

I am trying to use AudioStream2D.
And I can not get the volume_db, attenuation and max distance to work.
Pitch scale works perfectly, but those other properties have completely no effect - audio plays with the same volume no matter the position - tho L-R position is correct.

What may be the cause? :confused: I googled this but there is no info anywhere.

I want to have positional audio so that the volume gets higher when closer to player character (or center of viewport). At the moment I have positional, but all the same loudness, which is very bad :confused:

Could anyone give me some clue how to solve this?
Thanks! :smiley:

I’ve digged around this a bit more…

In version 3.1 alpha it works the same way, which means: does not work!

I’ve checked the GODOT source code, and there are corresponding lines like this:

float dist = global_pos.distance_to(screen_in_global); //distance to screen center
if (dist > max_distance)
		continue; //can't hear this sound in this viewport
float multiplier = Math::pow(1.0f - dist / max_distance, attenuation);
multiplier *= Math::db2linear(volume_db); //also apply player volume!

And this looks all alright - I understand this and it seems it should work as expected.

Though it does not work at all!

I’ve tested max_distance property values from 1 to 2000 and measured distance from kamera to sound emiter. Sound comes out even if over the max distance value.

I’ve tested attenuation curves - absolutely no effect on the volume.

Finally I’ve tried to set the volume_db parameter myself and it also does completely nothing!

Now… Either I am incredibly stupid and do not get something, or this thing does not work as expected!

I’ve also tried to find an example on AudioStreamPlayer2D usage and there is only the platformer demo, in which it behaves the same way - always plays at max volume. Or at least I did not noticed any difference in volume.

Does anyone have a working case? Or is this really a bug?

kozaluss | 2018-09-02 12:07

I am making progress…

I’ve managed to run some streams 2D properly with attenuation working as expected.

Though still having issues with one particular node, which plays sound always loud no matter the position.

I’ll post again if I find something to report :slight_smile:

kozaluss | 2018-09-02 15:02

Problem resolved.
Everything works fine now.
Fortunately it was a hard to spot bug on my behalf.

kozaluss | 2018-09-02 15:08

I know this was a while ago, but do you mind sharing how you resolved the issue? I’m trying to create enemies that make noise, but I don’t want every enemy on the level making noise at once (when they’re far away from the player).

paulsenm86 | 2021-03-23 14:02

Yeah, it was long time ago :/. I do not remember what my mistake was, but definitely I made a bug, that was hard for me to pinpoint. After removing the bug, sound started to sound ok. The bug was something like playing the sound for test purposes on certain node, that was forgotten - or something like that. So it isn’t exactly related to Your problem methinks. Good luck tho :).

kozaluss | 2021-03-23 15:55