Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question Web RTC / Audio Stream Track 3D sound effect not work

Discussion in 'Unity Render Streaming' started by Joo_y, Aug 24, 2022.

  1. Joo_y

    Joo_y

    Joined:
    Jun 7, 2022
    Posts:
    3
    I try to apply 3d sound effect with received AudioStreamTrack.

    So, I used "AudioSourceExtension SetTrack" method. like this.

    Code (CSharp):
    1. if (e.Track is AudioStreamTrack audioTrack)
    2. {
    3.     var audioSource = resourceObjects[idx].GetComponent<AudioSource>();
    4.  
    5.     audioSource.SetTrack(audioTrack);
    6.     audioSource.loop = true;
    7.     audioSource.Play();
    8. }
    and, in the audioSource, set Spatial Blend option to 1.

    then, I had listened the received sound. It seems like to work that applied 3d sound effect. but, the sound effect only about distance effect. not work about direction.

    I want to implement fully 3d sound effect.
    How can i solve this problem?
     
  2. kazuki_unity729

    kazuki_unity729

    Unity Technologies

    Joined:
    Aug 2, 2018
    Posts:
    543
    Have you tested the "Audio" scene in WebRTC sample?
    https://docs.unity3d.com/Packages/com.unity.webrtc@2.4/manual/sample.html
     
  3. Joo_y

    Joo_y

    Joined:
    Jun 7, 2022
    Posts:
    3
    Yes.

    Let me show you how to reproduce my problem with that sample.

    First, Set the audio source input and outputs position close to main camera that contains audio listener.

    Then, Active Spatial Blend option to 1 and Min distance option set enough to listen at the audio sources.
    ** I recommend set doppler level option to 0.

    Then, Execute unity, click the start button. and go to Scene tap, move the "AudioSource - Input" around main camera. Maybe you can feel the 3d effect about distance and direction. If you are listening with earphones or headphones.

    Then, Click call button and move the "AudioSource - Output" as before. Probably, You will only feel the effect on distance and not the effect on direction.

    This is my problem!
    ** if you compare again, click pause button and active loopback.

    Thanks :)
     
  4. kazuki_unity729

    kazuki_unity729

    Unity Technologies

    Joined:
    Aug 2, 2018
    Posts:
    543
    What audio codec do you use?
    Opus supports multi-channel audio and you need to choice that one to realize spacial audio.
     
  5. Joo_y

    Joo_y

    Joined:
    Jun 7, 2022
    Posts:
    3
    Thanks for your reply.

    When I checked the audio codec, it was already using the Opus codec.

    So far I'm still trying to find a solution to my problem.

    This is one of the methods I tried.
    I received audio data through the data channel, made an audio clip in the main thread, put the data in the clip, and played it with loop.

    Then, it worked just as I thought it would.

    In my opinion, the point of this problem is that the spatial effect is applied well to the data of the audio track, as the sound changes according to distance and the Doppler effect is applied.
    But the audio listener hear it like mono, not stereo.

    ** the default speaker mode option to stereo in the project settings.
     
  6. kazuki_unity729

    kazuki_unity729

    Unity Technologies

    Joined:
    Aug 2, 2018
    Posts:
    543
    I understood your issue.

    As you said, we don't support the feature that the spatial audio effect on receiver side. We need to check the implementation of audio whether we can support it or not.