Repository navigation
Description
Godot version:
3.1 alpha
OS/device including version:
Kubuntu 18.04 and Windows 10
Issue description:
Creating a rapidly firing weapon, if sounds are played at intervals less than 0.5 or 0.6 seconds there is a clipping or static sound.
Demo: https://www.dropbox.com/s/q5tx4y6272lgdae/2018-09-12%2017-16-00.mp4?dl=0
Improvement can come from modifying sound files with fade in and fade out at either end, but the issue is still present.
Demo: https://www.dropbox.com/s/hnvlu161x1t62fl/secondtest.mp4?dl=0
In the case of testing with a sine wave sound file, instead of clipping / static there is a sort of interference or modulation sound instead.
Demo: https://www.dropbox.com/s/nd2rcsrdrqxo6sd/2018-09-12%2021-19-52.mp4?dl=0
The clipping / static sound can seemingly be eliminated by setting a LowPassFilter and LowShelfFilter on a sound bus, both with a cutoff of 1000Hz.
These filters don't eliminate the modulation type of sound that comes up when using a sine testing sound.
Steps to reproduce:
Create a timer with an interval of about 0.3 seconds and have either a single sound repeat at that interval, or rotate between two different sounds.
Issue present in the editor on Linux and Windows, in builds for Linux and Windows, on 2 PCs in my house, through 3 headphone sets and two speaker sets. Also verified by another user who tested on 2 of their headphone sets.
Minimal reproduction project:
SoundTesting.zip
Tests and attempted solutions that didn't help
Before trying the filters, I also tried:
- Having an AudioStreamPlayer2D as a child of each instantiated missile (this made the effect worse)
- Having the Player character scene play a sound from a child AudioStreamPlayer or AudioStreamPlayer2D
- Creating two child AudioStreamPlayers and alternating between playing one or the other, using the same sound
- Alternating between those two child nodes, but playing two different sounds
- Creating a stand alone scene with an AudioStreamPlayer in it, and instantiating it newly and adding it as a child each time
- Outputting the sound from the two child AudioStreamPlayers to different audio buses
- All three different mix target options
- Reducing volume - tested at -2Db, -4Db, -6Db
- Tested with 9 sound files
- Modified a sound effect with fade in and fade out processing to ensure no clicking in the file itself
- Tried reducing the duration of the sound file to 0.3 seconds, but still had the static effect at intervals of 0.5 seconds or less
- Trying with different sound playback hardware
- Tested on Linux and two installations of Windows
- Tested on 2 PCs
- Tested in editor and in Linux and Windows builds (Windows builds tested on two PCs)
Extra information
I spent a few hours with the helpful folks at the Godot discord last night going through various test to try and isolate the source of the clipping / interference sounds. Our tests did lead us to believe it wasn't an issue localized to my setup alone.
Different people heard different effects from the videos and test project above. Some heard clipping / static on every sound, some heard none at all. One other person heard it as clearly as I did, and confirmed the same on two of their headphone sets.
@starry-abyss had the theory it was something to do with too many high frequency sounds at once, hence we tried the low pass / shelf filters which eliminated the clipping / static sounds.
Given the effect of the filters I'm not sure this is actually an issue as opposed to a sound management technique being required.
If we can confirm this is just about handling sound in a certain way, perhaps I can contribute to the docs with some information for people in the future who run into this problem.
Activity
Calinou commentedon Nov 8, 2018
Try reimporting sounds with the Trim property disabled:
I've found Godot's automatic trimming to be too aggressive, resulting in part of the sound not playing.
Also, beware that Godot 3 currently does not provide polyphony (#23541), so instancing an AudioStreamPlayer for every sound played is a good idea if you need several of them to play at the same time. (Of course, don't forget to
queue_free()them when they are done playing.)Aaron-Fleisher commentedon Nov 22, 2018
FWIW this does not happen on 3.0.6 for me. I sometimes get a random "static sound" (very rare, but it happens) at the beginning of certain sounds that are played (.ogg). Never heard that kind of static in 3.0.6. W10, 64-bit
By the way, that's a very extensive issue report, kudos.
lawnjelly commentedon Apr 5, 2019
Godot version :
3.1 stable
OS :
Linux Mint 18.2 Cinnamon 64 bit
Issue description :
Glitches in audio when reusing AudioStreamPlayer3D node
It sounds like this may be the same issue I have been dealing with in the past couple of days. I have a workaround that works, and a possible reason for what I now believe is probably a bug rather than calling the AudioStreamPlayer incorrectly.
Minimal reproduction project:
godot_audiostreamplayer_test.zip
Full description of the problem
Rather than creating new audioplayer nodes (in my case AudioStreamPlayer3D) each time I need a sound effect, I would expect to either:
Both of these cases involve reuse of the node to play multiple times.
A
When using this scheme, if the AudioStreamPlayer translation and / or volume is changed prior to playing, audio glitches occur. This is not to do with the import settings / normalization / trim, it occurs with these off. It is not clipping. The glitches on my system are approx 1/20th second, probably one of the audio tiles used in a circular audio buffer.
Picture of glitch

The glitch can be seen bottom left waveform, at the start. Each sound should be playing for 1 second, and the glitch is around 0.05 second.
Audio of glitch
https://soundcloud.com/lawnjelly/godot-audio-glitch-test
B
When attached to a game object node, there are not problems from translate (as it is not set prior to calling play()), however changing volume still results in glitches.
Workaround:
By chance I found a different method of playing sounds by Calinou, which I slightly modified and solves the issue:
This seems to solve the issue, and works as a workaround. However, the question is, why?
Creating new AudioStreamPlayer for each sound and attaching to the parent node and deletion on completion doesn't sound the most efficient way of playing sounds.
At a guess, I suspect the reason it works may be because creating a new AudioStreamPlayer is forcing creation and blanking of an audio buffer (or position within a buffer) whereas reuse of AudioStreamPlayer is not getting rid of previous data from playing (buffer, position within buffer, historical record of position or volume?).
I also discussed the issue here:
https://godotdevelopers.browse-tutorials.com/discussion/comment/27395
starry-abyss commentedon Apr 5, 2019
@lawnjelly Just a quick thought: do you initialize the state of objects (i.e. make sure all internal variables are not holding leftover values) before reusing them from the pool? As this is a common caveat with pools. When the new one is created (case B), it's clean, but is so the one in case A?
lawnjelly commentedon Apr 5, 2019
starry-abyss, the example project I posted should show exactly. I don't do anything to the AudioStreamPlayer between playing one sound and the next, just move the translation, change the volume, and call play() again after the previous sound has finished.
Is there anything else that should be done?
As a user I would assume that a sound would autostop at the end, and another play would reset everything necessary. I did actually try calling stop() before play just in case but that didn't change anything.
Calinou, the problem still occurs when trimming / normalizing is turned off during import (you can try this on the example project I posted, and reimport the wav). So I'm assuming it isn't to do with trimming / normalization.
Calinou commentedon Apr 5, 2019
I realized that just after posting the comment, which is why I deleted it 😉 Sorry for the confusion.
jitspoe commentedon Jan 29, 2020
There's also a problem with pops in the AudioStreamPlayer3D. Just going to paste the contents of my duplicate bug here for easy reference:
Godot version: 3.1.2, 3.2 rc4
OS/device including version: Windows 8.1
Issue description:
There are a few situations where playing a sound AudioStreamPlayer3D results in pops or crackles. The easiest to reproduce has something to do with the positional logic. The surround sound logic changed between 3.1 and 3.2, so I thought maybe it was fixed, but even with the new 3.2 positional code, it still has the pops.
I replaced my character's footstep sounds with sine waves, and it became VERY clear that there was something wrong.

It looks like there are actually 2 problems: One, seen in the top channel, is an abrupt volume/amplitude change. The second, shown in the bottom channel, shows the sine wave getting out of phase. I think it's actually playing the sound again at a later time and blending it (also followed by an abrupt amplitude change).
The abrupt change seems to happen at 21ms, which, at a 48000 sample rate is pretty close to the 1024 buffer size. My guess is the first buffer somehow has bad data and is mixing/fading incorrectly.
I dug into the code for a while, but couldn't identify the exact problem. From the looks of it:
Seems there is something wrong with the first buffer every time:

You can see here that sometimes the amplitude is scaled up, and sometimes it's scaled down. Rarely is it ever at the volume it should be (unless maybe the sound is played at a location very close to where it played previously?)
Other pops:
There are 2 other pops I'm aware of that may or may not be part of the same issue. Perhaps they should have their own bug entry once this is fixed.
Steps to reproduce: Play a sound on an AudioStreamPlayer3D, then move it to a new location relative to the camera and play it again. Really obvious when you move from the left to right side of the listener (see attached project).
Minimal reproduction project: sound_pop.zip
lawnjelly commentedon Jan 30, 2020
This may be the problem. I had assumed before it would be something to do with the audio buffer tiles (without looking at the source code), but it may simply be the audio is only changing things on physics ticks.
Besides using physics ticks (which is kind of dodgy, because it means changing physics affects the audio) It needs to be doing interpolation for everything between the ticks, because audio needs to be continuously interpolated. I'm guessing it isn't somewhere.
Also I suspect the problem I was having with changing position and playing a AudioStreamPlayer again was because it was waiting to the next physics tick to set the new output, instead of doing this via a forced path every time play is called.
I can't look at it now, busy with other stuff, but hopefully this might provide ideas for anyone else working on the audio.
jitspoe commentedon Jan 30, 2020
I tried a quick hack where I forced a call to update the physics-related stuff to try to ensure the data was set before the audio thread tried to process it, but that didn't seem to fix it. :(
The audio thread keeps track of the previous data and lerps between the previous and current values. This appears to work properly everywhere except for the first buffer.
jitspoe commentedon Feb 1, 2020
In case it's helpful, here's a clip from when I got a pop while hardcoding the relative position of the listener (WARNING: TURN VOLUME DOWN): https://clips.twitch.tv/ViscousCooperativeBasenjiMoreCowbell
Another: https://clips.twitch.tv/JollyDignifiedCarabeefItsBoshyTime (you can also hear the pop when the elevator looping sound stops, which is another issue).
Unfortunately, the compression makes it almost impossible to tell what the original wave form actually did.
I think there are 3+ unique pop bugs.
Calinou commentedon Feb 1, 2020
You could upload a short video with uncompressed audio, put it in a ZIP archive and upload it here. Or just upload a WAV file of the video's uncompressed audio in a ZIP archive 🙂
jitspoe commentedon Feb 2, 2020
I don't have an uncompressed recording. Whenever I try to catch it in the act, I can't seem to reproduce it. I just happened to have these because I'm live streaming the whole development.
57 remaining items
sketchyfun commentedon Mar 31, 2022
I've just tried applying the changes from #59413 but when I run the project I attached in my comment above I'm still getting popping noises, so I don't believe the issue has been completely fixed. Can you try the file I attached to my previous comment and see if it's fixed for you?
ellenhp commentedon Mar 31, 2022
That repro project still displays the pop. Seems like the cross-fade is broken. The 3.x audio system is really tricky to work on but I bet it would be possible to move the non-spatial player crossfade logic into the spatial players. No promises though because my availability for Godot work has been really inconsistent lately.
ellenhp commentedon Mar 31, 2022
As a workaround, you could try using multiple audio players and allowing playback for each to expire normally when the audio stream ends.
sketchyfun commentedon Apr 2, 2022
This happens in many places throughout my game, so I don't think multiple audio players would be a suitable solution for me. I'll have a dig through the regular audio player code and see if I can figure out what can be transplanted into the spatial audio player to fix my problem
ronyeh commentedon Jul 6, 2022
Hi!
If any devs on the Godot Audio system need me to help with testing or bug repros, please @ or message me. I've been running into issues with my app regarding rapidly repeating sound effects (and pitch shifting), so I am very much interested in seeing the audio system improved. I'm happy to help out in any way that I can.
Thanks for all your hard work. Godot is awesome. :-)
elvisish commentedon Oct 30, 2022
Is there any workaround for this in 3.x? Even using 4+ audio players and iterating through an array to assign which one to play doesn’t work for some reason.
elvisish commentedon Nov 1, 2022
Is this fixing the problem with zero-crossings causing the pops? I opened 5697 but it was closed as it was suggested to be a duplicate of this, but I don't think so. I think Godot needs to automatically add a micro fade out at the end of sounds when it stops playing them to avoid pops/clicks on zero-crossings. This will happen any time a sound is stopped and it lands on a zero crossing, be it destroying the audio player, stopping the stream, changing the stream or seeking. It's not a bug really, it's just a natural mathematical inconvenience that should be accounted for in the audio engine.
Fix volume interpolation in positional audio nodes
Fix volume interpolation in positional audio nodes
Fix volume interpolation in positional audio nodes
Fix volume interpolation in positional audio nodes