I feel like I’m going insane over here, adjusting volume_db on a ASP3D is simply not doing anything at all, and googling and searching these forums it seems like nobody else has ever had this issue.
I have a sound controller node3D with an ASP child and have simplified it down to just the Node3D parent, and a child Camera3D and AudioStreamPlayer3D both located at the origin. The only script running is on the AudioPlayer telling it to play the stream on ready.
I run the test scene, I hear the sound, but I can only play it at full volume. Adjusting volume_db either in the editor or in code does absolutely nothing. Adjusting pitch_scale and max_db works completely as expected.
Am I missing something really stupid or just not understanding something really basic here? In the editor, when I set the sound to playing and drag the volume_db slider, it has an effect. Why would this not work in game?
It’s about the attenuation - if you have attenuation_model set to the default inverse and place your Camera3D and AudioStreamPlayer3D at the exactly same position, changing the volume won’t make an effect, because the distance between the two is exactly 0.0 and the attenuation will make this change of volume have no actual effect (it’s basically dividing by zero, leaving you with the same actual volume level no matter what volume_db you set.)
In the real scenario you probably won’t have the camera and audio player at exactly the same position, so it will work as you’d expect - you can test it by moving your camera some distance away from the audio player. However, if you plan to have the camera and audio player placed at the same position for some reason, consider changing the attenuation_model to disabled, or using the regular AudioStreamPlayer (not 3D).
Oh my gosh. I can’t believe it didn’t occur to me to test this. I knew it had to be something pretty simple. Thank you. The reason I had put the camera at origin was that in my actual scene I had been placing an AudioListener on the player character, so that sound is based on proximity to the character rather than the trailing camera.
So, this does fix it, but that said it doesn’t make any sense really and seems like it could/should be improved. I don’t see any reason why this functionality should be so janky. Why doesn’t it just play the sound at your specified full volume (stream volume + volume_db) when you’re at the same exact position as the audio source and then fade out the further you go?
Is there a way to suggest an improvement for the next build or whatever because this just seems crazy that it would be glitched out in this way and that the attenuation wouldn’t be handled in the way that makes obvious intuitive sense (full modified volume at 0 distance, fades out from there).
It doesn’t make sense to me that there should be any dividing by zero involved. The code should be taking the specified full volume and then subtracting a value from it which is multiplied by distance, aka volume_at_location = min( max_db, volume_db - (attenuation_factor * distance)) or similar. Why is there any dividing by distance involved whatsoever? It makes no sense at all to me.
Having to offset the AudioListener3D by some arbitrary amount just feels super janky and imprecise, like how much should I offset it by? I’m offsetting vertically (y), setting it to low values (<.5) seems to limit the effect of volume_db and cause strange behavior. But offsetting it by a large amount is going to make the attenuation behave strangely for other sound sources near the player in the xz plane because the distance from the listener won’t increase linearly.
Again, not like a huge deal, I can just set the offset to around .5 and it will be OK, I can deal with it, but it just feels messy and like there’s no good reason for it to be like this.
Any thoughts on if there’s a good reason why it’s the way it is before I go to any effort to try to suggest that this be changed/fixed?
Also just to mention, the reason I want to use ASP3D is because in my architecture I have a “Ship” class which is generic to player and non-player ships which instantiates itself a generic “Sound Controller” scene on ready, I don’t want to have to write separate code and create a separate Sound Conroller scene using non 3D ASPs because it’s just clunky and feels stupid from a code architecture standpoint, when all the sounds the player ship is playing are the same as non-player ships. UI noises that are exclusive to the player are handled separately through the UI.
Your misconception comes from the fact that the slider is using the dB scale with a range between -80.0 and 0.0. The minimum on this scale (the -80.0 dB) is not truly a zero volume, but very close to a zero. So it still plays a sound at -80.0 dB, but just very very silently.
Now, if the attenuation is enabled and you put your listener at the exact same position as your audio player, it will still record that sound no matter how silent it is. It’s similar to if I whisper to you from across the room - you wouldn’t hear anything, but if I do the same right next to your ear, you’d hear it perfectly clear.
You can go below the -80.0 in a script, e.g. if you put this code in your audio player script, it will take the volume down to -200 decibels, which might be enough to see the difference in actual perceived volume. If not, just adjust -200 to something even lower. If it eventually gets to negative infinity - that’s the true silence then.
You can achieve the true silence by adjusting the “volume_linear” instead of the “volume_db”. The “volume_linear” scales from 0.0 to 1.0, where 0.0 is exactly negative infinity on the volume_db scale.
What I agree with you is that currently we don’t have a way of adjusting the volume_linear scale in the inspector - and there already is a proposal for that, which you can follow and endorse here: