-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Audio clips when changing volume of audio bus #32882
Comments
@Zylann Which duration would you recommend for the ramping? Also, does a specific easing method need to be used, or is linear interpolation fine? |
@Calinou I don't know, maybe 10, 20 samples? Need to be tested. This kind of problem occurred in the past (I think it was for looping?) and that's how it got fixed. |
@Calinou Even better might be to allow the user to specify the fade time, and have a default. Linear interpolation will probably be fine. e.g. Store the current volume, the target volume, and the end time of the fade. That way if another fade is requested before the first is complete you can just replace the values and it should work fine. I think with short fades the danger is that the fade itself can introduce extra artefact frequencies into the sound (with zero fade being worst case as it is now). Low frequencies may be more susceptible. If you think about a 50hz sin wave, fading it out from a peak over 1/8 of this period (1/50 * 1/8) will lead to a waveform at approx 100hz over the fade, giving a slight audible glitch. I suppose in theory we could calculate the minimum fade needed (this is just guesswork lol 😄 ): If we consider that the minimum frequency we could hear is 10 hz (giving it a bit of leeway), then in a worst case scenario we are fading a constant 1.0 value to 0.0, we would want any artefact frequencies created to be below 10hz. For a sine wave fade, this would be 1/10 second * 1/4 (peak to 0) = 1/40 second. With a linear fade this would produce a triangle wave rather than a sine, so you would get a bunch of higher artefact frequencies which is not ideal, but still that should give us some idea of the minimum fade. In practice I would think 1/10th of a second would be about right. The reason I suggest also having a user specified fade time is that if the user does want to try and do a fade over say 10 seconds manually, and you have a fixed short fade time, this will come out as a series of jumps in volume rather than a smooth fade. Of course all this is far more important for note-offs in music, and I don't know the use cases for bus volume changes - probably things like user changing volume, and moving between areas with different sound effect levels. So if you did go for a fixed fade time there would be an argument for using a larger value like a second. |
@lawnjelly I'd say slow fades are AnimationPlayer/Tween territory. The built-in fade should only be there to prevent audible clicks, not for effects. |
That is the thing about audio though, you can't use AnimationPlayer/Tween, because it is not frame or tick based, it runs on a separate thread and needs to be interpolated continuously. If you attempt to use a Godot node to do a slow fade, you'll get audio anomalies. It's a bit of a special case. |
I also get this issue when tweening the volume of an audio stream player. Is there any way to do this better ? |
Note that AudioStreamPlayer already interpolates the volume, across one buffer size: godot/scene/audio/audio_stream_player.cpp Lines 80 to 88 in cee5414
The same could be done for the buses. Apparently the buffer is 256 samples long, i.e. around 5 ms, which is a bit short. godot/servers/audio/audio_stream.h Line 62 in 8f7f584
Searching around the internet, I read that values around 20 ms and 50 ms should be fine for a linear ramp. |
Hello. I am the troublemaker that created the now closed duplicate. What you need to do is adjust the player/stream's volume directly which does not have this issue. |
Can anyone reproduce this on the |
A reliable workaround I have found for this is to use the delay effect on the appropriate audio bus, then enable one of the taps, set its The delay effect ( The only other option available in the effect is called 'dry'. The value of dry determines the output intensity of the original sound. The only two important options for our use case is the dry and one of the taps ( say Therefore, if we were to slide the 'dry' option around, the bus output would fade in or out. Empirically this method does not result in clipping or crackles, but it is still possible to get them if the volume change is nearly instantaneous in nature (such as with a volume slider), however these are nearly negligible and the end user is not very likely to notice. Even so, these can be easily avoided for the most part by using very small tweens on value change. This workaround was hinted on by this question over here: https://godotengine.org/qa/27939/how-to-fade-in-out-an-audio-stream |
I having this same problem in a Android export from Godot Engine 3.5.2. At first I tried to use a So I came here and tried the solution mentioned by ideaplexer just above, but got the same crackles in the audio. What worked for me was similar to ideaplexer workaround, but instead of using the Using tween to animate the |
thanks this helped me. some sample code for godot 3
|
Godot version: 3.1.1 stable
OS: Windows 10 Pro version 1903 build 18362.418
Device: ASUS ROG Zephyrus S GX502GW (using both integrated laptop speaker and OnePlus USB-C bullet earbuds)
Issue description:
Changing the volume of an audio bus using
AudioServer.set_bus_volume_db()
or through the visual interface (Audio bottom tab) produces very audible clipping noises. Comparatively, changing the volume_db property on an AudioStreamPlayer produces virtually zero clipping.Steps to reproduce:
Create a scene with an ASP and set it to the master channel. Load some music file on it, set
Playing
to true and play with the volume property knob. Notice virtually no sound clipping. Now open the audio tab on the bottom and play the same sound file. Try changing the volume of the master bus with the vertical bar. Sound will clip a lot as you change the volume.Bugsquad edit (keywords for easier searching): crack, cracking
The text was updated successfully, but these errors were encountered: