+ // Ignore the command if step isn't valid.
+ if (step == 0)
+ return;
+ float current_gain = getSoundGain(soundid);
+ step = gain - current_gain > 0 ? abs(step) : -abs(step);
+ if (m_sounds_fading.find(soundid) != m_sounds_fading.end()) {
+ auto current_fade = m_sounds_fading[soundid];
+ // Do not replace the fade if it's equivalent.
+ if (current_fade.target_gain == gain && current_fade.step == step)
+ return;
+ m_sounds_fading.erase(soundid);
+ }
+ gain = rangelim(gain, 0, 1);
+ m_sounds_fading[soundid] = FadeState(step, current_gain, gain);