Search Unity

Volume increases if 2 audio clips play at the same time

Discussion in 'Audio & Video' started by mukulabdagiri, Oct 20, 2016.

  1. mukulabdagiri

    mukulabdagiri

    Joined:
    Jul 1, 2016
    Posts:
    11
    I have my collision sound files in WAV format. I have set up the volume for all the sounds in Audio Source. I play the sound file using AudioClip.PlayOneShot(). It works fine for single sound at a time. However, if there are multiple collisions at the same time, PlayOneShot() is called simultaneously for all the collisions resulting in a louder sound.

    Why is the resulting sound of simultaneous play calls louder? It might be that its an illusion of louder sound because the multiple sounds are separated by a very small interval in milliseconds, but it does sound louder in volume.

    I can code it in a manner that the play sound function gets called only once if the successive function calls are too close to eachother, but it would be a hack. Is there a better solution to tackle this?

    Thanks,
    Mukul
     
    sem_fisher01 likes this.
  2. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    653
    I'm a noob at this but it must be coming from the same audio source. You can only play one sound per audio source. Incidentally I'm learning this all just today so the answers here should be helpful.
     
  3. Pelican_7

    Pelican_7

    Joined:
    Nov 25, 2014
    Posts:
    190
    Because you're essentially playing multiple instances of your collision sample at the same time. The audio signals will be summed. In your case, playing two identical samples at the same time will result in the sample played twice as loud.

    What's the reason that you don't want two collisions to be louder than one? In the real world that would be the case. Two impacts should really be louder than one. Having said that, I understand that this can sound quite jarring and unconvincing sometimes. Naturally, it depends on your game's needs, but a few things that helped me when having many potentially simultaneous sound effects:

    - Try using a few variations of the sound. Playing two identical samples very close together can be quite jarring. If you had say 5 collision sounds and 'randomly' select one each time your trigger a collision (never the same one twice in a row), it would help to create a more convincing solution.

    - Mix your levels in-game. This sounds obvious, but test and balance your levels in-game. You'll quickly discover that you have for example, 3 simultaneous collisions happening when you expected one, and so that sound effect needs to come down in volume. Again, 3 impacts probably should be louder than one.

    - Enforce some limits. You mentioned it was a hack but I think it's sensible to enforce some limits. There comes a point whereby it becomes hard to differentiate between say 4 simultaneous impact sounds and 5, and you're really just risking clipping/distortion and wasting CPU. It depends on your system, but you could even have separate sound effects for high numbers of collisions. A good example of this is in Wii bowling when you knock over large numbers of pins, a separate many-pins-falling-down sound effect is used as opposed to when you knock over two or three and it plays one for each pin.

    Hope that helps a bit!
    Andy
     
    sem_fisher01 likes this.
  4. FabDynamic

    FabDynamic

    Joined:
    Jul 31, 2017
    Posts:
    36
    I realize this is an old thread but for posterity: All of my distortion went away when I added all of the audio sources to an "AudioMixerGroup" and then added the "normalize" effect with default options. It did effectively exactly what I think you wanted it to do.
     
  5. datagreed

    datagreed

    Joined:
    Sep 17, 2018
    Posts:
    37
    This!
     
unityunity