Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot switch Audio input device (AudioServer.input_device) #75603

Open
Tracked by #76797
kevinloustau opened this issue Apr 2, 2023 · 14 comments · May be fixed by #75628
Open
Tracked by #76797

Cannot switch Audio input device (AudioServer.input_device) #75603

kevinloustau opened this issue Apr 2, 2023 · 14 comments · May be fixed by #75628

Comments

@kevinloustau
Copy link

Godot version

v4.0.1.stable.official [cacf499]

System information

Windows 11, Sound card zoom h2n, Sound card Roland duo capture

Issue description

I try to switch the audio input using the AudioServer.set_input_device() method. Unfortunately, the input device is always the same.
Screenshot 2023-04-02 181322

Steps to reproduce

  1. Be sure your computer has at leas 2 sound cards (motherboard + external at minimum)
  2. Try to use the AudioServer.set_input_device() to change the device

Minimal reproduction project

AudioInputDeviceList.zip

@lazydevl0per
Copy link

lazydevl0per commented Apr 3, 2023

I have analyzed the problem and found the cause and an initial fix for this problem.
It is also reproducable on the latest commit.

Affected file: drivers\wasapi\audio_driver_wasapi.cpp

Debugging showed that in the current state by using the given project the audio_input is not initialized.
One could initialize an audio_input device in the AudioDriverWASAPI::init() function but i dont know if that is wise regarding privacy? Seems like the way it currently is setup it only initializes an audio_input when input_start() is called. However it is not un-initialized when input_stop() is called so the device still remains as it would in case of using the init() function.. so i presume it would be safe to initialize an audio_input in the init() function first.

After this is done it still wont work since the audio_input.audio_device is never started.
The thread function contains a check if the input is active and only then will it check if the input device has been changed.
Me personally, i think it should be fine to change the input device regardless if its active or not especially AFAIK on windows if there is no microphone permission for the App the input device will stream null.
So we would also need to extract the checks for input device changes out by one scope aswell.

Now things are in a "working" state. I am extremely new to this codebase (just started 2 hours ago) so i am not sure if this would be the "right" solution in case of this engine.

Also since the change of the device seem to be done in a separate thread your print statement in the GoDot script:
print("Input device: ", AudioServer.input_device)
might not yet have the updated value of the input device so the print could still output the old one.
I tested this by adding another print before changing and one after and this behaviour seems to be reflected.

Hope i could help

EDIT:: should take my ADHD meds, this info is all over the place... sry, basically cannot change device because device not active. I am happy to provide more information if needed...

EDIT2:: I have now gained more insight into the code. I understand the problem better and would like to fix this. However i will need a little time as im still reading through the contribution guides/rules

@kevinloustau
Copy link
Author

I greatly appreciate your help @lazydevl0per 👍

@lazydevl0per
Copy link

I greatly appreciate your help @lazydevl0per 👍

Until then you can get the audio device to change if you add an AudioStreamPlayer Node to your scene and choose an AudioStreamPlaybackMicrophone resource as stream source for it. Make sure to start the AudioStreamPlayer so that the input data is being collected.

@Calinou
Copy link
Member

Calinou commented Apr 3, 2023

Can you reproduce this issue in 3.5.2? It's worth checking so that we can cherry-pick the fix to 3.x and 3.5 if it's needed there.

@lazydevl0per
Copy link

lazydevl0per commented Apr 3, 2023

I will try. Need to make a build for 3.5.2 real quick :)

EDIT:: Nevermind, glanced over the 3.5 code and saw that the AudioDriver API is entirely different.
If this same issue exists on 3.5 it might require its own separate fix so no cherry picking possible. I will hower check anyway if the same issue is there.

Event though the underlying AudioDriver interface being different it seems that the same logic is contained in the 3.5 WASAPI driver. The same behaviour is reproducable with the following project built for 3.5:

AudioInputDeviceList35.zip

I am not sure how to handle fixing this on the 3.5 branch. It should be easy doable to recreate the fix on a separate branch for 3.5 with a separate PR but i dont know if thats the best course of action.

@MJacred
Copy link
Contributor

MJacred commented May 17, 2023

@Calinou, this issue is also present in Godot 3.x: #46710

@Calinou Calinou changed the title [Audio] Cannot switch Audio input device (AudioServer.input_device) Cannot switch Audio input device (AudioServer.input_device) May 17, 2023
@lazydevl0per
Copy link

lazydevl0per commented Oct 16, 2023

Tried it yesterday on latest master branch and the issue is still present.

@MJacred this issue is caused by the same logic in 3.x however the affected file changed too much from 3.x to 4.x so it might require its own fix, dont know if cherrypicking or something similiar will work in this case.

Also this is an OS Specific Audio issue, currently only present on Windows using the WASAPI driver

@MJacred
Copy link
Contributor

MJacred commented Oct 16, 2023

@lazydevl0per: Yes, it would need its own fix in that case with a brand new PR. The other issue was also assigned to Windows (wasapi) platform.

@b4ux1t3
Copy link

b4ux1t3 commented Feb 22, 2024

Are we sure this is a platform-specific problem? I'm running into it on Linux, using v4.2.1.stable.mono.official [b09f793].

No matter what I do, I can't get it to switch inputs.

Here's a screenshot from within my editor:

image

Here, I'm showing that the input I'm trying to set the server to matches one of the entries in its list of inputs, but it ends up assigning "" and then "Default" instead.

I've tried locking and then unlocking first, no dice. Am I running into a different-yet-similar problem?

EDIT: Also, this happens for output devices as well. I do have the project setting checked to get inputs.

EDIT 2: Well. . .I can't reproduce this 100% of the time in a fresh project, but, it does seem to sporadically pop up in this sample project on Linux Mint: https://gitlab.com/b4ux1t3/AudioTestGodot

It does seem to happen 100% of the time in the project where I originally saw this: https://gitlab.com/b4ux1t3/RigControl.Net/-/tree/godot-gui?ref_type=heads

To be clear, it is almost impossible for most people to vet this from my primary project here; it relies on having specific hardware and external conditions to Godot. I include it just so the code is available.

EDIT 3: For my last edit, I want to share that I'm running into this issue in the non-mono Godot, as well. I copied the scene from my .NET project, got everything working in GDScript, and am still unable to correctly switch audio devices. I'm starting to think I may need to open a separate ticket for this, though, because it does sometimes seem to actually switch audio devices. But only sometimes.

@souplamp
Copy link
Contributor

souplamp commented Jun 23, 2024

Are we sure this is a platform-specific problem?

Yes, this is specific to Windows because the bug is in AudioDriverWASAPI. Even if the cause is similar, it would require a separate fix than addressing this bug.

Open another bug report if you get the chance!

@b4ux1t3
Copy link

b4ux1t3 commented Jun 23, 2024

Yes, this is specific to Windows because the bug is in AudioDriverWASAPI. Even if the cause is similar, it would require a separate fix than addressing this bug.

Open another bug report if you get the chance!

Gotcha! That was basically what I was asking, if I should open another ticket for the Linux issue.

I'll get the project dusted off, see if recent versions fixed it, and go from there.

Thanks!

@kevinloustau
Copy link
Author

Hello, any idea about this issue? With the trend of using voice in games, it should very nice to get an eyes on

Yes, this is specific to Windows because the bug is in AudioDriverWASAPI. Even if the cause is similar, it would require a separate fix than addressing this bug.
Open another bug report if you get the chance!

Gotcha! That was basically what I was asking, if I should open another ticket for the Linux issue.

I'll get the project dusted off, see if recent versions fixed it, and go from there.

Thanks!

Hi @b4ux1t3, Did you have a bit of time to check this issue? 🙂

@b4ux1t3
Copy link

b4ux1t3 commented Sep 2, 2024

Hi @b4ux1t3, Did you have a bit of time to check this issue? 🙂

@kevinloustau

I have not had time yet, sorry!

I'm planning on doing a round of godot version upgrades with the release in the near-ish future.

@nalmeth
Copy link

nalmeth commented Sep 7, 2024

I am also unable to set the AudioServer.output device in 4.3. Giving it anything from the get_output_device_list() just results in it still being 'Default'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants