Sudden loudness changes producing unwanted noises?
You are changing the volume in discrete steps, applied at random points in the audio signal.

If the signal happens to be close to zero, you won't hear much of anything.

If the signal is close to a peak, then you will get a "step" change in the signal.  This audible.

When you roll the volume up and down that way, you get a kind of "zipper" sounding noise.

What you want to do is to apply volume changes only when the signal is close to zero.  The "zippers" still occur, but are much less annoying - and may be completely inaudible if you change volume only at times when the signal is at zero.



Looking at the code you referred to in a comment, it appears you aren't changing volume when the amplitude is close to zero.

You are changing volume when the signal is less than zero.  What you want to do is to change volume when the absolute value of the signal is less than some small value.

Start with like 0.1, then try 0.01.  You should notice far less "zipper noise" that way.

Sort of like this:

if (abs(amplitude) &lt; 0.1d) {
   currentVolume = targetVolume;
}