# Handling sound effects for Multiple Collisions

How can I generate somewhat realistic sound effects for collisions in a physics engine that simulates lots of objects?

E.g. take >10 marbles that are bouncing off walls and off each other.

If I generate a sound for each collision I would quickly overload the system (Windows Phone 7).

Is there an algorithm that lets me combine multiple collisions to create fewer sound effect instances?

Usually what you do in this case is let the sound system handle it.

So somewhere there's a collision happening. And where that collision happens you call a "play bounce sound" function.

In pseudocode just change your sound class to do something like this

void Update()
{
timeSinceLastBounceSound += Time.deltaTime;
}

void PlayBounceSound()
{
if( timeSinceLastBounceSound < someThreshold )
return;

// do whatever you do to play the sound
}

• I basically took your approach but used time slices because they make it easier to calculate the volume. – laktak Dec 16 '10 at 10:40

You could create a new sound that is a sort of "many marbles hitting at once" sound, then play it if there are more than 10 active collisions at once. Play any individual collision under 10, and then the "many marbles" sound if there are more than 10.

Think of it like simulating a crowd applauding. At some point it just sounds like a crowd applauding, not a collection of individual claps.