Placeholder-Software / Dissonance

Unity Voice Chat Asset
70 stars 5 forks source link

Sound is very low on iPhone #131

Closed AvinashP closed 5 years ago

AvinashP commented 5 years ago

I have integrated Dissonance with Photon Unity Networking. Most of the settings are kept to default. I have set Channel volume to max (2) in Voice Broadcast Trigger. The sound is super low on iPhone. Unless we use earphones, it's not audible.

I tried to set Audio Quality to HIgh, but still no effect. Am I missing something? What could be the issue?

martindevans commented 5 years ago

As a quick workaround for this you could try using a custom playback prefab, sending the voice to a mixer and applying a compressor to boost the quiet sound. This probably shouldn't be necessary though!

By the way sorry for the slow reply - I typed this out yesterday but forgot to send it until now!

AvinashP commented 5 years ago

Hi, Thanks for your response. The issue is only happening on iPhone. It works perfectly on Android.

I found that there is some issue with iPhone speaker and Unity Issue: https://issuetracker.unity3d.com/issues/ios-audio-will-be-played-from-earspeaker-if-microphone-dot-start-is-used Fix: https://github.com/10people/UnitySpeakerFix

Can you take a look because I can not see the code of Dissonance plugin? We need to call iPhoneSpeaker.CheckiOSPrepare(); before Microphone.Start()

Then iPhoneSpeaker.ForceToSpeaker() after Microphone.End()

martindevans commented 5 years ago

I found that there is some issue with iPhone speaker and Unity

Ah yes that issue has been a persistent problem for Dissonance. I'm excited to see that it's now marked as "fix in review" - hopefully that will finally be fixed in 2019.x.

Can you take a look because I can not see the code of Dissonance plugin?

I'm not sure what you mean - Dissonance is always distributed with the complete source code.

We need to call....

To insert those calls I would suggest creating a custom microphone capture class for Dissonance. You should be able to inherit from Assets/Plugins/Dissonance/Core/Audio/Capture/BasicMicrophoneCapture.cs and simply insert your calls into the StartCapture and StopCapture methods in the correct places. Something like this:

class FixedIosMicrophoneCapture
  : BasicMicrophoneCapture
{
    override WaveFormat StartCapture(string name)
    {
        // Do this before mic is started
        iPhoneSpeaker.CheckiOSPrepare();

        // Now invoke the usual mic starting behaviour
        return base.StartCapture(name);
    }

    override void StopCapture()
    {
        // Invoke normal mic ending behaviour
        base.StopCapture();

        // Do this after mic is stopped
        iPhoneSpeaker.ForceToSpeaker();
    }
}

To do this you will need to modify the methods in the base class to be virtual.

AvinashP commented 5 years ago

I implemented new Component. It's still not working. Either the fix provided in UnitySpeakerFix is not working or there is some other issue. I am using Unity 2018.2.5f1. I will try it in a sample project. Can you please try it on your side as well.

I wonder why no one else has faced this issue with Dissonance on iPhone.

public class MGMicrophoneCapture : BasicMicrophoneCapture {

    public override WaveFormat StartCapture(string inputMicName)
    {
        // Do this before mic is started
        iPhoneSpeaker.CheckiOSPrepare();

        // Now invoke the usual mic starting behaviour
        return base.StartCapture(inputMicName);
    }

    public override void StopCapture()
    {
        // Invoke normal mic ending behaviour
        base.StopCapture();

        // Do this after mic is stopped
        iPhoneSpeaker.ForceToSpeaker();
    }
}
martindevans commented 5 years ago

Can you please try it on your side as well.

Unfortunately I can't, I don't own an iPhone :(

Either the fix provided in UnitySpeakerFix is not working or there is some other issue.

Do you have the issue described by UnitySpeakerFix? i.e. When Dissonance is started audio switches to the earphone. If so I know other people have had this issue and UnitySpeakerFix has worked for them, so we'll need to look into that.

If not then is the problem that audio stays on the iOS speakers, but is extremely quiet? If so how does other (non-voice) audio sound if you create a blank scene without Dissonance and just an AudioSource playing some music? How about if you add a button which just calls Microphone.Start(), does the audio change when you press the button?

AvinashP commented 5 years ago

Do you have the issue described by UnitySpeakerFix?

I am not too sure if that's the same issue because the fix is not working. I can't hear voice chat either on the speaker or earphones. It perfectly works on Android. We have other issue of too mcuh Echo there.

How about if you add a button which just calls Microphone.Start(), does the audio change when you press the button?

I tried it and it does reduce the volume of overall game. Everything plays well and loud as soon as I start Dissonance on a button tap (which calls Microphone.Start). Overall volume becomes very low. I can't hear any voice chat.

martindevans commented 5 years ago

Do you have the issue described by UnitySpeakerFix?

What I mean by this is do you have the problem that when Microphone.Start is called Unity audio switches to earpiece speaker? So sound changes from here (primary speaker):

iphone_6_speakerphone_loudspeaker_repair_2

to here (earpiece speaker):

iphone-6-ear-speaker-replacement-lovefone-london_large

That's the problem UnitySpeakerFix is designed to fix.

AvinashP commented 5 years ago

I got the sound working by Removing UnitySpeakerFix and enabling "Prepare for iOS recording" and "Force iOS Speaker while recording" unity build settings.

image

Now the issue is Echo. I have recorded the video of my game with Voice Chat enabled. Below are the Dissonance Voice Settings.

image

Here is dropbox link to video

https://www.dropbox.com/s/j9hs1chuvq7at90/VoiceChatWithEcho_480p.mov?dl=0

can you please suggest what might be wrong or i need to change something. This also happens on Android. It would be best if you had any working sample for iOS or Android.

martindevans commented 5 years ago

enabling "Prepare for iOS recording" and "Force iOS Speaker while recording" unity build settings.

I've not seen those settings before, it looks like they were added in 2018.1. I'll update the documentation to note that you should enable these if you're using an appropriate Unity version. Thanks for telling me about that 👍

Can you confirm if the Mute button on the iPhone still works after you have done this? (#95)

Now the issue is Echo.

Have you checked out the section on iOS at the bottom of the AEC docs?

This also happens on Android

Unfortunately we have encountered a confirmed bug in Unity itself which is breaking the AEC on Android (#110). We're still waiting for Unity to fix that.

You should consider lowering Audio Duck Attenuation to a lower value, this is worthwhile on any platform with speakers+microphone even when AEC is working. It automatically reduces the volume of remote voices when the local voice is being transmitted.

AvinashP commented 5 years ago

I have still not been able to make Echo cancellation work.

Can you confirm if the Mute button on the iPhone still works after you have done this?

Mute button doesn't work after enabling these settings.

Have you checked out the section on iOS at the bottom of the AEC docs?

I implemented Audio mixing and passing all voice and sound through this channel. I used AudioPluginInterface.h to resolve "Echo Cancellation could not be found" issue.

I used Unity Pd plugin as well but same results. I am attaching screenshots of my settings

image

image

Here is Unity Pd image

martindevans commented 5 years ago
AvinashP commented 5 years ago

Sorry for late post on this. We shipped our game without voice chat. Now i am trying it back again.

Does the echo cancellation work in editor?

I tried playing a sound on Audio Source which was going through mixer having Dissonance echo Cancellation. It worked. Below is the screenshot image

Then i tried between iPhone and editor. I could hear the voice clearly on editor. Below is the screenshot of Audio mixer on Editor for this scenario image

I don't know much about UnityPD. What exactly does that do?

Someone mentioned this in Issue #80.

I am not gettting any worning in xCode logs and the setup seems correct. Its still not working between iOS devices.

Can you please try one iOS sample? I know you don't have a device but if you could arrange one to just run once. You would know the issue. I am sure this is not working for anyone on iOS. Or if it is then please share any demo or link to the game.

martindevans commented 5 years ago

That reference to UnityPD was the way they've integrated their plugin into the Unity Audio pipeline. I included some instructions here (at the bottom of the page) based on that - have you tried that?

AvinashP commented 5 years ago

Yes, I have integrated required code to load audio plugins correctly. Here is the code required for Xcode

import "AudioPluginInterface.h"

I have created a sample voice chat Unity project with Photon Unity networking. It's having same issue. I have sent you google drive link to martindevans@gmail.com. Please take a look.

martindevans commented 5 years ago

Thanks for the reproduction project, that will be very helpful. I'll get @TomGillen to borrow an iOS device to have a look into this as soon as possible.

AvinashP commented 5 years ago

Thanks for the reproduction project, that will be very helpful. I'll get @TomGillen to borrow an iOS device to have a look into this as soon as possible.

Hi Martin, is there any progress on this. Let me know if you need any help running and exporting that demo project. Below is the link of plugin fix you need to put in Xcode project

DissonancePluginFix.zip

TomGillen commented 5 years ago

Thanks for that; I've just found time to take a look at this now.

martindevans commented 5 years ago

Tom and I have been looking over this yesterday and today and we haven't been able to reproduce the problem.

We commented out the UnityRegisterAudioPlugin to disable the AEC and there was a lot more echo (echo was crystal clear and quite loud). Commenting it back in significantly reduced the echo to the level of quiet background murmur.

Tom suggested this could be a test setup problem - if the second device can hear the first person speaking (i.e. the two test devices are within hearing range of each other) then the echo canceller will never converge because it can hear the remote speaker on the local mic (also you will get terrible feedback loops which the AEC will not try to resolve). Could this be the problem?

AvinashP commented 5 years ago

Hi,

You are correct. Feedback loop is the issue. If we test it from different locations (or rooms). Echo cancellation works. When we are in audible range or playing game from same room, feedback loop makes it terrible.

Thanks a lot for your support. And sorry for this long thread.

martindevans commented 5 years ago

Hi Avinash, I'm glad we finally managed to sorted this out for you!

I'll close this thread now. If you're happy with our support please consider giving us a review on the asset store, it really helps us out :)