Search Unity

Audio Multiple audio sources simultaneously playing the same audio clip - best approach?

Discussion in 'Audio & Video' started by Jon_Olive, Jul 20, 2018.

  1. Jon_Olive

    Jon_Olive

    Joined:
    Sep 26, 2017
    Posts:
    5
    Hi all

    I am working on an audio app that involves multiple audio sources playing back the same audioclip simultaneously (and synchronously). What is the most efficient way to do this? It seems to me you can either just have each audiosource reference the audio clip separately (as normal) or you read the audioclip once and somehow distribute it to all the audio sources. As the audio clips will tend to be quite lengthy I'm streaming them - so the tradeoff is between on the one hand multiple reads and on the other hand the processing involved in the distribution.

    If the best way is to read once - can anyone point me in the right direction for how best to script this? I was thinking either using on audio filter read or audiosource.getdata. My scripting skills are, by the way - beginner to intermediate!

    many thanks

    Jon
     
  2. Jon_Olive

    Jon_Olive

    Joined:
    Sep 26, 2017
    Posts:
    5
    Update : I've implemented this using OnAudioFilterRead - in the master source I fill a public array with the data - each slave source then writes this data to their own OnAudioFilterRead. So far works a treat. Anyone see any potential problems?
     
  3. Docaroo

    Docaroo

    Joined:
    Nov 7, 2017
    Posts:
    82
    What is the purpose in having the same clip played by multiple audio sources at the exact same time? All you will do is cause either a) a volume increase on the clip if they are in perfect sync or b) phasing issues when they are not perfectly in sync.

    What are you trying to acheive with the same clip playing through multiple sources?
     
  4. Jon_Olive

    Jon_Olive

    Joined:
    Sep 26, 2017
    Posts:
    5
    Hi Docaroo - I'm afraid I can't tell you - suffice it to say that what I wanted to achieve works very well!
     
  5. jdeangoldstein

    jdeangoldstein

    Joined:
    Nov 25, 2018
    Posts:
    22
    Hi @Jon_Olive - I'm trying to accomplish the same thing! Can you share how you used OnAudioFilterRead for your purposes?