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 plays its buffer in an infinite loop on Android when re-enabled #95120

Open
Tracked by #76797
goatchurchprime opened this issue Aug 4, 2024 · 3 comments
Open
Tracked by #76797

Comments

@goatchurchprime
Copy link

Tested versions

4.3.rc2

System information

Android version 13

Issue description

AudioStreamMicrophone can play its buffer in an infinite loop when it has been turned off and then turned back on. I used to encounter this intermittently, but it is now completely reproducible in a small project.

I tried it in v4.2.1.stable, but here it just keeps switching off after less than a second, so is probably this issue: #86428 The switching off still happens in v4.3.rc2 but not so quickly.

The following video was recorded off my Android phone as a demo.
https://github.com/user-attachments/assets/bfeea975-3386-4d54-a8ea-9941cf62b250

Steps to reproduce

Make an AudioStreamPlayer with an AudioStreamMicrophone, set to Autoplay. Then while it's running call stop() and then play() and the output to the Bus will be a ~0.5second loop of a fragment of recording. (Only happens on Android.)

Minimal reproduction project (MRP)

lipsyncapp2.zip

@goatchurchprime
Copy link
Author

This bug also manifests in the Quest2 VR headset (which is Android based), but takes a few minutes to go wrong (so I'd hoped it didn't have this problem).

This is a show-stopper for the two-voip plugin, which is intended for multiplayer VR.

@goatchurchprime
Copy link
Author

According to the source code https://github.com/godotengine/godot/blob/master/platform/android/audio_driver_opensl.cpp#L257 the ring buffer receiving microphone input is 2048 frames, which at 44100Hz is only 0.04 seconds. The looping bug sounds close to 4 times a second, so can't be caused by this ring buffer. (I've not been able to find if other android applications have had this problem with reading the microphone.)

@goatchurchprime
Copy link
Author

This problem is not happening this way on v4.3.stable (on Android). Instead the AudioStreamPlayer that has the AudioStreamMicrophone is stopping intermittently (sometimes after seconds, and other times after minutes) with AudioStreamPlayer.playing == false.

When I set this value to true (in my Push-To-Talk implementation), it works again for a short duration (doesn't stutter as it used to).

I could make a permanent call-back auto-reset like this:

$AudioStreamPlayer.finished.connect(func a(): $AudioStreamPlayer.playing = true)

but it wouldn't be right!

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

2 participants