Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Multiple AudioListeners

Discussion in 'Editor & General Support' started by Bjerre, Mar 21, 2007.

  1. Bjerre

    Bjerre

    Joined:
    Nov 8, 2006
    Posts:
    108
    I read in the script reference that you can only have one listener in a scene.
    Is that right. If it is, wouldn't it be impossible to create a split screen game, where both players could pick up objects that play a sound.

    If I'm limited to one Audio Listener, could a solution be to move the Audio Listener between the 2 players positions. (did that make sense).


    Bjerre
     
    SamFernGamer4k likes this.
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Imagine there are two listeners. Now a single sound is played; so it should come out at volume X for one listener, and volume Y for the other listener (the same for panning/3D effect). How should this sound be actually played then?

    Yes, you can move the audio listener anywhere you like. By default it's on the camera because it's the most common use, but you can remove it from the camera and attach it anywhere else.
     
    SamFernGamer4k likes this.
  3. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    You could possibly get the effect you want by placing the audio listener half way between the two cameras.

    Code (csharp):
    1.  
    2. var camera1 : Transform;
    3. var camera2 : Transform;
    4.  
    5. function Update() {
    6.     transform.position = (camera1.position + camera2.position) / 2.0;
    7. }
    8.  
     
    SamFernGamer4k and elan88889 like this.
  4. Bjerre

    Bjerre

    Joined:
    Nov 8, 2006
    Posts:
    108
    Aras: I see the problem, I think I will try to move my audio listener between the 3 players positions, and if that doesn't work i'll just send the players coordinates to max/msp and control the sound from there.

    freyr: If you had to make a split screen (2 player) version of the Fps demo that came with unity, where would you place the audio listener. If you place it half way between the two cameras how could you hear the players firing their guns if they are positioned on opposite side of the level?
     
  5. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    You could also emit sounds near the audio listener instead of at the location of the gun firing the bullets. The problem is that when having more than one player on a single machine, directional audio ceases to make sense as pointed out by Aras. You will have to chose whatever sounds best in each situation. (Read: cheat a lot :) )
     
    SamFernGamer4k likes this.
  6. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I've been playing the heck out of the Resident Evil 5 demo, in splitscreen, and I wondered what they would do with surround sound. Does anybody have any firsthand experience with this (not specifically that game, although it has already become my favorite splitscreen game ever, and interests me the most)? I don't have a surround setup, but this issue interests me. I would think the most logical thing to do would be to mix two audio listeners together, but that's not a possibility in Unity.
     
  7. Bezzy

    Bezzy

    Joined:
    Apr 1, 2009
    Posts:
    75
    An alternate desirable feature to having multiple listeners would be to "separate" the left and right "ear", as it were (and I guess the same with any surround sound outputs... one mic per speaker). That way, a left hand side split screen listener could have mono sound playing to a left hand speaker.

    Just an idea for handy configurations.

    There's a work around, but it's weird enough that multiple listeners would be a better request: construct a "relative sound scape".

    This means multiplying every sound emitted by the number of split screen fake listeners you want.

    Essentially, Player 1 has their sounds played normally, relative to their point of view. Player 2, however, makes a copy of every sound emitter, transforms each positions of the sound emitter into local space, and then copies them over to Player 1's transform space.

    Essentially, Player 1 is listening to BOTH player's sounds at once. Weird, huh?
     
  8. GennadiyKorol

    GennadiyKorol

    Joined:
    Jul 10, 2010
    Posts:
    107
    Lately I've been pondering on the same problem as well, as we want to have a split screen for our game.

    Bezzy,

    I was thinking about exactly the same thing with a twist. You could also move the sounds in local space to match the camera the sound is played from.

    So, you could position the listener strictly in the middle of the screen. The when each sound is played, it is converted to local space and moved a bit depending on where the listener camera is (I'd say each sound would pick the closest camera to itself to be played in).
    That way if you have a 4 player split screen, lower left player should hear his sounds coming from lower left, etc. Should help a bit with picking up different sounds.

    I wonder how one makes it work with reverb zones though. We'd need to transform those as well :D
     
  9. Tinus

    Tinus

    Joined:
    Apr 6, 2009
    Posts:
    437
    Sorry for digging up an old thread, but I want people googling for this issue to find this post.

    I'm developing a Multi Audio Listener plugin based on Unity's default audio components. The approach I took is somewhat similar to what has been described in this thread, but it turns out there's quite a lot of boilerplate involved in making it work smoothly.

    The plugin is currently available for testing (on demand) and will later be sold on the Asset Store. Contact me if you're interested!

    MultiAudio Listener: Split Screen Audio on the Unity Forums
     
  10. Bezzy

    Bezzy

    Joined:
    Apr 1, 2009
    Posts:
    75
    Thanks Tinus! I'm returning to this issue, so your work is timely and highly appreciated! I had one quick question: if the virtual listeners move, is doppler handled correctly? It's not a big deal if not, just interested.
     
  11. deram_scholzara

    deram_scholzara

    Joined:
    Aug 26, 2005
    Posts:
    1,043
    Presumably this would work essentially the same as two microphones plugged into the same speaker system - you'd effectively only hear the louder of the two (assuming a mono speaker system).

    In Unity, this could be a group of settings in the audio project settings:
    • Single Listner
    • Dominant Listener (by volume)
    • All Listeners

    In multiple-speaker systems using Dominant Listener mode, panning could follow the listener with dominant volume from the source. If a further listener from the source hears it on the left, and the closer listener hears it on the right, it will play in the right channel. This seems like it would provide ideal results for split-screen gameplay because odds are that the player closer to the source will usually have a more pressing need to hear it (bouncing grenades, for example).
     
  12. Icevengeance

    Icevengeance

    Joined:
    Aug 7, 2013
    Posts:
    1
    Hi guys!

    I don't if this thread was finalized, but i have some workaround that can be useful in this matter. What i did, is placed one game-object "AUDIO-OBJECT" with audio listener, anywhere in the game room, and set it to play sound for all cameras in split screen mode.

    Whenever there is an object passing near any of the cameras, "AUDIO-OBJECT" plays adequate AudioClip wit adequate volume, depending on the object passing near the camera. Of course you have to k It helped me a lot with split screen issue.

    Hope this helps someone!
     
  13. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    How on Earth does Unity3D still not support proper audio mixing from multiple listeners. Ares's logic doesn't make any sense. Two audio listeners with a sound playing in the center of the two would play out both speakers equally in a split screen game... like every decent game for the last 20-30 years. This is pathetic...
     
  14. Pangamini

    Pangamini

    Joined:
    Aug 8, 2012
    Posts:
    54
    Or, Imagine an ingame camera that renders into an ingame screen. Now you just want to do the same thing for the audio. Like Half-Life 2 does often. You'd have an audioListener that outputs as an audioSource somewhere else, being listened to by the primary audioListener
     
  15. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    Forgot to post this here: https://1drv.ms/u/s!Alt5wRhQYKD7gfdAGPWIuBUgRQ6oMQ?e=vQsYpR

    Thats a fully working solution. Its fast and all 3D audio velocity/doppler effects etc you would expect work.
    Its very easy to understand how to use.

    * Put the "AudioSystem3D" and "AudioSystem3D_Update" on the same GameObject but a unique one for them.
    * Then instead of using Unity's AudioListener and AudioSource use AudioListener3D & AudioSource3D.
    * Thats it.


    Should handle scene loads correctly as well.
    Perfect for split screen in games.
     
    ROBYER1 and StupydHors like this.