Fade in and out streaming audio

Hi everyone!

Quick question about the new audioengine now that I’m kind of tackling music stuff… Is there a recommended way to have a fade in/out with the streaming audio? I’m beginning to implement a “jukebox” kind of functionality of changing songs in my game and I wonder if I have to manually just up/lower the volume in the main loop or is there any other way? Thanks in advance <3

Pinging @docEdub a bit :slight_smile:

This is a good question. Yes, using the main loop is the way to do that right now, but it would be better to do fades at the audio rate, instead. This would be a good feature to add.

3 Likes

Would be a cool feature no doubt!

I would imagine using it like:

sound.fadeIn(1000, options)
sound.fadeOut(1000, options)

To get a cross fade…

1 Like

@docEdub Is this something that exists at the present time:

sound.fadeIn(1000, options)
sound.fadeOut(1000, options)

It would be great to have that. I’m looking to do that in my behavior scripts right now and I’m wondering what exists at the moment or if there are plans to have this soon.

Thank you in advance.

No, but soon. I need to do some investigation on what works in different browsers. I know the fade in/out WebAudio functionality is not 100% implemented in Firefox and Chrome on Meta Quest, so I need to go deeper to find the best solution.

3 Likes

PR 16781 adds a new setVolume function to sounds and buses that takes options for duration and shape type. Fade in and out can be done using this new function.

The important parts are here:

…and the docs will be updated to include setVolume soon!

5 Likes

Wow, that"s great. Thank you very much for this addition. @docEdub :slightly_smiling_face:

1 Like