Random audio popping/crackling

Godot Version

4.6.1

Question

How do I prevent random popping/crackling?

I made some coinup .wav files from https://pro.sfxr.me/ to play on my game’s main menu. But there is random popping/crackling. I tried new sounds and the problem just kept… popping up.

PlaybackType doesn’t fix it.

readonly float _pitchA = 0.8f;
readonly float _pitchB = 1.2f;
float t = (float)rnd.NextDouble(); // 0 to 1
_audio.PitchScale = _pitchA * MathF.Exp(t * MathF.Log(_pitchB / _pitchA));
// this cool formula is courtesy Freya Holmer: https://x.com/FreyaHolmer/status/1813629237187817600

The Fix

The high-pitched coin-up sound does not work well with the formula.

Use a lower range:

readonly float _pitchA = 0.7f;
readonly float _pitchB = 0.9f;

I have not tested low-pitch sounds, but I assume for those, you might want to use a higher range:

readonly float _pitchA = 1.1f;
readonly float _pitchB = 1.3f;