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

Microphone builds up delay over time #80173

Open
Tracked by #76797
edmundmtang opened this issue Aug 2, 2023 · 7 comments
Open
Tracked by #76797

Microphone builds up delay over time #80173

edmundmtang opened this issue Aug 2, 2023 · 7 comments

Comments

@edmundmtang
Copy link

edmundmtang commented Aug 2, 2023

Godot version

v4.1.1.stable.official [bd6af8e]

System information

Godot v4.1.1.stable - Windows 10.0.19045 - Vulkan (Mobile) - dedicated GeForce GTX 960 () - Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz (8 Threads)

Issue description

The delay between when a sound is produced in real life and when it is reproduced within Godot grows over time, gaining about 1 second of delay for every hour that the project runs.

I'd also note that I am using a USB mic (Blue Yeti) set to 2 channel, 16 bit, 48000 Hz. Likewise, the mix rate in project settings is set to 48000.

Steps to reproduce

  1. Create an AudioStreamPlayer node, assign a new AudioStreamMicrophone to Stream and turn on Autoplay.
  2. Go to Audio and Add Bus. Then add a Record effect to the new bus (Add Effect > Record).
  3. Enable audio input under Project > Project Settings... > Audio > Driver > Enable Input.
  4. Run project. You should be able to hear your microphone through the project. Make a sharp noise (like snapping your fingers) and note the delay (it should be very short, within milliseconds).
  5. Let the project run for an extended period of time. Make a sharp noise again and it should be apparent that it has taken longer to hear it reproduced within the project.

Minimal reproduction project

microphone_test.zip

@fire
Copy link
Member

fire commented Aug 2, 2023

Perhaps we need to rewrite AudioEffectRecord to be using AudioEffectCapture. @lyuma Any ideas?

@edmundmtang
Copy link
Author

Your comment prompted me to go back and look into something and I realized that I was using AudioEffectCapture in my own project, so this issue isn't due to using either and I can experience it without adding the extra audio bus.

@edmundmtang edmundmtang changed the title AudioEffectRecord builds up delay over time Microphone builds up delay over time Aug 2, 2023
@fire
Copy link
Member

fire commented Aug 2, 2023

The mix rate is very suspicious. Can you double check if they match and what the number is?

@edmundmtang
Copy link
Author

image
Yeah, I'm making sure they're matching at 48000.

@CalinLeafshade
Copy link

I can confirm this is a problem.
The issue here: edmundmtang/vosk-godot#6 (comment) by @edmundmtang recommends "restarting" the microphone periodically but I can't figure out a way to reliably do that.

Stopping the AudioStreamPlayer seems to just kill the microphone input entirely even if I restart it.

How can I "reset" the microphone to remove the delay?

@edmundmtang
Copy link
Author

edmundmtang commented Dec 22, 2023

How can I "reset" the microphone to remove the delay?

I call stop() and then play() on the AudioStreamPlayer. Often it works, but as you noted sometimes it just kills the microphone input entirely and nothing short of a full app restart will get it to work. So sadly the workaround doesn't really fix the problem because eventually the microphone will stop working if you restart it frequently enough to keep the desync low.

@Calinou
Copy link
Member

Calinou commented Dec 22, 2023

This reminds me of an issue I encounter on CS2 on Linux with -sdlaudiodriver pipewire (it uses SDL3). Changing audio output devices resolves latency until it slowly starts building up again, at a similar rate of 1 second per hour the game is running.

I have no idea why it's occurring either way, but I figure I'd leave this here nonetheless.

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

No branches or pull requests

5 participants