The original code changes volume resistor value abruptly in one big change. This affects DC value of audio signal and results in audible pop in speaker. My idea is to change resistor value gradually in smallest possible steps, which should reduce or eliminate speaker pop.

Volume now changes in small steps every 4ms instead of one big step. Step size is minimal (1/127 of total resistance).

This method is actually more annoying then original method. Now, instead of one slightly louder pop we get a series of quieter pops, almost like a short buzz. Not satisfied with solution.