Placeholder-Software / Dissonance

Unity Voice Chat Asset
71 stars 5 forks source link

Not switching audio device when I turn off my system Bluetooth before disconnecting wireless headset from the system. #230

Closed Rohith-Nanthan closed 2 years ago

Rohith-Nanthan commented 3 years ago

dissonance bug

Context

If I switch off my system Bluetooth while my headset is still connected to the system, dissonance throws Unknown microphone capture error and it does not switch back to default microphone. It is also not switching my speaker to default system speaker. It works fine if I disconnect the headset first and then switch off the Bluetooth of my device.

Expected Behavior

It must switch back to default speaker and microphone

Actual Behavior

It throws error and I am unable to use speaker and microphone. [Dissonance:Recording] (11:52:34.005) BasicMicrophoneCapture: Unknown microphone capture error (zero length clip) - restarting mic UnityEngine.Debug:LogError (object) Dissonance.Logs/LogMessage:Log () (at Assets/Plugins/Dissonance/Core/Log.cs:69) Dissonance.Logs:SendLogMessage (string,Dissonance.LogLevel) (at Assets/Plugins/Dissonance/Core/Log.cs:98) Dissonance.Log:WriteLog (Dissonance.LogLevel,string) (at Assets/Plugins/Dissonance/Core/Log.cs:181) Dissonance.Log:Error (string) (at Assets/Plugins/Dissonance/Core/Log.cs:425) Dissonance.Audio.Capture.BasicMicrophoneCapture:UpdateSubscribers () (at Assets/Plugins/Dissonance/Core/Audio/Capture/BasicMicrophoneCapture.cs:250) Dissonance.Audio.Capture.CapturePipelineManager:Update (bool,single) (at Assets/Plugins/Dissonance/Core/Audio/Capture/CapturePipelineManager.cs:188) Dissonance.DissonanceComms:Update () (at Assets/Plugins/Dissonance/Core/DissonanceCommsImpl.cs:683)

Steps to Reproduce

Provide a detailed set of steps to reproduce the problem

  1. Connect a wireless headset and start the communication
  2. Turn off the system Bluetooth while the headset is still connected and being used.

Your Environment

martindevans commented 3 years ago

Could you check if the OnAudioConfigurationChanged callback (docs) happens when you do this? We've had some reports of it not happening in certain circumstances.

Rohith-Nanthan commented 3 years ago

Yes, the callback gets invoked every time I turn off the bluetooth but I get a warning stating that Audio system failed to initialize. dissonance bug 2

martindevans commented 3 years ago

I think I'll need to have a look through the full log of this to see how Dissonance is reacting to the failed reset. Before sending me that could you please:

  1. Add an event handler to that event which logs out "Unity OnAudioConfigurationChanged called here (martindevans)"
  2. Raise Dissonance logging to Debug for all categories (Window > Dissonance > Diagnostic Settings)
  3. Delete the current editor log
  4. Repro the problem and send me the log

Thanks.

Rohith-Nanthan commented 3 years ago

I have attached the log file below for your reference. Please look into it.

Dissonance debug.txt

martindevans commented 3 years ago

It looks like Dissonance is responding to the audio reset event basically as I would expect. The capture pipeline gets totally reset, which emptees out all buffers and attempts to re-initialise the microphone. You can see it re-initialising with messages like this:

DEBUG [Dissonance:Recording] (17:06:08.478) BasicMicrophoneCapture: GetDeviceCaps name=` min=48000max=48000`

The empty name here indicates that Dissonance is not specifying a mic and is instead telling Unity to use whatever the system default Microphone is.

On the other end (playback) Dissonance actually doesn't have any input into which playback device is used - it simply plays audio through an AudioSource and Unity is responsible for playing that out through some actual hardware.

Unfortunately I think this is a Unity bug. If you report it to Unity please share a link to the bug report here.

Some potential workarounds:

Rohith-Nanthan commented 3 years ago

Hi, I tried to force reset but it did not work. Also, I found a few use-cases around this bug:

  1. My Bluetooth microphone by default does not connect with the application and this happened only for my Bluetooth headset and not for my colleague. My microphone connects and works when I manually choose the Bluetooth microphone from editor. dissonance microphone not connecting. Sometimes when I select my Bluetooth microphone from the editor, it throws this error. dissonance microphone selection bug. This is the full log for selecting microphone from editor. Dissonance bug.txt

but I get this error only sometimes, other times it works when I select microphone from editor and I get no error.

  1. When I turn-off my Bluetooth, my microphone works but my speaker does not work (a wired headset already connected with my system was the fallback device when my Bluetooth turned off) but still I get an error stating that "Unknow microphone capture error" even though my wired headset microphone works. It was different for my colleague - both microphone and speaker didn't work for her. She was using a MacOs and built-in system microphone and speaker was her fallback device.

  2. This audio device switching bug happens only when another participant has started speaking, it does not happen before that. The switching between devices is smooth when no one has started speaking.

Can you please look into it these use-cases and solve this issue ?

martindevans commented 3 years ago

Unfortunately I don't think there's much I can do about these bugs. Have you reported them to Unity to see if they know about the bugs or have a potential workaround?

For input device selection the bugs are coming up from the Unity Microphone API (e.g. Failed to get recording driver capabilities when calling Microphone.GetDeviceCaps. Dissonance responds to this by disabling the input system (until a reset is forced). The only thing that can be done about this is simply to try again later and hope that the Unity API is no longer throwing exceptions.

For the output device issues Dissonance doesn't have any influence at all on the output device that Unity uses! The only thing I can can think that may be related is Unity not properly switching output device while there is an active audio playback (try playing some music through an audiosource instead of speech to see if the issue persists).