Do not play too many sounds at once
Indy2222 opened this issue · 3 comments
For example during destruction of a large number of entities, a big number of sounds may be played at parallel. Limit the number of sounds started during a single tick (and ignore the rest).
The obvious approach is to aggregate the sound events over a tick instead of starting playback for each event. The ambiguous part is how to play it back. A naive way would be to average the positions and play the sound once at that point, but that would begin to present problems when there's fighting all around the map, so that wouldn't work. But I think there are some things you could do to avoid the issues.
One way would be to only count the sounds that are currently audible in the player's view. That way the sound would definitely play in a logical area, but it would mean when you pan to another area, no sounds would be playing. Optionally we could keep track of the positions that every aggregated playback instance came from, and adjust the playback based on the average in view every frame, instead of ignoring everything out of view at the time of the event.
An improvement regardless could be to scoop up bunches of the event based on a radius for example, to reduce the density so we have less information to deal with.
How about the closer the sound the higher the priority and we play the top 25 sounds. Maybe also decrease priority for duplicate sounds.
How about the closer the sound the higher the priority and we play the top 25 sounds. Maybe also decrease priority for duplicate sounds.
Prioritizing based on camera distance at the time of the sound start makes sense.