Graf Zahl wrote:HM. Looking at s_sound.cpp it looks like the sound code completely ignores this scenario and happily keeps an active channel for the looping sounds no matter what - even if they are not playing.
If a sound is physically stopped (eg. it reached the end and wasn't looping, or was explicitly stopped), it decouples the source from the high-level channel.. it clears the SysChannel field, and removes the buffer from the source. The next sound that's started can then freely use the source with its high-level channel.
The problem is, the sounds
are playing. They're looping ambient sounds. From what I can tell, if a sound type has SOURCE_None, or if the actor is the camera, it's gets a priority of 40. All other sounds get a priority of 0. Because of this, if all sources are taken and a normal non-player sound tries to play, it'll never find a sound that it can kill because the other priorites will always be >= to it. Even if a sound is a quiet ambient wind at the edge of audibility, it'll prevent a barrel exploding in your face from making a sound. And even if you allowed a sound to overtake another sound with equal priority, it would only help for a split second, before the the other sounds are triggered again and re-take it.
EDIT:
What I think needs to happen is ZDoom needs to realize a sound is out of hearing range (ie. is beyond MaxDistance with a non-log rolloff type) and stop the channel itself, and not try to start it again until it comes back in range (for looping sounds). This doesn't seem to be something the individual audio systems need to do because they'll all behave the same.. the sound will never be heard because the attenuated volume must be 0. It could also help to be a bit more.. explicit with priority values, instead of just 40 or 0. Maybe it could have 40 for "camera" sounds, 20 for in-range sounds, and 0 for out-of-range sounds (coupled with not trying to restart ouf-of-range looping sounds).
EDIT2:
This seems to work. If the sound is stopped when it's beyond max distance for non-log rolloff types (calculated attenuation is 0), and I don't even attempt to start a sound that's beyond max distance for non-log rolloff, then even Z1M3 with 32 channels plays fine. But this seems to be something ZDoom should do itself, instead of relying on the sound backend to do it.