Refactor audio system and improve loot mechanics

  • Implement MasterSpeaker to handle audio mixing outside of the SDL callback.
  • Introduce SfxSource and Snd3d pull/vpull logic to optimize concurrent sound processing.
  • Remove thread locks from audio mixing path for improved performance.
  • Add loot bounce SFX and update physics properties for loot objects.
  • Shuffle loot drop delays to distribute processing load.
  • Optimize Snd3d attenuation and mixing logic.
  • Clean up unused todo documentation.

May the fourth be with you!

I’ve been adding more sounds and hitting some performance issues. With 60 mobs walking around, attacking, and grunting, plus loot showering down—each piece making noise when it spawns, bounces, and gets picked up—I sometimes have hundreds of concurrent sounds. My current implementation is struggling to keep up. I added a priority system to play only the most important sounds, but I really want to hear everything!

I’ve been thinking… could I implement this on the GPU? It should work, right? I could upload all the SFX to the GPU and use a compute shader to mix the sound frames (1024-2048 samples). It would be lightning fast. I’d just need to upload a list of active SFX positions each frame and download the mixed buffer back. Since it’s only 2 channels * 2048 samples * 4 bytes, that’s only 16 kilobytes to transfer back—hardly anything.

I’ve been playing around with the CPU version for now. In a debug build with 64 concurrent audio sources, it takes 10ms to process a 2048-sample frame, but in release, it’s only 0.5ms. I’m torn on what to do since I spend most of my time developing in debug mode.

Previous