Babylon Sound's setVolume with time parameter ignores the custom attenuation function


I encountered an issue while using sounds attached to a mesh with a custom attenuation function.
These are the sound options - { loop: true, autoplay: true, maxDistance: 20, volume: 0.3, useCustomAttenuation: true }.

The custom attenuation works fine, but when I call sound.setVolume with the time parameter, the result is buggy.
For example, if I call
sound.setVolume(0.5, 5);
for the next 5 seconds, the volume switches between the gradual increase of the volume to 0.5, and the output volume returned by the custom attenuation function.

In the playground example below, the camera is further than the maxDistance, so once setVolume(0.5, 5); is called, the volume switches between gradual increase in volume and silence. IMO, ideally any changes to volume will always consult the custom attenuation function, and not work independently.

Please let me know what you think!

Thanks :slight_smile:

Adding @docEdub our Audio Guru.

Sound.setVolume and Sound.setAttenuationFunction are not intended to be used at the same time. They will both compete for the Sound’s underlying GainNode.

To have separate control over the volume while using Sound.setAttenuationFunction, you need to insert another GainNode into the audio graph after the Sound’s underlying GainNode, like in this playground: