Skip to content

Add a fade in to stream playback on start #107557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ObaniGemini
Copy link

@ObaniGemini ObaniGemini commented Jun 15, 2025

This is a simple attempt to fix #107551

I used the same behaviour used for the fade out mechanism to add a fade in mechanism. This just takes advantage of the cubic interpolation to smooth the start, just like it does for the stop.

Without interpolation on start:

audioloopclick.mp4

With interpolation on start:

audioloopnoclick.mp4

Problems

This doesn't work well with sounds with a punchy start, and should only be an option you set for streams. A comment below shows why.

Potential enhancements

Because of the problem above, this could be used only for looping streams, or added as a stream parameter (the playback state would just need to be set to PLAYING instead of FADE_IN if it's not a looping stream). I'm just not really sure how to do it properly in this case.

@ObaniGemini ObaniGemini requested a review from a team as a code owner June 15, 2025 10:57
@AThousandShips AThousandShips changed the title Add a fade in to stream playback on start (solves #107551) Add a fade in to stream playback on start Jun 16, 2025
@AThousandShips AThousandShips added bug topic:audio cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release labels Jun 16, 2025
@AThousandShips AThousandShips added this to the 4.5 milestone Jun 16, 2025
@ObaniGemini
Copy link
Author

After doing some test with sounds with a punchy start, it revealed this PR cannot be merged as-is. If this were to get in godot, it should be an option, because it's too destructive for the start of some punchy sounds. Here's an example:

no fade in:

no_fade_in.mp4

with fade in:

with_fade_in.mp4

note that this example is just godot playing samples one after the other with a 1.5s interval

@@ -462,8 +462,8 @@ void AudioServer::_mix_step() {
// The channels correspond to output channels of the audio device, e.g. stereo or 5.1. To reduce needless nesting, this is done with a helper method named `_mix_step_for_channel`.
for (int channel_idx = 0; channel_idx < channel_count; channel_idx++) {
AudioFrame *channel_buf = thread_get_channel_mix_buffer(bus_idx, channel_idx);
// TODO: This `fading_out` check could be replaced with with an exponential fadeout of the samples from the lookahead buffer for more punchy results.
if (fading_out) {
// TODO: This `fading` check could be replaced with with an exponential fadeout of the samples from the lookahead buffer for more punchy results.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// TODO: This `fading` check could be replaced with with an exponential fadeout of the samples from the lookahead buffer for more punchy results.
// TODO: This `fading` check could be replaced with with an exponential fade of the samples from the lookahead buffer for more punchy results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release topic:audio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AudioStreamPlayer doesn't fade in sound on start
3 participants