Jump to content
  • Advertisement
EddieK

Dealing with large amount of sounds playing at the same time

Recommended Posts

Hello, I'm new to OpenAL and audio programming in general so I might not explain everything clearly, but bear with me.

Essentially I'm making a tower defense game where I have dozens of turrets shooting at approximately the same time and each shot makes a sound. So there are few problems/questions which I have:

1) While one turret is shooting the volume of the shot is low, but when dozens of them are shooting the sounds seem to add up and make everything too loud. Is there a way I can fix this?

2) When there are many turrets shooting, the music becomes quiet. And when they stop shooting I can hear the music gradually up in volume. Does OpenAL use some sort of compression? If so, how can I tweak it?

I tried making it so that there would be a max number of shot sounds at any given time, but sometimes you can see a turret shooting and it doesn't make any noise, which looks weird. 

 

Share this post


Link to post
Share on other sites
Advertisement

One thing I do when I have lots of entities that can do the same action at once is wait a random delay before doing the action. That way, it looks a lot more natural and the sound problem is lessened. 

If you have a large map, then you will naturally use positional sound effects which will reduce the volume of sounds that are far from you if not mute them.

If it's still too loud and lots of sounds happen all the time, I will lower the volume simply. If few sounds happen, it's fine if they are quiet because it gives auditive strength to the more intense action.

For limiting the number of sounds, I presume that you count how many sounds are currently playing and skip newer sounds if it reached a limit. Instead of playing sounds directly, send a sound event to a sound manager. This sound manager will receive events from everywhere it's needed and it will keep track of the number of received events for each individual sound. Once the sound manager has received all the events for this current frame, it will decide which sounds should be played. For example, if I count 100 events to play the sound "laser_gun", I can play the sound once, but adjust the volume with the following algorithm.

for each (soundEvent) {
      // Each additional sound event increases the volume by 5%
      // instead of 100% if you'd play it twice.
      float vol = 1.f + (soundEvent.counter - 1) * 0.05f;
      SoundAPI.play_sound(soundEvent.sound, vol);
}

That way, many sounds are still louder, yet not too loud. Notice that I used a linear function to increase the volume, but you could use an exponential function so that a second sound event increases the volume by 50% and the tenth only increases by 5%, etc.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!