MixedReality-WebRTC icon indicating copy to clipboard operation
MixedReality-WebRTC copied to clipboard

Remote Audio is not smooth, seems like there is double audio sources?

Open josette-seitz opened this issue 5 years ago • 9 comments

Hello! We have integrated MRTK-WebRTC in our client project and noticed bizarre audio coming from the remote receiver on Hololens2. After further investigation, we even created a whole new Unity project and completed all steps listed here: https://microsoft.github.io/MixedReality-WebRTC/manual/unity/helloworld-unity.html and still getting the same audio issues.

We need to make a video call, headset to headset (Hololens2 to Hololens2). The remote user keeps hearing some kind of echo from the other user when speaking, but "echo" doesn't seem to be the best term for this issue. It's like there are 2 audio sources and it sounds like the user speaking in a tunnel 👎

Does this have anything to do with having Audio Spatializer to MS HRTF Spatializer? I tried to have this to "None" to test out, but keep getting errors where I needed to have this set to MS HRTF Spatializer.

Environment

  • MR-WebRTC version: Latest Version
  • Platform: Unity WSA Player (UWP)
  • Architecture: ARM
  • Unity version: 2019.4.13
  • Target device: HoloLens 2

josette-seitz avatar Mar 23 '21 22:03 josette-seitz

There used to be some bug about duplicate output, but now that this is fixed normally direct output to speakers is disabled by the following code, and therefore all audio is rendered by Unity alone: https://github.com/microsoft/MixedReality-WebRTC/blob/3d15d1624604a99cdcf40ce11603279177fb4f9c/libs/unity/library/Runtime/Scripts/PeerConnection.cs#L676-L681

I'd suggest checking that there's no duplicate audio transceiver on the peer connection. Also what is the effect of muting the MicrophoneSource component (enabled = false)? Is that preventing all audio, or can you still hear something?

Does this have anything to do with having Audio Spatializer to MS HRTF Spatializer? I tried to have this to "None" to test out, but keep getting errors where I needed to have this set to MS HRTF Spatializer.

I don't think audio spatialization is any mandatory, but I may remember wrong. Does that happen only on HL2, or can you repro on Desktop in the Editor? What about a standalone UWP build on PC?

jehumb-havok avatar Mar 23 '21 22:03 jehumb-havok

@djee-ms Here is what I have for PeerConnection. I don't see any duplicate audio transceiver...

PeerConnection

Regarding disabling the MicrophoneSource, that seems to prevent all audio; I don't hear anything. And actually I was able to set the Audio Spatializer to None, but still hearing bizarre audio like the user is in a tunnel 👎 One more thing I did was to set Default Speaker Mode from Stereo to Mono (because what the heck), and it still didn't do anything different.

Do you guys by chance have two HL2 to test out and hear what we are hearing? It's happening on all of our Hololens2's...

josette-seitz avatar Mar 24 '21 21:03 josette-seitz

@djee-ms after further investigation, we were able to find the problem. We ended up commenting all the code within OnAudioFilterRead in the AudioRenderer script. Once we commented out those lines, now the audio comes in very nicely. We also played around with leaving AudioRenderer as is, and disabling the AudioSource component. While the audio was better, it still wasn't as nice as just commenting out these lines below:

`       protected void OnAudioFilterRead(float[] data, int channels)
        {
            //var behavior = PadWithSine ?
            //    AudioTrackReadBuffer.PadBehavior.PadWithSine :
            //    AudioTrackReadBuffer.PadBehavior.PadWithZero;
            //bool hasRead = false;
            //bool hasOverrun = false;
            //bool hasUnderrun = false;

            //lock (_readBufferLock)
            //{
            //    // Read and use buffer under lock to prevent disposal while in use.
            //    if (_readBuffer != null)
            //    {
            //        _readBuffer.Read(_audioSampleRate, channels, data,
            //            out int numSamplesRead, out hasOverrun, behavior);
            //        hasRead = true;
            //        hasUnderrun = numSamplesRead < data.Length;
            //    }
            //}

            //if (hasRead)
            //{
            //    // Uncomment for debugging.
            //    //if (hasOverrun)
            //    //{
            //    //    Debug.LogWarning($"Overrun in track {Track.Name}");
            //    //}
            //    //if (hasUnderrun)
            //    //{
            //    //    Debug.LogWarning($"Underrun in track {Track.Name}");
            //    //}

            //    return;
            //}

            //// If there is no track/buffer, fill array with 0s.
            //for (int i = 0; i < data.Length; ++i)
            //{
            //    data[i] = 0.0f;
            //}
        }


josette-seitz avatar Mar 26 '21 20:03 josette-seitz

So you have double audio for some reason, and you just disabled the codepath that is supposed to be the valid one. If that works for you fine, but that's not solving anything.

jehumb-havok avatar Mar 26 '21 21:03 jehumb-havok

@djee-ms the only thing I can tell you is, either we comment this out, or we remove AudioSource component to not have this tunnel sound. Though in the docs it states to have the Audio Source component: https://microsoft.github.io/MixedReality-WebRTC/manual/unity/helloworld-unity-remotevideo.html. So is the double audio, due to having both AudioSource & AudioReceiver? We have done everything step by step based on the docs and the best results was commenting those lines out.

josette-seitz avatar Mar 26 '21 21:03 josette-seitz

I am pretty sure we have ran into the same problem in our project. We are building app which makes video calls from HL2 to PC and the audio is definitely doubled on HL2 side. Things worth mentioning:

  • On PC we don't use mrwebrtc, so the issue occurs when receiving/playing audio on HL2, not when recording.
  • Disabling AudioSource component disables only one audio track. In our case it doesn't resolve the issue, because we would like to control the AudioSource. For now we don't even know where the duplicate AudioSource is.

Environment

  • MR-WebRTC version: 2.0.2
  • Platform: UWP
  • Architecture: ARM
  • Unity version: 2019.4.19
  • Target device: HoloLens 2

GMyjak avatar Mar 30 '21 09:03 GMyjak

@GMyjak we thought the best decision was to leave AudioSource as is and comment those lines within OnAudioFilterRead out as shown above in AudioRenderer script. Not sure if this will work for you guys, but it worked for us. To add, commenting those lines works for HL2, but for PC we used the original AudioRenderer script (uncommented lines).

josette-seitz avatar Mar 30 '21 19:03 josette-seitz

So I have tried building app with OnAudioFilterRead body commented out. Sound is no longer doubled but I cannot control it by muting/unmuting AudioSource. It seems like commenting OnAudioFilterRead disables AudioSource sound.

GMyjak avatar Apr 02 '21 11:04 GMyjak

Still same issue. The problem is that

nativePeer.AudioTrackAdded += (RemoteAudioTrack track) => { // Tracks will be output by AudioReceivers, so avoid outputting them twice. track.OutputToDevice(false); }; does not work for HoloLens 2, it works only for Windows. Any updates with the issue?

@josette-seitz This issue should not be closed. It doesn't solve the problem of SDK not working correctly. Please do not close reported issues next time if they were not fixed by developers of SDK. Thank you.

tettogreen avatar Jan 26 '22 17:01 tettogreen