Search code examples
c#audioxna

Same sound overlapping making it very loud. Tips/Tricks?


I've got multiple object in a game I'm making, and I'm having major issues figuring out how to play sounds without playing the same sound twice or more. I'm wondering if you have any tricks/tips on how to make the sound play only once no matter how many instances of it is made and be balanced, rather than having it played 50 times being mega loud.

I'm using the XNA.Framework.Audio.SoundEffectInstance to play sounds.


Solution

  • This is more of a mixing issue than a programming issue. Playing a sample twice will always result in a fuller effect.

    From a programmatic perspective, you can make sure the sound is never playing twice at the same time. To accomplish this, set a boolean value every time a sound is about to play. Before you play the sound, make sure the boolean value is false or cancel the event. Set the boolean value to false once the sound is played.