Godot: Microphone recording doesn't work on Linux

Created on 30 Oct 2019  路  14Comments  路  Source: godotengine/godot

Godot version: Git https://github.com/godotengine/godot/commit/924db5fa58ab28912857029ec8dd34fbde771550

OS/device including version: Fedora 30, PulseAudio

Issue description: Microphone recording doesn't seem to work on Linux, even though Godot appears as a capture device when running the Mic Record Demo:

image

Saving the file after recording a few seconds will write a WAV file that contains only a few seconds of silence. I made sure the microphone is not muted by recording a sample in Audacity beforehand (where it works correctly).

Steps to reproduce: Use the "Mic Record Demo" from godot-demo-projects. Click the Record button, say something, then press Stop. Save the audio to a WAV file then inspect it using a media player.


See also https://github.com/godotengine/godot-demo-projects/issues/359. This issue has been confirmed by @CombustibleLemonade in https://github.com/godotengine/godot-demo-projects/issues/359#issuecomment-547962679, so I'll add the confirmed label right away.

bug confirmed linuxbsd audio

Most helpful comment

@FeralBytes the change might be in the fa26a551. After reverting that in Master the recording started working for me. The changes look pretty innocent and I cannot tell just by looking what is the problem. Any thoughts @marcelofg55.

Edit: Adding this line seems to be enough fix it for me. Race condition / synchronization problem perhaps?

--- drivers/pulseaudio/audio_driver_pulseaudio.cpp  (revision 21dec856f2a7482fc69e18ffc60f64e90e10fcc5)
+++ drivers/pulseaudio/audio_driver_pulseaudio.cpp  (date 1577224764136)
@@ -669,6 +669,8 @@
            break;
    }

+   print_verbose("PulseAudio: detected " + itos(pa_rec_map.channels) + " input channels");
+   
    pa_sample_spec spec;

    spec.format = PA_SAMPLE_S16LE;

All 14 comments

Works for me on Mageia 7 using PulseAudio.

Confirmed Linux Mint 19.2 Cinnamon, x64 Kernel 5.0.0-31-generic, Lenovo Laptop.

Confirmed on Ubuntu 18.04.3 on a Lenovo Thinkpad T420.

Confirmed on up-to-date NixOS unstable with KDE, PulseAudio.

Can this get added to 3.2 milestone, and how can we help troubleshoot the problem?

@FeralBytes Which Godot versions can you reproduce this on? Microphone support was added in 3.1.

Here, I can still reproduce this on https://github.com/godotengine/godot/commit/a10449bbbc1c04f3ca151e067974717145a396d7, which means it wasn't fixed by #34306.

I can reproduce this with 3.1.2

@Calinou 3.2 beta 4 is broken, also 3.1.1 is broken Also 3.1 Stable does not work. A what stage of 3.1 was it added at Alpha? Ah 3.1 Alpha1 works. I then tested Beta 1 and it was broken. I then worked backwards and found that even 3.1. Alpha2 was broken.

So a change between 3.1 Alpha1 and 3.1Alpha2 broke mic recording for many versions of Linux.

EDIT: Tested in both Linux Mint 19.2 and 19.3, same result.

@FeralBytes the change might be in the fa26a551. After reverting that in Master the recording started working for me. The changes look pretty innocent and I cannot tell just by looking what is the problem. Any thoughts @marcelofg55.

Edit: Adding this line seems to be enough fix it for me. Race condition / synchronization problem perhaps?

--- drivers/pulseaudio/audio_driver_pulseaudio.cpp  (revision 21dec856f2a7482fc69e18ffc60f64e90e10fcc5)
+++ drivers/pulseaudio/audio_driver_pulseaudio.cpp  (date 1577224764136)
@@ -669,6 +669,8 @@
            break;
    }

+   print_verbose("PulseAudio: detected " + itos(pa_rec_map.channels) + " input channels");
+   
    pa_sample_spec spec;

    spec.format = PA_SAMPLE_S16LE;

I could finally reproduce this too, it seems like official builds don't work but local builds do. Likely an issue with the different PulseAudio versions used on the official buildsystem and on user systems.

I confirm that reverting fa26a551 "fixes" the issue, i.e. the audio recording works again, but it's cracking and of bad quality (contrarily to the current state in the master branch if you build against a recent PulseAudio, where it works and sounds good).

The official buildsystem uses Ubuntu 14.04 with libpulse-dev 4.0, which is quite old. Updating it to a newer version matching what users have on their system might help.

@akien-mga Would loading the PulseAudio library via dlopen() solve the issue? (#20978)

No, it's properly linked and found already.

I can confirm @Zolzak's finding about the print_verbose().
Neither local builds of the master nor the 3.2.2-stable were giving off any sound.
Now they do. Even when running Godot without --verbose.

Was this page helpful?
0 / 5 - 0 ratings