by Chris » Fri Jan 01, 2021 4:36 pm
To clarify what seems to be going on, what's happening is the armor pickup sound plays on the local channel for player pickup sounds. When you pick up another armor bonus, it stops the current pickup sound and starts playing it again (since only one instance of that sound is allowed to play at a time). The faster you pick them up, the sooner they get cut off. If a sound just stopped mixing without any consideration for anything, there could be a significant amplitude change since it now would essentially be mixing 0s compared to what it was just before it stopped.
In older versions of GZDoom (4.3.3), this was worked around by making it so when a sound is supposed to stop, the sound source would instead continue playing but its gain would be set to 0. That would make OpenAL fade the sound to silence over the course of the next mixing update while it kept playing (meanwhile, the sound source would be unusable for playing another sound and the sound buffer would remain in use). GZDoom would wait for a few frames before stopping the sound source for real. Consequently, GZDoom had to keep track of "stopped" sound sources, wait until OpenAL mixed and silenced them by checking the current time vs when they were set to silence, then actually stop them. And if a sound buffer needed to be removed from the cache, it had to be more careful to ensure "stopped" sources were really stopped (potentially causing a click/pop anyway) so the sound buffer could be deleted.
While this worked, it resulted in increased bookkeeping costs on GZDoom's side, and it only benefited GZDoom (there was also the limitation that it did nothing for sounds being paused, so things like opening/closing the menu or console could still cause clicks/pops). Having a built-in solution that would work for all OpenAL apps and regardless of why a sound stopped mixing would be much more desirable since apps then wouldn't have to care and would get glitch/pop-free playback regardless. So with OpenAL Soft 1.20, I implemented the method that is being used now (when a sound is stopped, the internal mixing voice is set to do one more mix without any associated sound source or sound buffer, since the app may be changing or deleting them, using the last known sample values to fade to silence). Later versions of GZDoom that updated to OpenAL Soft 1.20 removed the extra bookkeeping code since OpenAL's handling of the issue was suitable.
To clarify what seems to be going on, what's happening is the armor pickup sound plays on the local channel for player pickup sounds. When you pick up another armor bonus, it stops the current pickup sound and starts playing it again (since only one instance of that sound is allowed to play at a time). The faster you pick them up, the sooner they get cut off. If a sound just stopped mixing without any consideration for anything, there could be a significant amplitude change since it now would essentially be mixing 0s compared to what it was just before it stopped.
In older versions of GZDoom (4.3.3), this was worked around by making it so when a sound is supposed to stop, the sound source would instead continue playing but its gain would be set to 0. That would make OpenAL fade the sound to silence over the course of the next mixing update while it kept playing (meanwhile, the sound source would be unusable for playing another sound and the sound buffer would remain in use). GZDoom would wait for a few frames before stopping the sound source for real. Consequently, GZDoom had to keep track of "stopped" sound sources, wait until OpenAL mixed and silenced them by checking the current time vs when they were set to silence, then actually stop them. And if a sound buffer needed to be removed from the cache, it had to be more careful to ensure "stopped" sources were really stopped (potentially causing a click/pop anyway) so the sound buffer could be deleted.
While this worked, it resulted in increased bookkeeping costs on GZDoom's side, and it only benefited GZDoom (there was also the limitation that it did nothing for sounds being paused, so things like opening/closing the menu or console could still cause clicks/pops). Having a built-in solution that would work for all OpenAL apps and regardless of why a sound stopped mixing would be much more desirable since apps then wouldn't have to care and would get glitch/pop-free playback regardless. So with OpenAL Soft 1.20, I implemented the method that is being used now (when a sound is stopped, the internal mixing voice is set to do one more mix without any associated sound source or sound buffer, since the app may be changing or deleting them, using the last known sample values to fade to silence). Later versions of GZDoom that updated to OpenAL Soft 1.20 removed the extra bookkeeping code since OpenAL's handling of the issue was suitable.