Skip to content
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 / Sound Pops on AudioStreamPlayer3D #35689

Closed
jitspoe opened this issue Jan 29, 2020 · 3 comments
Closed

Audio / Sound Pops on AudioStreamPlayer3D #35689

jitspoe opened this issue Jan 29, 2020 · 3 comments
Labels

Comments

@jitspoe
Copy link
Contributor

jitspoe commented Jan 29, 2020

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.
image

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:

  1. AudioStreamPlayer3D::play() indicates the player is active and enables the physics process.
  2. AudioStreamPlayer3D::_mix_audio() is called from a separate thread. Data isn't set yet, so it fills the buffer with 0's (this is probably not great, as it likely delays the sound, but shouldn't cause a pop).
  3. _calc_output_vol() called when there's a NOTIFICATION_INTERNAL_PHYSICS_PROCESS, which sets proper data.

Seems there is something wrong with the first buffer every time:
image
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.

  • A rare, but very harsh pop that happens seemingly at random. Does not appear to be position related (I hardcoded the location to test). Can't figure out a consistent repro for this one.
  • Calling stop() on a looping sound.

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
Copy link
Member

Related to #22016?

@Calinou
Copy link
Member

Calinou commented Jan 29, 2020

Duplicate of #22016. Still, thanks for making a detailed bug report 🙂

@jitspoe
Copy link
Contributor Author

jitspoe commented Jan 29, 2020

Darn it, I tried like 3 times to find an issue for this, since I was pretty sure it was known, but I didn't find that one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants